示例#1
0
 /**
  * singleton getter
  *
  * @param void
  * @return PApps
  */
 public static function get()
 {
     if (!isset(self::$_instance)) {
         $c = __CLASS__;
         self::$_instance = new $c();
     }
     return self::$_instance;
 }
示例#2
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;
 }
示例#3
0
 /**
  * Returns a list of suggestions that match with a given text
  */
 public function searchSuggestions($text)
 {
     $sphinx = new MOD_sphinx();
     $sphinxClient = $sphinx->getSphinxSuggestions();
     $results = $sphinxClient->Query($sphinxClient->EscapeString($text), 'suggestions');
     $suggestions = array();
     if ($results['total'] != 0) {
         foreach ($results['matches'] as $match) {
             $suggestion = new Suggestion($match['id']);
             $suggestions[] = $suggestion;
         }
     }
     return $suggestions;
 }