Skip to content

Commit

Permalink
map categories in search result
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Jul 25, 2017
1 parent 08c2fcc commit f6c9b1f
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions controllers/FrontendController.php
Expand Up @@ -342,11 +342,13 @@ public function findAction()
} catch (\Zend_Search_Lucene_Exception $e) {
}

foreach ($this->categories as $category) {
try {
$searchResult['categories'][] = $hit->getDocument()->getField('cat')->value;
} catch (\Zend_Search_Lucene_Exception $e) {
$searchResult['categories'] = [];
try {
$categories = $doc->getField('categories')->value;
if(!empty($categories)) {
$searchResult['categories'] = $this->mapCategories($categories);
}
} catch (\Zend_Search_Lucene_Exception $e) {
}

$searchResults[] = $searchResult;
Expand Down Expand Up @@ -571,6 +573,28 @@ private function getFuzzySuggestions($searchResults = [])
return $suggestions;
}

/**
* @param string $documentCategories
*
* @return array
*/
private function mapCategories($documentCategories = '')
{
$categoryStore = [];
$validCategories = $this->categories;
if(empty($validCategories)) {
return $categoryStore;
}

$categories = explode(',', $documentCategories);
foreach($categories as $categoryId) {
if(in_array($categoryId, $validCategories)) {
$categoryStore[] = $categoryId;
}
}
return $categoryStore;
}

/**
* remove evil stuff from request string
*
Expand Down

0 comments on commit f6c9b1f

Please sign in to comment.