Exemple #1
0
 static function getEntities($options = array())
 {
     $s = new LsSphinxClient();
     $s->SetServer('localhost', 3312);
     //$s->SetMatchMode(SPH_MATCH_ANY);
     $s->SetFieldWeights(array('name' => 3, 'aliases' => 3));
     if (@$options['list_ids']) {
         $listIds = explode(',', $options['list_ids']);
         if (is_array($listIds) && count($listIds)) {
             $s->setFilter('list_ids', $listIds);
         }
     }
     //no query produces no results
     if (!($query = @$options['q'])) {
         $query = 'bleahbleahbleahbleahbleahbleahbleah';
     }
     $query = LsSphinxClient::cleanQuery($query);
     $query = $s->EscapeString($query);
     //filter by type_ids, if requested
     if ($typeIds = @$options['type_ids']) {
         $s->SetFilter('type_ids', explode(',', $typeIds));
     }
     //paging
     if (!($num = @$options['num'])) {
         $num = 20;
     }
     if (!($page = @$options['page'])) {
         $page = 1;
     }
     $s->SetLimits(($page - 1) * $num, (int) $num);
     $result = $s->Query($query, 'entities entities_delta');
     if ($result === false) {
         throw new Exception("Sphinx search failed: " . $s->getLastError());
     }
     return $result;
 }