Beispiel #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;
 }
Beispiel #2
0
 static function getSphinxHits($query, $page = 1, $num = 20, array $listIds = null, $aliases = true, $primary_ext = null)
 {
     $s = new LsSphinxClient();
     $s->SetServer('localhost', 3312);
     $s->SetMatchMode(SPH_MATCH_EXTENDED);
     $s->SetFieldWeights(array('name' => 3, 'aliases' => 3));
     $s->SetLimits(($page - 1) * $num, $num);
     if (is_array($listIds) && count($listIds)) {
         $s->setFilter('list_ids', $listIds);
     }
     $query = $s->buildEntityQuery($query, $aliases, $primary_ext);
     $result = $s->Query($query, 'entities entities_delta');
     if ($result === false) {
         throw new Exception("Sphinx search failed: " . $s->getLastError());
     }
     return $result;
 }
Beispiel #3
0
 static function getSphinxIds(LsSphinxClient $s, $query = null)
 {
     $s->setSortMode(SPH_SORT_ATTR_DESC, 'created_at');
     $query = LsSphinxClient::cleanQuery($query);
     $result = $s->Query($query, 'notes notes_delta');
     if ($result === false) {
         throw new Exception("Sphinx search failed: " . $s->getLastError());
     }
     if ($result['total_found'] > 0 && isset($result['matches'])) {
         return array_keys($result['matches']);
     }
     return null;
 }