Esempio n. 1
0
 /**
  * @param $keywords Keywords to search for in the Sphinx index
  * @return array
  */
 public function searchForums($keywords)
 {
     $sphinx = new MOD_sphinx();
     $results = array('count' => 0);
     $member = $this->getLoggedInMember();
     if (!$member) {
         $results['errors'][] = 'ForumSearchNotLoggedIn';
     } else {
         $groupEntities = $member->getGroups();
         $groups = array(0);
         foreach ($groupEntities as $group) {
             $groups[] = $group->id;
         }
         $sphinxClient = $sphinx->getSphinxForums();
         $sphinxClient->SetFilter('IdGroup', $groups);
         $sphinxClient->SetSortMode(SPH_SORT_ATTR_DESC, 'created');
         $resultsThreads = $sphinxClient->Query($sphinxClient->EscapeString($keywords), 'forums');
         if ($resultsThreads) {
             $results['count'] = $resultsThreads['total'];
             if ($resultsThreads['total'] != 0) {
                 $threadIds = array();
                 foreach ($resultsThreads['matches'] as $match) {
                     $threadIds[] = $match['id'];
                 }
                 $this->board->initThreads($this->getPage(), false, $threadIds);
             } else {
                 $results['errors'][] = 'ForumSearchNoResults';
             }
         } else {
             $results['errors'][] = 'ForumSearchNoSphinx';
         }
     }
     return $results;
 }