Example #1
0
 /**
  * Builds a search query from a give search term.
  * @return SearchQuery
  */
 protected function getSearchQuery($keywords)
 {
     $categoryIDs = array();
     $categoryFilterID = $this->request->requestVar(self::$search_category_key);
     $categories = $this->Categories();
     if ($categories->count() == 0) {
         $categories = FAQ::getRootCategory()->Children();
     }
     $filterCategory = $categories->filter('ID', $categoryFilterID)->first();
     $categoryIDs = array();
     if ($filterCategory && $filterCategory->exists()) {
         $categoryIDs = $this->getSelectedIDs(array($filterCategory));
     } else {
         $categoryIDs = $this->Categories()->column('ID');
     }
     $query = new SearchQuery();
     $query->classes = self::$classes_to_search;
     if (count($categoryIDs) > 0) {
         $query->filter('FAQ_Category_ID', array_filter($categoryIDs, 'intval'));
     }
     $query->search($keywords);
     // Artificially lower the amount of results to prevent too high resource usage.
     // on subsequent canView check loop.
     $query->limit(100);
     return $query;
 }