SetSortMode() public method

set matches sorting mode
public SetSortMode ( $mode, $sortby = "" )
コード例 #1
0
 /**
  * Инициализация сфинкса
  */
 protected function InitSphinx()
 {
     /**
      * Получаем объект Сфинкса(из Сфинкс АПИ)
      */
     $this->oSphinx = new SphinxClient();
     $this->oSphinx->SetServer(Config::Get('module.search.sphinx.host'), intval(Config::Get('module.search.sphinx.port')));
     /**
      * Устанавливаем тип сортировки
      */
     $this->oSphinx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC, @id DESc");
 }
コード例 #2
0
 private function get_sugg_trigrams($word, SearchEngineOptions $options)
 {
     $trigrams = $this->BuildTrigrams($word);
     $query = "\"{$trigrams}\"/1";
     $len = strlen($word);
     $this->resetSphinx();
     $this->suggestionClient->SetMatchMode(SPH_MATCH_EXTENDED2);
     $this->suggestionClient->SetRankingMode(SPH_RANK_WORDCOUNT);
     $this->suggestionClient->SetFilterRange("len", $len - 2, $len + 4);
     $this->suggestionClient->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC");
     $this->suggestionClient->SetLimits(0, 10);
     $indexes = [];
     foreach ($options->getDataboxes() as $databox) {
         $indexes[] = 'suggest' . $this->CRCdatabox($databox);
     }
     $index = implode(',', $indexes);
     $res = $this->suggestionClient->Query($query, $index);
     if ($this->suggestionClient->Status() === false) {
         return [];
     }
     if (!$res || !isset($res["matches"])) {
         return [];
     }
     $words = [];
     foreach ($res["matches"] as $match) {
         $words[] = $match['attrs']['keyword'];
     }
     return $words;
 }
コード例 #3
0
ファイル: Searcher.php プロジェクト: ntemple/intelli-plancake
 /**
  *
  * @param string $query
  * @return array of integers - taskIds
  */
 public static function searchTasks($query)
 {
     $fieldWeights = array('description' => 10, 'note' => 6);
     $indexName = 'plancake_tasks';
     $client = new SphinxClient();
     // $client->SetServer (sfConfig::get('app_sphinx_host'), sfConfig::get('app_sphinx_port'));
     $client->SetFilter("author_id", array(PcUserPeer::getLoggedInUser()->getId()));
     $client->SetConnectTimeout(1);
     $client->SetMatchMode(SPH_MATCH_ANY);
     $client->SetSortMode(SPH_SORT_RELEVANCE);
     $client->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
     $client->SetArrayResult(true);
     $client->SetFieldWeights($fieldWeights);
     $client->setLimits(0, 100);
     $results = $client->query($client->EscapeString($query), $indexName);
     if ($results === false) {
         $error = "Sphinx Error - " . $client->GetLastError();
         sfErrorNotifier::alert($error);
     }
     $ids = array();
     if (isset($results['matches']) && count($results['matches'])) {
         foreach ($results['matches'] as $match) {
             $ids[] = $match['id'];
         }
     }
     return PcTaskPeer::retrieveByPKs($ids);
 }
コード例 #4
0
ファイル: Search.php プロジェクト: kastner/pgboard
 function query($query, $index, $offset = 0)
 {
     require_once DIR . "lib/sphinx/sphinxapi.php";
     $sphinx = new SphinxClient();
     $sphinx->setServer(SPHINX_HOST, SPHINX_PORT);
     $sphinx->SetLimits($offset, 100, 10000000);
     $sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
     $sphinx->SetSortMode(SPH_SORT_ATTR_DESC, 'date_posted');
     $res = $sphinx->Query($query, $index);
     return $res;
 }
コード例 #5
0
ファイル: Sphinx.class.php プロジェクト: AntiqS/altocms
 /**
  * Инициализация сфинкса
  */
 protected function InitSphinx()
 {
     // * Получаем объект Сфинкса(из Сфинкс АПИ)
     $this->oSphinx = new SphinxClient();
     $sHost = Config::Get('plugin.sphinx.host');
     $nPort = 0;
     if (strpos($sHost, ':')) {
         list($sHost, $nPort) = explode(':', $sHost);
     }
     // * Подключаемся
     $this->oSphinx->SetServer($sHost, intval($nPort));
     $sError = $this->GetLastError();
     if ($sError) {
         $sError .= "\nhost:{$sHost}";
         $this->LogError($sError);
         return false;
     }
     // * Устанавливаем тип сортировки
     $this->oSphinx->SetSortMode(SPH_SORT_EXTENDED, "@weight DESC, @id DESc");
 }
コード例 #6
0
 /**
  * 获取竞品信息
  * @author zhangxiao@dachuwang.com
  */
 public function get_list($friend_id = null, $city_id = null, $key, $key_word = null, $cate_name = null, $offset = 0, $page_size = 10)
 {
     $key = $key ?: $this->input->get_post('search_key', TRUE);
     $key_word = $key_word ?: $this->input->get_post('search_value', TRUE);
     $cate_name = $cate_name ?: $this->input->get_post('cate_name', TRUE);
     $friend_id = $friend_id ?: $this->input->get_post('friend_id', TRUE);
     $city_id = $city_id ?: $this->input->get_post('city_id', TRUE);
     //使用sphinx
     $s = new SphinxClient();
     $s->setServer(C('service.spider'), 9312);
     $s->setMatchMode(SPH_MATCH_EXTENDED2);
     $s->setLimits($offset, $page_size, 100000);
     $s->setMaxQueryTime(30);
     //筛选友商城市
     if ($city_id != C('open_cities.quanguo.id')) {
         $s->setFilter('city_id', array($city_id));
     }
     //筛选友商站点
     if ($friend_id != C('anti_sites.all.id')) {
         $s->setFilter('site_id', array($friend_id));
     }
     $s->SetSortMode(SPH_SORT_EXTENDED, "product_id asc");
     $fields = '';
     //筛选关键字
     if ($key_word) {
         if ($key == 'product_name') {
             $fields .= '@title "' . $key_word . '" ';
         } elseif ($key == 'product_id') {
             $s->setFilter('product_id', array($key_word));
         } elseif ($key == 'sku_number') {
             $auto_ids = $this->_get_product_by_sku_num($key_word);
             if ($auto_ids) {
                 $s->setFilter('auto_id', $auto_ids);
             } else {
                 return array('total' => 0, 'data' => []);
             }
         }
     }
     //筛选友商品类名称
     if ($cate_name) {
         $fields .= '@category_name "' . $cate_name . '" ';
     }
     $result = $s->query($fields, 'anti_products');
     if (isset($result['matches'])) {
         $list = array_column($result['matches'], 'attrs');
     } else {
         $list = array();
     }
     $final_list = $this->_assemble_sku_num($list);
     $return = array('total' => $result['total'], 'data' => $final_list);
     return $return;
 }
コード例 #7
0
ファイル: actions.class.php プロジェクト: voota/voota
 private function institutions($data)
 {
     $q = $this->getRequestParameter("q", '');
     if (!$q) {
         throw new BadRequestException('A search string must be provided.');
     }
     $page = $this->getRequestParameter("page", '1');
     $limit = $this->getRequestParameter("limit", self::PAGE_SIZE);
     $culture = $this->getRequestParameter("culture", 'es');
     $type = $this->getRequestParameter("type", false);
     $this->getUser()->setCulture($culture);
     $cl = new SphinxClient();
     $dbConf = Propel::getConfiguration();
     $dsn = $dbConf['datasources']['propel']['connection']['dsn'];
     $sphinxServer = sfConfig::get('sf_sphinx_server');
     $cl->SetServer($sphinxServer, 3312);
     $this->limit = 1000;
     $cl->SetLimits(0, $this->limit, $this->limit);
     $cl->SetArrayResult(true);
     #instituciones
     $this->res = $cl->Query($q, "institucion_{$culture}");
     $cl->SetFieldWeights(array('vanity' => 5));
     $cl->SetSortMode(SPH_SORT_RELEVANCE);
     $institutions = array();
     if ($this->res !== false) {
         if (isset($this->res["matches"]) && is_array($this->res["matches"])) {
             $c = new Criteria();
             $list = array();
             foreach ($this->res["matches"] as $idx => $match) {
                 $list[] = $match['id'];
             }
             $c->add(InstitucionPeer::ID, $list, Criteria::IN);
             $c->addAscendingOrderByColumn(InstitucionPeer::ORDEN);
             //$instituciones = InstitucionPeer::doSelect($c);
             $pager = new sfPropelPager('Institucion', $limit);
             $pager->setCriteria($c);
             $pager->setPage($this->getRequestParameter('page', $page));
             $pager->init();
             foreach ($pager->getResults() as $aInstitution) {
                 $institution = new Institution();
                 $institution->setId($aInstitution->getId());
                 $institution->setVanity($aInstitution->getVanity());
                 $institution->setName($aInstitution->getNombreCorto());
                 $institution->setLongName($aInstitution->getNombre());
                 $institutions[] = $institution;
             }
         }
     }
     return $institutions;
 }
コード例 #8
0
 protected function resetClient()
 {
     $this->sphinxClient->ResetFilters();
     $this->sphinxClient->ResetGroupBy();
     $this->sphinxClient->ResetOverrides();
     $this->sphinxClient->SetLimits(0, 20);
     $this->sphinxClient->SetArrayResult(true);
     $this->sphinxClient->SetFieldWeights(array());
     $this->sphinxClient->SetIDRange(0, 0);
     $this->sphinxClient->SetIndexWeights(array());
     $this->sphinxClient->SetMatchMode(SPH_MATCH_EXTENDED2);
     $this->sphinxClient->SetRankingMode(SPH_RANK_NONE);
     $this->sphinxClient->SetSortMode(SPH_SORT_RELEVANCE, "");
     $this->sphinxClient->SetSelect("*");
 }
コード例 #9
0
ファイル: suggest.php プロジェクト: gagoel/sphinxsearch
function MakeSuggestion($keyword)
{
    $trigrams = BuildTrigrams($keyword);
    $query = "\"{$trigrams}\"/1";
    $len = strlen($keyword);
    $delta = LENGTH_THRESHOLD;
    $cl = new SphinxClient();
    $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
    $cl->SetRankingMode(SPH_RANK_WORDCOUNT);
    $cl->SetFilterRange("len", $len - $delta, $len + $delta);
    $cl->SetSelect("*, @weight+{$delta}-abs(len-{$len}) AS myrank");
    $cl->SetSortMode(SPH_SORT_EXTENDED, "myrank DESC, freq DESC");
    $cl->SetArrayResult(true);
    // pull top-N best trigram matches and run them through Levenshtein
    $cl->SetLimits(0, TOP_COUNT);
    $res = $cl->Query($query, "suggest");
    if (!$res || !$res["matches"]) {
        return false;
    }
    if (SUGGEST_DEBUG) {
        print "--- DEBUG START ---\n";
        foreach ($res["matches"] as $match) {
            $w = $match["attrs"]["keyword"];
            $myrank = @$match["attrs"]["myrank"];
            if ($myrank) {
                $myrank = ", myrank={$myrank}";
            }
            // FIXME? add costs?
            // FIXME! does not work with UTF-8.. THIS! IS!! PHP!!!
            $levdist = levenshtein($keyword, $w);
            print "id={$match['id']}, weight={$match['weight']}, freq={$match[attrs][freq]}{$myrank}, word={$w}, levdist={$levdist}\n";
        }
        print "--- DEBUG END ---\n";
    }
    // further restrict trigram matches with a sane Levenshtein distance limit
    foreach ($res["matches"] as $match) {
        $suggested = $match["attrs"]["keyword"];
        if (levenshtein($keyword, $suggested) <= LEVENSHTEIN_THRESHOLD) {
            return $suggested;
        }
    }
    return $keyword;
}
コード例 #10
0
ファイル: Search_model.php プロジェクト: asmenglei/lanxiao
 public function getResultByTag($keyword = "", $offset = 0, $limit = 0, $searchParams = array())
 {
     $sphinx = $this->config->item('sphinx');
     $query = array();
     $cl = new SphinxClient();
     $cl->SetServer($sphinx['ip'], $sphinx['port']);
     // 注意这里的主机
     $cl->SetConnectTimeout($sphinx['timeout']);
     $cl->SetArrayResult(true);
     //         $cl->SetIDRange(89,90);//过滤ID
     if (isset($searchParams['provice_sid']) && $searchParams['provice_sid']) {
         $cl->setFilter('provice_sid', array($searchParams['provice_sid']));
     }
     if (isset($searchParams['city_sid']) && $searchParams['city_sid']) {
         $cl->setFilter('city_sid', array($searchParams['city_sid']));
     }
     if (isset($searchParams['piccode']) && $searchParams['piccode']) {
         $cl->setFilter('piccode', array($searchParams['piccode']));
     }
     if (isset($searchParams['recent']) && $searchParams['recent']) {
         $cl->SetFilterRange('createtime', time() - 86400 * 30, time());
         //近期1个月
     }
     if (isset($searchParams['searchtype']) && $searchParams['searchtype']) {
         //精确:模糊
         $searchtype = SPH_MATCH_ALL;
     } else {
         $searchtype = SPH_MATCH_ANY;
     }
     $cl->SetLimits($offset, $limit);
     $cl->SetMatchMode($searchtype);
     // 使用多字段模式
     $cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc,@id desc");
     $index = "*";
     $query = $cl->Query($keyword, $index);
     $cl->close();
     return $query;
 }
コード例 #11
0
 $mode = SPH_MATCH_ALL;
 if (strpos($q, '~') === 0) {
     $q = preg_replace('/^\\~/', '', $q);
     if (substr_count($q, ' ') > 1) {
         //over 2 words
         $mode = SPH_MATCH_ANY;
     }
 } elseif (strpos($q, '-') !== FALSE || strpos($q, '|') !== FALSE) {
     $mode = SPH_MATCH_EXTENDED;
 }
 $index = "gaz";
 $cl = new SphinxClient();
 $cl->SetServer($CONF['sphinx_host'], $CONF['sphinx_port']);
 $cl->SetWeights(array(100, 1));
 $cl->SetMatchMode($mode);
 $cl->SetSortMode(SPH_SORT_EXTENDED, "score ASC, @relevance DESC");
 $cl->SetLimits(0, 20);
 $res = $cl->Query($q, $index);
 // --------------
 if (!empty($_GET['debug'])) {
     print_r($res);
 }
 if ($res === false) {
     print "\tQuery failed: -- please try again later.\n";
     exit;
 } else {
     if ($cl->GetLastWarning()) {
         print "\nWARNING: " . $cl->GetLastWarning() . "\n\n";
     }
     $query_info = "Query '{$q}' retrieved " . count($res['matches']) . " of {$res['total_found']} matches in {$res['time']} sec.\n";
 }
コード例 #12
0
ファイル: sphinx_search.php プロジェクト: duynhan07/elink
 function draw2()
 {
     $keywords = AZLib::getParam('keywords');
     $total_item = 0;
     $search_result = false;
     $items = array();
     $paging = '';
     $cmd = '';
     $cat_search_id = 0;
     $item_array = array();
     $listCat = array();
     if ($keywords) {
         //AZLib::getCats();
         require "./includes/sphinxapi.class.php";
         foreach (CGlobal::$allCategories as $value) {
             if ($value['parent_id'] == 0) {
                 $cat_list[$value['id']] = $value['brief_name'];
             }
         }
         $category = $this->getTotalPerCategory($keywords);
         foreach ($category as $row) {
             $row['brief_name'] = isset($cat_list[$row['level_1_catid']]) && $cat_list[$row['level_1_catid']] ? $cat_list[$row['level_1_catid']] : "Khác";
             $listCat[$row['level_1_catid']] = array("level_1_catid" => $row["level_1_catid"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
         }
         $total = 0;
         $catid = 0;
         $catActive = '';
         $total_cat = 0;
         if ($listCat) {
             $first_val = array_slice($listCat, 0, 1);
             $total = $first_val[0]['count_ad'];
             $catid = $first_val[0]['level_1_catid'];
             $catActive = $first_val[0]['brief_name'];
             $total_cat = count($listCat);
         }
         $i = 0;
         $allrecord = 0;
         $otherCat = '';
         $cat_content = "";
         foreach ($listCat as $cat) {
             if ($i < 3) {
                 $active = $i == 0 ? "class=\"active\"" : "";
                 $cat_content .= "<li id=\"tab_{$i}\" {$active} onclick=\"javascript:acive_tab_cat(this);\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></li>";
             } else {
                 $otherCat .= "<div class=\"other\"><a href=\"javascript:void(0);\" onclick=\"javascript:search_cat({$cat['level_1_catid']},{$cat['count_ad']},1,0);acive_tab_cat(this);\" id=\"tab_{$i}\"><span id=\"kby_{$cat['level_1_catid']}\">" . $cat['brief_name'] . " <font style=\"color: #5a7e92;font-weight: normal;\">(" . $cat['count_ad'] . ")</font></span></a></div>";
             }
             $i++;
             $allrecord = $allrecord + $cat['count_ad'];
         }
         $display->add("cat_content", $cat_content);
         $display->add("CatActiveId", $catid);
         $display->add("catActive", $catActive);
         $display->add("listCat", $listCat);
         $display->add("allrecord", $allrecord);
         $display->add("otherCat", str_replace(array(chr(13), chr(10)), "", $otherCat));
         $display->add("total_cat", $total_cat);
         //Init for sphinx search paging
         $pager = new Pager();
         //config
         $limit = SEARCH_LIMIT;
         $pager->type = "search";
         $pager->catid = $catid;
         $pager->total = $total;
         $pager->limit = $limit;
         $pager->page_param = 'page';
         $pager->page = 1;
         $offset = $pager->get_offset();
         $limit_from = $pager->limit_from();
         $limit_to = $pager->limit_to();
         //Sphinx search by Nova
         $q = $keywords;
         $mode = SPH_MATCH_EXTENDED2;
         //Init config
         $host = SPHINX_SERVER;
         $port = SPHINX_PORT;
         //$index 		= SPHINX_INDEX;
         $index = "enbac delta";
         $filtervals = array();
         $ranker = SPH_RANK_WORDCOUNT;
         $cl = new SphinxClient();
         $cl->SetServer($host, $port);
         $cl->SetConnectTimeout(1);
         $cl->SetWeights(array(100, 1));
         $cl->SetMatchMode($mode);
         //filter
         if ($catid) {
             $cl->SetFilter('level_1_catid', array($catid));
         }
         $cl->SetFilter('status', array('1'));
         $cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
         //$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
         //$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
         //$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
         $cl->SetSortMode(SPH_SORT_EXPR, "@weight");
         //Sort theo trọng số
         //SPH_RANK_WORDCOUNT
         //SPH_MATCH_EXTENDED2
         //end filter
         $cl->SetLimits($offset, $limit, 10000);
         $cl->SetRankingMode($ranker);
         $cl->SetArrayResult(true);
         $res = $cl->Query($q, $index);
         /*echo '<pre>';
         		print_r($res["matches"]);*/
         if ($res && isset($res["matches"])) {
             if (is_array($res["matches"])) {
                 foreach ($res["matches"] as $results) {
                     $list_item_id[] = $results['id'];
                 }
             }
             $comma_separated = join(",", $list_item_id);
         }
         if ($total) {
             if ($limit_to > $total) {
                 $limit_to = $total;
             }
             $comma_separated = join(",", $list_item_id);
             if ($comma_separated) {
                 //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN($comma_separated) AND status=1 ORDER BY up_time DESC";
                 //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN($comma_separated) AND status=1  AND state=0 ORDER BY find_in_set(id,'$comma_separated')";
                 $sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_catid,category_id,description,img_url, img_server FROM item WHERE id IN({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')";
                 $search_result = DB::query($sql);
                 $pager->total = $total;
                 $paging = $pager->page_link();
             }
         }
     }
     $highlight = '';
     if ($keywords) {
         $highlight = $str_search = str_replace(array('+', '/', '|', '-', '*'), "", $keywords);
         $highlight = AZLib::trimSpace($highlight);
         $highlight = str_replace("'", '', $highlight);
         $highlight = str_replace("&#39;", '', $highlight);
         $highlight = str_replace("&quot;", '', $highlight);
     }
     $highlight1 = '';
     if ($highlight) {
         $arr = explode(' ', $highlight);
         if ($arr) {
             $highlight = "";
             foreach ($arr as $word) {
                 $highlight = ($highlight ? $highlight . ', ' : '') . "'{$word}'";
                 $highlight1 = ($highlight1 ? $highlight1 . ',' : '') . $word;
             }
         }
     }
     if ($keywords && $search_result) {
         while ($item = mysql_fetch_assoc($search_result)) {
             $item['profile_url'] = WEB_DIR . $item['user_name'];
             $item['name_hl'] = AZLib::HighLightKeyword(strip_tags(AZLib::filter_title($item['name'])), $highlight1);
             $item_time = TIME_NOW - $item['up_time'];
             //neu nho hon 1h thi tinh ra phut
             if ($item_time < 3600) {
                 $item['item_time'] = floor($item_time / 60) . " phút trước đây";
             } elseif ($item_time < 86400) {
                 $item['item_time'] = floor($item_time / 3600) . " giờ trước đây";
             } else {
                 $item['item_time'] = date('\\n\\gà\\y j \\t\\há\\n\\g n', $item['up_time']);
             }
             $item['description'] = AZLib::HighLightKeyword(AZLib::delDoubleSpace(AZLib::trimSpace(strip_tags(AZLib::post_db_parse_html(preg_replace('/\\[[0-9]{1,3}\\]/', '', $item['description']))))), $highlight1, 35, "background:yellow;font-size:14px;font-weight:bold;color:blue;");
             $ebname = AZLib::safe_title($item['name']);
             $ebname_tmp = substr(AZLib::safe_title($item['name']), 0, 20);
             if (isset(CGlobal::$allCategories[$item['category_id']])) {
                 $item['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname . '&nice_name=' . CGlobal::$allCategories[$item['category_id']]['nice_name']);
                 $item['item_url_tmp'] = WEB_ROOT . CGlobal::$allCategories[$item['category_id']]['nice_name'] . '/p' . $item['id'] . '/' . $ebname_tmp . '...';
             } else {
                 $item['item_url'] = WEB_DIR . AZRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname);
                 $item['item_url_tmp'] = WEB_ROOT . 'p' . $item['id'] . '/' . $ebname_tmp . '...';
             }
             if ($item['img_url']) {
                 $item['img_url'] = AZLib::getImageThumb($item['img_url'], 110, 0, 1, $item['img_server']);
             }
             $item['price'] = number_format($item['price'], 0, ',', '.');
             $item_array[] = $item;
         }
     }
     global $start_rb;
     $mtime = microtime();
     $mtime = explode(" ", $mtime);
     $mtime = $mtime[1] + $mtime[0];
     $end_rb = $mtime;
     $search_time = round($end_rb - $start_rb, 3);
     $display->add('limit_from', $limit_from);
     $display->add('limit_to', $limit_to);
     $display->add('search_time', $search_time);
     $display->add('keywords', $keywords);
     $display->add('base_url', WEB_ROOT);
     $display->add('highlight', $highlight);
     $display->add('total_item_cat', $total);
     $display->add('name_item_cat', $catActive);
     $display->add('block_id', Module::$block_id);
     $display->add('paging', $paging);
     $display->add('items', $item_array);
     $display->output('sphinx_search');
 }
コード例 #13
0
 public function index()
 {
     C('TOKEN_ON', false);
     $seo = seo();
     $this->assign("seo", $seo);
     if (isset($_GET['q'])) {
         G('search');
         //关键字
         $q = Input::forSearch(safe_replace($this->_get("q")));
         $q = htmlspecialchars(strip_tags($q));
         //时间范围
         $time = $this->_get("time");
         //模型
         $mid = (int) $this->_get("modelid");
         //栏目
         $catid = (int) $this->_get("catid");
         //排序
         $order = array("adddate" => "DESC", "searchid" => "DESC");
         //搜索历史记录
         $shistory = cookie("shistory");
         if (!$shistory) {
             $shistory = array();
         }
         $model = F("Model");
         $category = F("Category");
         if (trim($_GET['q']) == '') {
             header('Location: ' . U("Search/Index/index"));
             exit;
         }
         array_unshift($shistory, $q);
         $shistory = array_slice(array_unique($shistory), 0, 10);
         //加入搜索历史
         cookie("shistory", $shistory);
         $where = array();
         //每页显示条数
         $pagesize = $this->config['pagesize'] ? $this->config['pagesize'] : 10;
         //缓存时间
         $cachetime = (int) $this->config['cachetime'];
         //按时间搜索
         if ($time == 'day') {
             //一天
             $search_time = time() - 86400;
             $where['adddate'] = array("GT", $search_time);
         } elseif ($time == 'week') {
             //一周
             $search_time = time() - 604800;
             $where['adddate'] = array("GT", $search_time);
         } elseif ($time == 'month') {
             //一月
             $search_time = time() - 2592000;
             $where['adddate'] = array("GT", $search_time);
         } elseif ($time == 'year') {
             //一年
             $search_time = time() - 31536000;
             $where['adddate'] = array("GT", $search_time);
         } else {
             $search_time = 0;
         }
         //可用数据源
         $this->config['modelid'] = $this->config['modelid'] ? $this->config['modelid'] : array();
         //按模型搜索
         if ($mid && in_array($mid, $this->config['modelid'])) {
             $where['modelid'] = array("EQ", (int) $mid);
         }
         //按栏目搜索
         if ($catid) {
             //不支持多栏目搜索,和父栏目搜索。
             $where['catid'] = array("EQ", (int) $catid);
         }
         //分页模板
         $TP = '共有{recordcount}条信息&nbsp;{pageindex}/{pagecount}&nbsp;{first}{prev}{liststart}{list}{listend}{next}{last}';
         //如果开启sphinx
         if ($this->config['sphinxenable']) {
             import("Sphinxapi", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/');
             $sphinxhost = $this->config['sphinxhost'];
             $sphinxport = $this->config['sphinxport'];
             $cl = new SphinxClient();
             //设置searchd的主机名和TCP端口
             $cl->SetServer($sphinxhost, $sphinxport);
             //设置连接超时
             $cl->SetConnectTimeout(1);
             //控制搜索结果集的返回格式
             $cl->SetArrayResult(true);
             //设置全文查询的匹配模式 api http://docs.php.net/manual/zh/sphinxclient.setmatchmode.php
             $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
             //设置排名模式 api http://docs.php.net/manual/zh/sphinxclient.setrankingmode.php
             $cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
             //按一种类似SQL的方式将列组合起来,升序或降序排列。用weight是权重排序
             $cl->SetSortMode(SPH_SORT_EXTENDED, "@weight desc");
             //设置返回结果集偏移量和数目
             $page = (int) $this->_get(C("VAR_PAGE"));
             $page = $page < 1 ? 1 : $page;
             $offset = $pagesize * ($page - 1);
             $cl->SetLimits($offset, $pagesize, $pagesize > 1000 ? $pagesize : 1000);
             if (in_array($time, array("day", "week", "month", "year"))) {
                 //过滤时间
                 $cl->SetFilterRange('adddate', $search_time, time(), false);
             }
             if ($mid && in_array($mid, $this->config['modelid'])) {
                 //过滤模型
                 $cl->SetFilter('modelid', (int) $mid);
             }
             if ($catid) {
                 //过滤栏目
                 $cl->SetFilter('catid', (int) $catid);
             }
             //执行搜索 api http://docs.php.net/manual/zh/sphinxclient.query.php
             $res = $cl->Query($q, "*");
             //信息总数
             $count = $res['total'];
             //如果结果不为空
             if (!empty($res['matches'])) {
                 $result_sphinx = $res['matches'];
             }
             $result = array();
             //数组重新组合
             foreach ($result_sphinx as $k => $v) {
                 $result[$k] = array("searchid" => $v['id'], "adddate" => $v['attrs']['adddate'], "catid" => $v['attrs']['catid'], "id" => $v['attrs']['id'], "modelid" => $v['attrs']['modelid']);
             }
             $words = array();
             //搜索关键字
             foreach ($res['words'] as $k => $v) {
                 $words[] = $k;
             }
             $page = page($count, $pagesize);
             $page->SetPager('default', $TP, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
             $this->assign("Page", $page->show('default'));
         } else {
             import("Segment", APP_PATH . C("APP_GROUP_PATH") . '/Search/Class/');
             $Segment = new Segment();
             //分词结果
             $segment_q = $Segment->get_keyword($Segment->split_result($q));
             $words = explode(" ", $segment_q);
             if (!empty($segment_q)) {
                 $where['_string'] = " MATCH (`data`) AGAINST ('{$segment_q}' IN BOOLEAN MODE) ";
             } else {
                 //这种搜索最不行
                 $where['data'] = array('like', "%{$q}%");
             }
             //查询结果缓存
             if ($cachetime) {
                 //统计
                 $count = M("Search")->cache(true, $cachetime)->where($where)->count();
                 $page = page($count, $pagesize);
                 $result = M("Search")->cache(true, $cachetime)->where($where)->limit($page->firstRow . ',' . $page->listRows)->order($order)->select();
             } else {
                 $count = M("Search")->where($where)->count();
                 $page = $this->page($count, $pagesize);
                 $result = M("Search")->where($where)->limit($page->firstRow . ',' . $page->listRows)->order($order)->select();
             }
             $page->SetPager('default', $TP, array("listlong" => "6", "first" => "首页", "last" => "尾页", "prev" => "上一页", "next" => "下一页", "list" => "*", "disabledclass" => ""));
             $this->assign("Page", $page->show('default'));
         }
         //搜索结果处理
         if ($result && is_array($result)) {
             foreach ($result as $k => $r) {
                 $modelid = $r['modelid'];
                 $id = $r['id'];
                 $tablename = ucwords($model[$modelid]['tablename']);
                 if ($tablename) {
                     $result[$k] = M($tablename)->where(array("id" => $id))->find();
                 }
             }
         }
         //搜索记录
         if (strlen($q) < 17 && strlen($q) > 1 && $result) {
             $res = M("SearchKeyword")->where(array('keyword' => $q))->find();
             if ($res) {
                 //关键词搜索数+1
                 M("SearchKeyword")->where(array('keyword' => $q))->setInc("searchnums");
             } else {
                 //关键词转换为拼音
                 load("@.iconvfunc");
                 $pinyin = gbk_to_pinyin(iconv('utf-8', 'gbk//IGNORE', $q));
                 if (is_array($pinyin)) {
                     $pinyin = implode('', $pinyin);
                 }
                 M("SearchKeyword")->add(array('keyword' => $q, 'searchnums' => 1, 'data' => $segment_q, 'pinyin' => $pinyin));
             }
         }
         //相关搜索功能
         if ($this->config['relationenble']) {
             $map = array();
             //相关搜索
             if (!empty($segment_q)) {
                 $relation_q = str_replace(' ', '%', $segment_q);
             } else {
                 $relation_q = $q;
             }
             $map['_string'] = " MATCH (`data`) AGAINST ('%{$relation_q}%' IN BOOLEAN MODE) ";
             $relation = M("SearchKeyword")->where($map)->select();
             $this->assign("relation", $relation);
         }
         foreach ($this->config['modelid'] as $modelid) {
             $source[$modelid] = array("name" => $model[$modelid]['name'], "modelid" => $modelid);
         }
         //搜索结果
         $this->assign("result", $result);
         //运行时间
         $search_time = G('search', 'end', 6);
         $this->assign("count", $count ? $count : 0);
         $this->assign("search_time", $search_time);
         $this->assign("keyword", $q);
         $this->assign("category", $category);
         $this->assign("source", $source);
         $this->assign("time", $time);
         $this->assign("modelid", $mid);
         $this->assign("shistory", $shistory);
         //分词后的搜索关键字
         $this->assign("words", $words);
         $this->display("search");
     } else {
         $this->display();
     }
 }
コード例 #14
0
ファイル: sort_attr_asc.php プロジェクト: ravshanium/sphinx
<?php

require "sphinxapi.php";
$cl = new SphinxClient();
$cl->SetSortMode(SPH_SORT_ATTR_ASC, 'sortby');
$cl->Query('query');
コード例 #15
0
ファイル: ajax_item.ajax.php プロジェクト: hqd276/bigs
 function search()
 {
     global $display;
     $catid = (int) Url::get('catid', 0);
     $total = (int) Url::get('total', 0);
     $page = (int) Url::get('page', 0);
     $tt = (int) Url::get('tt', 0);
     $keywords = Url::get('keywords');
     require "./includes/sphinxapi.class.php";
     EClassApi::getCats();
     foreach (CGlobal::$allCategories as $value) {
         if ($value['parent_id'] == 0) {
             $cat_list[$value['id']] = $value['brief_name'];
         }
     }
     $category = $this->getCategory($keywords);
     foreach ($category as $row) {
         $row['brief_name'] = isset($cat_list[$row['level_1_category_id']]) && $cat_list[$row['level_1_category_id']] ? $cat_list[$row['level_1_category_id']] : "Khác";
         $listCat[$row['level_1_category_id']] = array("level_1_category_id" => $row["level_1_category_id"], "brief_name" => $row['brief_name'], "count_ad" => $row['@count']);
     }
     $catActive = '';
     $total_cat = 0;
     if ($listCat) {
         $catActive = $listCat[$catid]['brief_name'];
         $total_cat = count($listCat);
     }
     $i = 0;
     $allrecord = 0;
     $otherCat = '';
     $cat_content = "";
     foreach ($listCat as $cat) {
         $allrecord = $allrecord + $cat['count_ad'];
     }
     $display->add("cat_content", $cat_content);
     $display->add("CatActiveId", $catid);
     $display->add("catActive", $catActive);
     $display->add("listCat", $listCat);
     $display->add("allrecord", $allrecord);
     $display->add("total_cat", $total_cat);
     $pager = new Pager();
     $limit = SEARCH_LIMIT;
     $pager->type = "search";
     $pager->catid = $catid;
     $pager->total = $total;
     $pager->limit = $limit;
     $pager->page_param = 'page';
     $pager->page = $page;
     $offset = $pager->get_offset();
     $limit_from = $pager->limit_from();
     $limit_to = $pager->limit_to();
     //Sphinx search by Nova
     $q = $keywords;
     //$mode = SPH_MATCH_ALL;
     $mode = SPH_MATCH_EXTENDED2;
     //Init config
     $host = SPHINX_SERVER;
     $port = SPHINX_PORT;
     $index = 'enbac';
     $filtervals = array();
     //$ranker = SPH_RANK_PROXIMITY_BM25;
     $ranker = SPH_RANK_WORDCOUNT;
     $cl = new SphinxClient();
     $cl->SetServer($host, $port);
     $cl->SetConnectTimeout(1);
     $cl->SetWeights(array(100, 1));
     $cl->SetMatchMode($mode);
     $cl->SetFilter('level_1_category_id', array($catid));
     $cl->SetFilter('status', array('1'));
     $cl->SetFieldWeights(array('user_name' => 10000, 'name' => 1000, 'description' => 1));
     //$cl->SetSortMode( SPH_SORT_EXTENDED, 'up_time DESC' );
     //$cl->SetSortMode( SPH_SORT_RELEVANCE);//Sort theo kq chính xác nhất
     //$cl->SetSortMode ( SPH_SORT_EXPR, "@weight + ( user_karma + ln(pageviews) )*0.1");
     $cl->SetSortMode(SPH_SORT_EXPR, "@weight");
     //Sort theo trọng số
     $cl->SetLimits($offset, $limit, 10000);
     $cl->SetRankingMode($ranker);
     $cl->SetArrayResult(true);
     $res = $cl->Query($q, $index);
     if ($res && isset($res["matches"])) {
         if (is_array($res["matches"])) {
             foreach ($res["matches"] as $results) {
                 $list_item_id[] = $results['id'];
             }
         }
         $comma_separated = join(",", $list_item_id);
     }
     if ($total) {
         if ($limit_to > $total) {
             $limit_to = $total;
         }
         $comma_separated = join(",", $list_item_id);
         if ($comma_separated) {
             //$sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ($comma_separated) AND status=1 ORDER BY up_time DESC";
             $sql = "SELECT id,name,up_time,price,user_id,user_name, level_1_category_id,category_id,description,original_image_url, img_server FROM item WHERE id IN ({$comma_separated}) AND status=1 ORDER BY find_in_set(id,'{$comma_separated}')";
             $search_result = DB::query($sql);
             $pager->total = $total;
             $paging = $pager->page_link();
         }
     }
     $item_array = array();
     if ($search_result) {
         EClassApi::getCats();
         $highlight = '';
         if ($keywords) {
             $highlight = $str_search = str_replace(array('+', '/', '|', '-', '*'), "", $keywords);
             $highlight = EClassApi::trimSpace($highlight);
             $highlight = str_replace("'", '', $highlight);
             $highlight = str_replace("&#39;", '', $highlight);
             $highlight = str_replace("&quot;", '', $highlight);
         }
         $highlight1 = '';
         if ($highlight) {
             $arr = explode(' ', $highlight);
             if ($arr) {
                 $highlight = "";
                 foreach ($arr as $word) {
                     $highlight = ($highlight ? $highlight . ', ' : '') . "'{$word}'";
                     $highlight1 = ($highlight1 ? $highlight1 . ',' : '') . $word;
                 }
             }
         }
         while ($item = mysql_fetch_assoc($search_result)) {
             $item['profile_url'] = WEB_DIR . $item['user_name'];
             //$item['name'] = EClassApi::subString(strip_tags(EClassApi::filter_title($item['name'])), 0, 115, true);
             $item['name_hl'] = EClassApi::HighLightKeyword(strip_tags(EClassApi::filter_title($item['name'])), $highlight1);
             $item_time = TIME_NOW - $item['up_time'];
             //neu nho hon 1h thi tinh ra phut
             if ($item_time < 3600) {
                 $item['item_time'] = floor($item_time / 60) . " phút trước đây";
             } elseif ($item_time < 86400) {
                 $item['item_time'] = floor($item_time / 3600) . " giờ trước đây";
             } else {
                 $item['item_time'] = date('\\n\\gà\\y j \\t\\há\\n\\g n', $item['up_time']);
             }
             //$item['description'] = String::display_sort_title(EClassApi::delDoubleSpace(EClassApi::trimSpace(strip_tags(EClassApi::post_db_parse_html($item['description'])))), 35);
             $item['description'] = EClassApi::HighLightKeyword(EClassApi::delDoubleSpace(EClassApi::trimSpace(strip_tags(EClassApi::post_db_parse_html(preg_replace('/\\[[0-9]{1,3}\\]/', '', $item['description']))))), $highlight1, 35, "background:yellow;font-size:14px;font-weight:bold;color:blue;");
             $ebname = EClassApi::safe_title($item['name']);
             $ebname_tmp = substr(EClassApi::safe_title($item['name']), 0, 20);
             if (isset(CGlobal::$allCategories[$item['category_id']])) {
                 $item['item_url'] = WEB_DIR . ECRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname . '&nice_name=' . CGlobal::$allCategories[$item['category_id']]['nice_name']);
                 $item['item_url_tmp'] = WEB_ROOT . CGlobal::$allCategories[$item['category_id']]['nice_name'] . '/p' . $item['id'] . '/' . $ebname_tmp . '...';
             } else {
                 $item['item_url'] = WEB_DIR . ECRewrite::formatUrl('?page=item_detail&id=' . $item['id'] . '&ebname=' . $ebname);
                 $item['item_url_tmp'] = WEB_ROOT . 'p' . $item['id'] . '/' . $ebname_tmp . '...';
             }
             if ($item['original_image_url']) {
                 $item['original_image_url'] = EClassApi::getImageThumb($item['original_image_url'], 110, 0, 1, $item['img_server']);
             }
             $item['price'] = number_format($item['price'], 0, ',', '.');
             $item_array[] = $item;
         }
     }
     $display->add('total_item_cat', $total);
     $display->add('name_item_cat', $catActive);
     $display->add('paging', $paging);
     $display->add('keywords', $keywords);
     $display->add('items', $item_array);
     $display->output('sphinx_search_ajax', false, 'sphinx_search');
 }
コード例 #16
0
 /**
  * ¬озвращает список публичных типовых услуг по заданным услови¤м и пагинацией
  * 
  * @return array
  */
 public function getList($excluded_ids = array())
 {
     $criteria = array($this->category_id, $this->city_id, $this->country_id, $this->keywords, $this->limit, $this->offset, $this->price_ranges, $this->price_max, $this->order, $excluded_ids, $this->user_id);
     $membuf = new memBuff();
     $memkey = __METHOD__ . '#' . md5(serialize($criteria));
     if (false !== ($result = $membuf->get($memkey)) && is_release()) {
         return $result;
     }
     $sort = $this->getSort();
     # @see http://sphinxsearch.com/forum/view.html?id=11538 about city = x or country = y
     $sphinxClient = new SphinxClient();
     $sphinxClient->SetServer(SEARCHHOST, SEARCHPORT);
     $sphinxClient->SetLimits($this->offset, $this->limit, 20000);
     $sphinxClient->SetSortMode(SPH_SORT_EXTENDED, $sort);
     $sphinxClient->SetFieldWeights(array('title' => 2, 'extra_title' => 1));
     //$sphinxClient->SetRankingMode(SPH_RANK_PROXIMITY_BM25);
     $selectExpression = '*';
     // все колонки
     if ($this->user_id) {
         $selectExpression .= ", IF(user_id = {$this->user_id}, 1, 0) as match_user";
         $sphinxClient->setFilter('match_user', array(1));
     }
     if ($this->category_id) {
         $selectExpression .= ", IF(category_id = {$this->category_id} or category_parent_id = {$this->category_id}, 1, 0) as match_category";
         $sphinxClient->setFilter('match_category', array(1));
     }
     if ($this->country_id) {
         $selectExpression .= ", IF(user_country_id = {$this->country_id} or country_id = {$this->country_id}, 1, 0) as match_country";
         $sphinxClient->setFilter('match_country', array(1));
     }
     if ($this->city_id) {
         $selectExpression .= ", IF(user_city_id = {$this->city_id} or city_id = {$this->city_id}, 1, 0) as match_city";
         $sphinxClient->setFilter('match_city', array(1));
     }
     if (count($this->price_ranges)) {
         $match_price_exprs = array();
         foreach ($this->getPriceRanges() as $i => $price_range) {
             if (!isset($this->price_ranges[$i])) {
                 continue;
             }
             $match_price_exprs[] = "price_{$i} = 1";
         }
         $match_price_exprs = implode(' or ', $match_price_exprs);
         $selectExpression .= ", IF({$match_price_exprs}, 1, 0) as match_price";
         $sphinxClient->setFilter('match_price', array(1));
     }
     if ($this->price_max > 0) {
         $selectExpression .= ", IF(price <= {$this->price_max}, 1, 0) as match_price_max";
         $sphinxClient->setFilter('match_price_max', array(1));
     }
     $searchString = '';
     if (!empty($this->keywords)) {
         $keywords = implode(' ', array_filter(preg_split('/\\s*,\\s*/', $this->keywords)));
         $searchString = trim($keywords);
         //$searchString = $this->GetSphinxKeyword($searchString);
         $sphinxClient->SetMatchMode(SPH_MATCH_ANY);
         //SPH_MATCH_EXTENDED2);
     }
     if (count($excluded_ids)) {
         $sphinxClient->setFilter('tservice_id', $excluded_ids, true);
     }
     $sphinxClient->SetSelect($selectExpression);
     $queryResult = $sphinxClient->query($searchString, "tservices;delta_tservices");
     //echo '<pre>error: ', $sphinxClient->GetLastError(), '</pre>';
     //echo '<pre>warn : ', $sphinxClient->GetLastWarning(), '</pre>';
     $list = array();
     $total = 0;
     if (isset($queryResult['matches'])) {
         foreach ($queryResult['matches'] as $id => $row) {
             $row['attrs']['id'] = $id;
             $list[] = $row['attrs'];
         }
         $total = $queryResult['total_found'] < $queryResult['total'] ? $queryResult['total_found'] : $queryResult['total'];
     }
     $result = array('list' => $list, 'total' => $total);
     if ($this->_ttl) {
         $membuf->set($memkey, $result, $this->_ttl);
     }
     return $result;
 }
コード例 #17
0
 /**
  * Set matches sorting mode.
  *
  * @param int $mode The sorting mode to be used.
  * @param string $sortby The expression or the fields used for sorting.
  */
 public function setSortMode($mode, $sortby = "")
 {
     $this->sphinx->SetSortMode($mode, $sortby);
 }
コード例 #18
0
ファイル: matcher2.php プロジェクト: nytonkla/stupidspider
 public function run($subject_id, $clean = true, $query_offset = 0, $from, $to)
 {
     $this->load->helper('sphinxapi');
     $this->load->helper('mood');
     // skip if matching_status is "matching"
     $matching_status = $this->custom_model->get_value('subject', 'matching_status', $subject_id);
     if ($matching_status == 'matching') {
         echo "subject is matching";
         return false;
     }
     // flag subject as matching.. do other bot runs this queue.
     //$this->db->update('subject',array('matching_status'=>'matching'),array('id'=>$subject_id));
     // clear all match record for this subject
     $config['hostname'] = "192.168.1.102";
     $config['username'] = "******";
     $config['password'] = "******";
     $config['database'] = "thothconnect";
     $config['dbdriver'] = "mysql";
     $config['dbprefix'] = "";
     $config['pconnect'] = FALSE;
     $config['db_debug'] = TRUE;
     $config['cache_on'] = FALSE;
     $config['cachedir'] = "";
     $config['char_set'] = "utf8";
     $config['dbcollat'] = "utf8_general_ci";
     $thothconnect_db = $this->load->database($config, true);
     $query = $this->db->query("SELECT client_id FROM subject WHERE id = " . $subject_id);
     $row = $query->row();
     $client_id = $row->client_id;
     if ($clean) {
         $thothconnect_db->delete('website_c' . $client_id, array('subject_id' => $subject_id));
         $thothconnect_db->delete('twitter_c' . $client_id, array('subject_id' => $subject_id));
         $thothconnect_db->delete('facebook_c' . $client_id, array('subject_id' => $subject_id));
     }
     //
     // begin re-matching this subject
     //
     // get search string from subject_id
     $query = $this->custom_model->get_value('subject', 'query', $subject_id);
     // sphinx init
     $cl = new SphinxClient();
     $q = $query;
     $sql = "";
     $mode = SPH_MATCH_EXTENDED;
     $host = "192.168.1.102";
     $port = 9312;
     $index = "*";
     $groupby = "";
     $groupsort = "@group desc";
     $filter = "group_id";
     $filtervals = array();
     $distinct = "";
     $sortby = "@id ASC";
     $sortexpr = "";
     $offset = $query_offset;
     $limit = 1000000;
     $ranker = SPH_RANK_PROXIMITY_BM25;
     $select = "";
     echo 'limit=' . $limit . ' offset=' . $offset . PHP_EOL;
     //Extract subject keyword from search string
     $keywords = get_keywords($q);
     ////////////
     // do query
     ////////////
     $cl->SetServer($host, $port);
     $cl->SetConnectTimeout(1);
     $cl->SetArrayResult(true);
     $cl->SetWeights(array(100, 1));
     $cl->SetMatchMode($mode);
     // if ( count($filtervals) )	$cl->SetFilter ( $filter, $filtervals );
     // if ( $groupby )				$cl->SetGroupBy ( $groupby, SPH_GROUPBY_ATTR, $groupsort );
     if ($sortby) {
         $cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);
     }
     // if ( $sortexpr )			$cl->SetSortMode ( SPH_SORT_EXPR, $sortexpr );
     if ($distinct) {
         $cl->SetGroupDistinct($distinct);
     }
     if ($select) {
         $cl->SetSelect($select);
     }
     if ($limit) {
         $cl->SetLimits(0, $limit, $limit > 1000000 ? $limit : 1000000);
     }
     $cl->SetRankingMode($ranker);
     $res = $cl->Query($q, $index);
     //$res = true;
     ////////////
     // do Insert to DB
     ////////////
     // Current matching
     $current_matching = array();
     /*$query_matchs = $this->db->get_where('matchs',array('subject_id'=>$subject_id));
     		if($query_matchs->num_rows() > 0)
     		{
     			echo PHP_EOL.'currents matching :'.$query_matchs->num_rows();
     			foreach($query_matchs->result() as $match)
     			{
     				$current_matching[] = $match->post_id;
     			}
     		}*/
     // set matching date range from-to
     $from = strtotime($from);
     $to = strtotime($to);
     // Search and Update
     if ($res === false) {
         echo "Query failed: " . $cl->GetLastError() . ".\n";
     } else {
         if ($cl->GetLastWarning()) {
             echo "WARNING: " . $cl->GetLastWarning() . "\n\n";
         }
         echo "Query '{$q}' \nretrieved {$res['total']} of {$res['total_found']} matches in {$res['time']} sec.\n";
         if ($res['total'] == 0) {
             echo "no result<br/>\n";
         } else {
             if ($res['total'] > $limit + $offset) {
                 $this->run($subject_id, $limit + $offset);
             } else {
                 echo "Updating...";
                 foreach ($res["matches"] as $k => $docinfo) {
                     //					echo '('.$k.')'.$docinfo["id"]." ";
                     // Reset PHP Timeout to 1min
                     // if found in $current_matching then skip
                     if (in_array($docinfo["id"], $current_matching)) {
                         continue;
                     } else {
                         // else insert new match
                         set_time_limit(60);
                         $post = new Post_model();
                         $post->init($docinfo["id"]);
                         // if post_date is our of range then skip
                         $post_date = strtotime($post->post_date);
                         if ($post_date < $from || $post_date > $to) {
                             continue;
                         }
                         $mood = get_mood($post->body, $keywords);
                         //-----------------------------------------------------
                         $subject = $post->get_subject($subject_id);
                         //print_r($subject);
                         if ($post->type == "post" || $post->type == "comment") {
                             $postData = $post->get_post_website($post->id);
                             if ($postData != null) {
                                 $data = array();
                                 $data["post_id"] = $postData->post_id;
                                 $data["post_date"] = $postData->post_date;
                                 $data["title"] = $postData->title;
                                 $data["body"] = $postData->body;
                                 $data["type"] = $postData->type;
                                 $data["author_id"] = $postData->author_id;
                                 $data["author"] = $postData->author;
                                 $data["website_id"] = $postData->website_id;
                                 $data["website_name"] = $postData->website_name;
                                 $data["website_cate_id"] = $postData->website_cate_id;
                                 $data["website_cate"] = $postData->website_cate;
                                 $data["website_type_id"] = $postData->website_type_id;
                                 $data["website_type"] = $postData->website_type;
                                 $data["group_id"] = $subject->group_id;
                                 $data["group"] = $subject->group;
                                 $data["url"] = substr($postData->root_url, 0, -1) . "" . $postData->url;
                                 $data["page_id"] = $postData->page_id;
                                 $data["subject_id"] = $subject->subject_id;
                                 $data["subject_name"] = $subject->subject_name;
                                 $data["mood"] = $mood;
                                 $data["mood_by"] = 'system';
                                 $thothconnect_db->insert("website_c" . $subject->client_id, $data);
                                 $post->insert_post_comment($postData->page_id, $subject->client_id, $thothconnect_db);
                             }
                         } else {
                             if ($post->type == "tweet" || $post->type == "retweet") {
                                 $postData = $post->get_post_twitter($post->id);
                                 if ($postData != null) {
                                     $data = array();
                                     $data["post_id"] = $postData->post_id;
                                     $data["post_date"] = $postData->post_date;
                                     $data["body"] = $postData->body;
                                     $data["type"] = $postData->type;
                                     $data["author_id"] = $postData->author_id;
                                     $data["author"] = $postData->author;
                                     $data["group_id"] = $subject->group_id;
                                     $data["group"] = $subject->group;
                                     $data["tweet_id"] = $postData->tweet_id;
                                     $data["subject_id"] = $subject->subject_id;
                                     $data["subject_name"] = $subject->subject_name;
                                     $data["mood"] = $mood;
                                     $data["mood_by"] = 'system';
                                     $thothconnect_db->insert("twitter_c" . $subject->client_id, $data);
                                 }
                             } else {
                                 if ($post->type == "fb_post" || $post->type == "fb_comment") {
                                     $postData = $post->get_post_facebook($post->id);
                                     if ($postData != null) {
                                         $data = array();
                                         $data["post_id"] = $postData->post_id;
                                         $data["post_date"] = $postData->post_date;
                                         $data["body"] = $postData->body;
                                         $data["type"] = $postData->type;
                                         $data["author_id"] = $postData->author_id;
                                         $data["author"] = $postData->author;
                                         $data["group_id"] = $subject->group_id;
                                         $data["group"] = $subject->group;
                                         $data["facebook_page_id"] = $postData->facebook_page_id;
                                         $data["facebook_page_name"] = $postData->facebook_page_name;
                                         $data["subject_id"] = $subject->subject_id;
                                         $data["subject_name"] = $subject->subject_name;
                                         $data["facebook_id"] = $postData->facebook_id;
                                         $data["parent_post_id"] = $postData->parent_post_id;
                                         $data["likes"] = $postData->likes;
                                         $data["shares"] = $postData->shares;
                                         $data["mood"] = $mood;
                                         $data["mood_by"] = 'system';
                                         $thothconnect_db->insert("facebook_c" . $subject->client_id, $data);
                                     }
                                 }
                             }
                         }
                         /*
                         $data = array(
                         	'post_id'=> $post->id, 
                         	'subject_id' => $subject_id , 
                         	'matching_date' => null,
                         	'sentiment' => $mood,
                         	'by' => 'system',
                         	'system_correct' => $mood,
                         	'system_correct_date' => mdate('%Y-%m-%d %H:%i',time())
                         );						
                         $this->db->insert('matchs',$data);	
                         */
                         //---------------------------------------
                     }
                 }
             }
         }
     }
     // flag subject as update..
     $data = array('matching_status' => 'update', 'latest_matching' => mdate('%Y-%m-%d %H:%i:%s', time()), 'from' => mdate('%Y-%m-%d %H:%i:%s', $from), 'to' => mdate('%Y-%m-%d %H:%i:%s', $to));
     $this->db->update('subject', $data, array('id' => $subject_id));
 }
コード例 #19
0
 /**
  * Edit settings related to the sphinx or sphinxQL search function.
  *
  * - Called by ?action=admin;area=managesearch;sa=sphinx.
  * - Checks if connection to search daemon is possible
  */
 public function action_managesphinx()
 {
     global $txt, $context, $modSettings;
     // Saving the settings
     if (isset($_POST['save'])) {
         checkSession();
         validateToken('admin-mssphinx');
         updateSettings(array('sphinx_data_path' => rtrim($_POST['sphinx_data_path'], '/'), 'sphinx_log_path' => rtrim($_POST['sphinx_log_path'], '/'), 'sphinx_stopword_path' => $_POST['sphinx_stopword_path'], 'sphinx_indexer_mem' => (int) $_POST['sphinx_indexer_mem'], 'sphinx_searchd_server' => $_POST['sphinx_searchd_server'], 'sphinx_searchd_port' => (int) $_POST['sphinx_searchd_port'], 'sphinxql_searchd_port' => (int) $_POST['sphinxql_searchd_port'], 'sphinx_max_results' => (int) $_POST['sphinx_max_results']));
     } elseif (isset($_POST['checkconnect'])) {
         checkSession();
         validateToken('admin-mssphinx');
         // If they have not picked sphinx yet, let them know, but we can still check connections
         if (empty($modSettings['search_index']) || $modSettings['search_index'] !== 'sphinx' && $modSettings['search_index'] !== 'sphinxql') {
             $context['settings_message'][] = $txt['sphinx_test_not_selected'];
             $context['error_type'] = 'notice';
         }
         // Try to connect via Sphinx API?
         if (!empty($modSettings['search_index']) && ($modSettings['search_index'] === 'sphinx' || empty($modSettings['search_index']))) {
             if (@file_exists(SOURCEDIR . '/sphinxapi.php')) {
                 include_once SOURCEDIR . '/sphinxapi.php';
                 $mySphinx = new SphinxClient();
                 $mySphinx->SetServer($modSettings['sphinx_searchd_server'], (int) $modSettings['sphinx_searchd_port']);
                 $mySphinx->SetLimits(0, (int) $modSettings['sphinx_max_results']);
                 $mySphinx->SetMatchMode(SPH_MATCH_BOOLEAN);
                 $mySphinx->SetSortMode(SPH_SORT_ATTR_ASC, 'id_topic');
                 $request = $mySphinx->Query('test', 'elkarte_index');
                 if ($request === false) {
                     $context['settings_message'][] = $txt['sphinx_test_connect_failed'];
                     $context['error_type'] = 'serious';
                 } else {
                     $context['settings_message'][] = $txt['sphinx_test_passed'];
                 }
             } else {
                 $context['settings_message'][] = $txt['sphinx_test_api_missing'];
                 $context['error_type'] = 'serious';
             }
         }
         // Try to connect via SphinxQL
         if (!empty($modSettings['search_index']) && ($modSettings['search_index'] === 'sphinxql' || empty($modSettings['search_index']))) {
             if (!empty($modSettings['sphinx_searchd_server']) && !empty($modSettings['sphinxql_searchd_port'])) {
                 $result = @mysqli_connect($modSettings['sphinx_searchd_server'] === 'localhost' ? '127.0.0.1' : $modSettings['sphinx_searchd_server'], '', '', '', (int) $modSettings['sphinxql_searchd_port']);
                 if ($result === false) {
                     $context['settings_message'][] = $txt['sphinxql_test_connect_failed'];
                     $context['error_type'] = 'serious';
                 } else {
                     $context['settings_message'][] = $txt['sphinxql_test_passed'];
                 }
             } else {
                 $context['settings_message'][] = $txt['sphinxql_test_connect_failed'];
                 $context['error_type'] = 'serious';
             }
         }
     } elseif (isset($_POST['createconfig'])) {
         checkSession();
         validateToken('admin-mssphinx');
         require_once SUBSDIR . '/ManageSearch.subs.php';
         createSphinxConfig();
     }
     // Setup for the template
     $context['page_title'] = $txt['search_sphinx'];
     $context['page_description'] = $txt['sphinx_description'];
     $context['sub_template'] = 'manage_sphinx';
     createToken('admin-mssphinx');
 }
コード例 #20
0
 /**
  * 内容搜索
  */
 public function searchAction()
 {
     $kw = $this->get('kw');
     $kw = urldecode($kw);
     $sql = null;
     $page = (int) $this->get('page') > 0 ? (int) $this->get('page') : 1;
     $param = $this->getParam();
     if ($this->site['SITE_SEARCH_TYPE'] == 2) {
         //Sphinx
         if (empty($kw)) {
             $this->msg(lang('con-5'));
         }
         App::auto_load('sphinxapi');
         $cl = new SphinxClient();
         $host = $this->site['SITE_SEARCH_SPHINX_HOST'];
         $prot = $this->site['SITE_SEARCH_SPHINX_PORT'];
         $name = $this->site['SITE_SEARCH_SPHINX_NAME'];
         $start = ($page - 1) * (int) $this->site['SITE_SEARCH_PAGE'];
         $limit = (int) $this->site['SITE_SEARCH_PAGE'];
         $cl->SetServer($host, 9312);
         $cl->SetMatchMode(SPH_MATCH_ALL);
         $cl->SetSortMode(SPH_SORT_EXTENDED, 'updatetime DESC');
         $cl->SetLimits($start, $limit);
         $res = $cl->Query($kw, $this->site['SITE_SEARCH_SPHINX_NAME']);
         if ($res['total']) {
             $ids = '';
             foreach ($res['matches'] as $cid => $val) {
                 $ids .= $cid . ',';
             }
             $ids = substr($ids, -1) == ',' ? substr($ids, 0, -1) : $ids;
             $total = $res['total'];
             $pageurl = $this->site['SITE_SEARCH_URLRULE'] ? str_replace('{id}', urlencode($kw), $this->site['SITE_SEARCH_URLRULE']) : url('content/search', array('kw' => urlencode($kw), 'page' => '{page}'));
             $sql = 'SELECT id,modelid,catid,url,thumb,title,keywords,description,username,updatetime,inputtime from ' . $this->content->prefix . 'content_' . $this->siteid . ' WHERE id IN (' . $ids . ') ORDER BY updatetime DESC LIMIT ' . $limit;
         }
     } else {
         //普通搜索
         $search = $this->model('search');
         $start = ($page - 1) * (int) $this->site['SITE_SEARCH_PAGE'];
         $limit = $this->site['SITE_SEARCH_PAGE'] ? (int) $this->site['SITE_SEARCH_PAGE'] : 10;
         $cache = (int) $this->site['SITE_SEARCH_INDEX_CACHE'];
         $result = $search->getData((int) $this->get('id'), $cache, $param, $start, $limit, $this->site['SITE_SEARCH_KW_FIELDS'], $this->site['SITE_SEARCH_KW_OR']);
         $kw = $result['keywords'];
         $sql = $result['sql'];
         $total = $result['total'];
         $catid = $result['catid'];
         $modelid = $result['modelid'];
         $pageurl = $this->site['SITE_SEARCH_URLRULE'] ? str_replace('{id}', $result['id'], $this->site['SITE_SEARCH_URLRULE']) : url('content/search', array('id' => $result['id'], 'page' => '{page}'));
     }
     if ($sql) {
         $pagelist = $this->instance('pagelist');
         $pagelist->loadconfig();
         $data = $this->content->execute($sql, true, $this->site['SITE_SEARCH_DATA_CACHE']);
         $pagelist = $pagelist->total($total)->url($pageurl)->num($this->site['SITE_SEARCH_PAGE'])->page($page)->output();
     } else {
         $data = array();
         $total = 0;
         $pagelist = '';
     }
     $this->view->assign(listSeo($cat, $page, $kw));
     $this->view->assign(array('id' => $id, 'kw' => $kw, 'model' => $this->get_model(), 'catid' => $catid, 'modelid' => $modelid, 'searchpage' => $pagelist, 'searchdata' => $data, 'searchnums' => $total));
     $this->view->display('search');
 }
コード例 #21
0
// simple
$file = fopen("spec/fixtures/data/simple.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
// index
$file = fopen("spec/fixtures/data/index.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ", "edition")]);
fclose($file);
// any
$client->SetMatchMode(SPH_MATCH_ANY);
$file = fopen("spec/fixtures/data/any.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test this ")]);
fclose($file);
$client->SetMatchMode(SPH_MATCH_ALL);
// sort
$client->SetSortMode(SPH_SORT_EXTENDED, "id");
$file = fopen("spec/fixtures/data/sort.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("testing ")]);
fclose($file);
$client->SetSortMode(SPH_SORT_RELEVANCE, "");
// boolean
$client->SetMatchMode(SPH_MATCH_BOOLEAN);
$file = fopen("spec/fixtures/data/boolean.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("test ")]);
fclose($file);
$client->SetMatchMode(SPH_MATCH_ALL);
// phrase
$client->SetMatchMode(SPH_MATCH_PHRASE);
$file = fopen("spec/fixtures/data/phrase.bin", "w");
fwrite($file, $client->_reqs[$client->AddQuery("testing this ")]);
fclose($file);
コード例 #22
0
    }
}
//搜索时间
if (!empty($srchfrom)) {
    $srchfrom = (int) $srchfrom;
    $sp_time_now = time();
    $ps_time_select = $sp_time_now - $srchfrom;
    //$before默认是false	所选时间到现在		$before=1时,表示这段时间之外
    $cl->setfilterrange('dateline', $ps_time_select, $sp_time_now, $before);
}
//排序类型
$sp_order = isset($ascdesc) && $ascdesc == 'asc' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC;
$sp_orderby = array('lastpost', 'dateline', 'replies', 'views');
//'rank',
if (in_array($orderby, $sp_orderby)) {
    $cl->SetSortMode($sp_order, $orderby);
} else {
    $cl->SetSortMode(SPH_SORT_EXPR, '@weight');
}
//搜索论坛板块范围
if (!empty($srchfid) && $srchfid != 'all') {
    foreach ($srchfid as $forum) {
        if ($forum = intval(trim($forum))) {
            $sp_fids[] = $forum;
        }
    }
    !empty($sp_fids) && $cl->setfilter('fid', $sp_fids);
}
//分页
$sp_page = isset($page) ? abs((int) $page) : 1;
$sp_page = max(1, $sp_page);
コード例 #23
0
ファイル: Search.php プロジェクト: rankinp/OpenCATS
 public function __construct($rowsPerPage, $currentPage, $siteID, $wildCardString, $sortBy, $sortDirection)
 {
     $this->_db = DatabaseConnection::getInstance();
     $this->_siteID = $siteID;
     $this->_sortByFields = array('firstName', 'lastName', 'city', 'state', 'dateModifiedSort', 'dateCreatedSort', 'ownerSort');
     if (ENABLE_SPHINX) {
         /* Sphinx API likes to throw PHP errors *AND* use it's own error
          * handling.
          */
         assert_options(ASSERT_WARNING, 0);
         $sphinx = new SphinxClient();
         $sphinx->SetServer(SPHINX_HOST, SPHINX_PORT);
         $sphinx->SetWeights(array(0, 100, 0, 0, 50));
         $sphinx->SetMatchMode(SPH_MATCH_EXTENDED);
         $sphinx->SetLimits(0, 1000);
         $sphinx->SetSortMode(SPH_SORT_TIME_SEGMENTS, 'date_added');
         // FIXME: This can be sped up a bit by actually grouping ranges of
         //        site IDs into their own index's. Maybe every 500 or so at
         //        least on the Hosted system.
         $sphinx->SetFilter('site_id', array($this->_siteID));
         /* Create the Sphinx query string. */
         $wildCardString = DatabaseSearch::humanToSphinxBoolean($wildCardString);
         /* Execute the Sphinx query. Sphinx can ask us to retry if its
          * maxed out. Retry up to 5 times.
          */
         $tries = 0;
         do {
             /* Wait for one second if this isn't out first attempt. */
             if (++$tries > 1) {
                 sleep(1);
             }
             $results = $sphinx->Query($wildCardString, SPHINX_INDEX);
             $errorMessage = $sphinx->GetLastError();
         } while ($results === false && strpos($errorMessage, 'server maxed out, retry') !== false && $tries <= 5);
         /* Throw a fatal error if Sphinx errors occurred. */
         if ($results === false) {
             $this->fatal('Sphinx Error: ' . ucfirst($errorMessage) . '.');
         }
         /* Throw a fatal error (for now) if Sphinx warnings occurred. */
         $lastWarning = $sphinx->GetLastWarning();
         if (!empty($lastWarning)) {
             // FIXME: Just display a warning, and notify dev team.
             $this->fatal('Sphinx Warning: ' . ucfirst($lastWarning) . '.');
         }
         /* Show warnings for assert()s again. */
         assert_options(ASSERT_WARNING, 1);
         if (empty($results['matches'])) {
             $this->_WHERE = '0';
         } else {
             $attachmentIDs = implode(',', array_keys($results['matches']));
             $this->_WHERE = 'attachment.attachment_id IN(' . $attachmentIDs . ')';
         }
     } else {
         $this->_WHERE = DatabaseSearch::makeBooleanSQLWhere(DatabaseSearch::fulltextEncode($wildCardString), $this->_db, 'attachment.text');
     }
     /* How many companies do we have? */
     $sql = sprintf("SELECT\n                COUNT(*) AS count\n            FROM\n                attachment\n            LEFT JOIN candidate\n                ON attachment.data_item_id = candidate.candidate_id\n                AND attachment.data_item_type = %s\n                AND attachment.site_id = candidate.site_id\n            LEFT JOIN user AS owner_user\n                ON candidate.owner = owner_user.user_id\n            WHERE\n                resume = 1\n            AND\n                %s\n            AND\n                (ISNULL(candidate.is_admin_hidden) OR (candidate.is_admin_hidden = 0))\n            AND\n                (ISNULL(candidate.is_active) OR (candidate.is_active = 1))\n            AND\n                attachment.site_id = %s", DATA_ITEM_CANDIDATE, $this->_WHERE, $this->_siteID);
     $rs = $this->_db->getAssoc($sql);
     /* Pass "Search By Resume"-specific parameters to Pager constructor. */
     parent::__construct($rs['count'], $rowsPerPage, $currentPage);
 }
コード例 #24
0
ファイル: locum-client.php プロジェクト: aadl/locum
 /**
  * Does an index search via Sphinx and returns the results
  *
  * @param string $type Search type.  Valid types are: author, title, series, subject, keyword (default)
  * @param string $term Search term/phrase
  * @param int $limit Number of results to return
  * @param int $offset Where to begin result set -- for pagination purposes
  * @param array $sort_array Numerically keyed array of sort parameters.  Valid options are: newest, oldest
  * @param array $location_array Numerically keyed array of location params.  NOT IMPLEMENTED YET
  * @param array $facet_args String-keyed array of facet parameters. See code below for array structure
  * @return array String-keyed result set
  */
 public function search($type, $term, $limit, $offset, $sort_opt = NULL, $format_array = array(), $location_array = array(), $facet_args = array(), $override_search_filter = FALSE, $limit_available = FALSE, $show_inactive = FALSE)
 {
     if (is_callable(array(__CLASS__ . '_hook', __FUNCTION__))) {
         eval('$hook = new ' . __CLASS__ . '_hook;');
         return $hook->{__FUNCTION__}($type, $term, $limit, $offset, $sort_opt, $format_array, $location_array, $facet_args, $override_search_filter, $limit_available);
     }
     require_once $this->locum_config['sphinx_config']['api_path'] . '/sphinxapi.php';
     $db =& MDB2::connect($this->dsn);
     $term_arr = explode('?', trim(preg_replace('/\\//', ' ', $term)));
     $term = trim($term_arr[0]);
     if ($term == '*' || $term == '**') {
         $term = '';
     } else {
         $term_prestrip = $term;
         //$term = preg_replace('/[^A-Za-z0-9*\- ]/iD', '', $term);
         $term = preg_replace('/\\*\\*/', '*', $term);
         //fix for how iii used to do wildcards
     }
     $final_result_set['term'] = $term;
     $final_result_set['type'] = trim($type);
     $cl = new SphinxClient();
     $cl->SetServer($this->locum_config['sphinx_config']['server_addr'], (int) $this->locum_config['sphinx_config']['server_port']);
     // Defaults to 'keyword', non-boolean
     $bool = FALSE;
     $cl->SetMatchMode(SPH_MATCH_ALL);
     if (!$term) {
         // Searches for everything (usually for browsing purposes--Hot/New Items, etc..)
         $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
     } else {
         $picturebook = array('picturebook', 'picture book');
         $picbk_search = '(@callnum ^E)';
         $term = str_ireplace($picturebook, $picbk_search, $term);
         if ($type == 'keyword') {
             // Custom fiction and non-fiction search
             $nonfic_search = ' (@callnum "0*" | @callnum "1*" | @callnum "2*" | @callnum "3*" | @callnum "4*" | @callnum "5*" | @callnum "6*" | @callnum "7*" | @callnum "8*" | @callnum "9*")';
             $fiction_search = ' (@title fiction | @subjects fiction | @callnum mystery | @callnum fantasy | @callnum fiction | @callnum western | @callnum romance)';
             if (stripos($term, 'nonfiction') !== FALSE) {
                 $term = '@@relaxed ' . str_ireplace('nonfiction', '', $term) . $nonfic_search;
             } else {
                 if (strpos($term, 'non-fiction') !== FALSE) {
                     $term = '@@relaxed ' . str_ireplace('non-fiction', '', $term) . $nonfic_search;
                 } else {
                     if (strpos($term, 'fiction') !== FALSE) {
                         $term = '@@relaxed ' . str_ireplace('fiction', '', $term) . $fiction_search;
                     }
                 }
             }
         }
         // Is it a boolean search?
         if (preg_match("/ \\| /i", $term) || preg_match("/ \\-/i", $term) || preg_match("/ \\!/i", $term)) {
             $cl->SetMatchMode(SPH_MATCH_BOOLEAN);
             $bool = TRUE;
         }
         if (preg_match("/ OR /i", $term)) {
             $cl->SetMatchMode(SPH_MATCH_BOOLEAN);
             $term = preg_replace('/ OR /i', ' | ', $term);
             $bool = TRUE;
         }
         // Is it a phrase search?
         if (preg_match("/\"/i", $term) || preg_match("/\\@/i", $term)) {
             $cl->SetMatchMode(SPH_MATCH_EXTENDED2);
             $bool = TRUE;
         }
     }
     // Set up for the various search types
     switch ($type) {
         case 'author':
             $cl->SetFieldWeights(array('author' => 50, 'addl_author' => 30));
             $idx = 'bib_items_author';
             break;
         case 'title':
             $cl->SetFieldWeights(array('title' => 50, 'title_medium' => 50, 'series' => 30));
             $idx = 'bib_items_title';
             break;
         case 'series':
             $cl->SetFieldWeights(array('title' => 5, 'series' => 80));
             $idx = 'bib_items_title';
             break;
         case 'subject':
             $idx = 'bib_items_subject';
             break;
         case 'callnum':
             $cl->SetFieldWeights(array('callnum' => 100));
             $idx = 'bib_items_callnum';
             //$cl->SetMatchMode(SPH_MATCH_ANY);
             break;
         case 'tags':
             $cl->SetFieldWeights(array('tag_idx' => 100));
             $idx = 'bib_items_tags';
             //$cl->SetMatchMode(SPH_MATCH_PHRASE);
             break;
         case 'reviews':
             $cl->SetFieldWeights(array('review_idx' => 100));
             $idx = 'bib_items_reviews';
             break;
         case 'keyword':
         default:
             $cl->SetFieldWeights(array('title' => 400, 'title_medium' => 30, 'author' => 70, 'addl_author' => 40, 'tag_idx' => 25, 'series' => 25, 'review_idx' => 10, 'notes' => 10, 'subjects' => 5));
             $idx = 'bib_items_keyword';
             break;
     }
     // Filter out the records we don't want shown, per locum.ini
     if (!$override_search_filter) {
         if (trim($this->locum_config['location_limits']['no_search'])) {
             $cfg_filter_arr = $this->csv_parser($this->locum_config['location_limits']['no_search']);
             foreach ($cfg_filter_arr as $cfg_filter) {
                 $cfg_filter_vals[] = $this->string_poly($cfg_filter);
             }
             $cl->SetFilter('loc_code', $cfg_filter_vals, TRUE);
         }
     }
     // Valid sort types are 'newest' and 'oldest'.  Default is relevance.
     switch ($sort_opt) {
         case 'newest':
             $cl->SetSortMode(SPH_SORT_EXTENDED, 'pub_year DESC, @relevance DESC');
             break;
         case 'oldest':
             $cl->SetSortMode(SPH_SORT_EXTENDED, 'pub_year ASC, @relevance DESC');
             break;
         case 'catalog_newest':
             $cl->SetSortMode(SPH_SORT_EXTENDED, 'bib_created DESC, @relevance DESC');
             break;
         case 'catalog_oldest':
             $cl->SetSortMode(SPH_SORT_EXTENDED, 'bib_created ASC, @relevance DESC');
             break;
         case 'title':
             $cl->SetSortMode(SPH_SORT_ATTR_ASC, 'title_ord');
             break;
         case 'author':
             $cl->SetSortMode(SPH_SORT_EXTENDED, 'author_null ASC, author_ord ASC');
             break;
         case 'top_rated':
             $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'rating_idx');
             break;
         case 'popular_week':
             $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'hold_count_week');
             break;
         case 'popular_month':
             $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'hold_count_month');
             break;
         case 'popular_year':
             $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'hold_count_year');
             break;
         case 'popular_total':
             $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'hold_count_total');
             break;
         case 'atoz':
             $cl->SetSortMode(SPH_SORT_ATTR_ASC, 'title_ord');
             break;
         case 'ztoa':
             $cl->SetSortMode(SPH_SORT_ATTR_DESC, 'title_ord');
             break;
         default:
             $cl->SetSortMode(SPH_SORT_EXPR, "@weight + (hold_count_total)*0.02");
             break;
     }
     // Filter by material types
     if (is_array($format_array)) {
         foreach ($format_array as $format) {
             if (strtolower($format) != 'all') {
                 $filter_arr_mat[] = $this->string_poly(trim($format));
             }
         }
         if (count($filter_arr_mat)) {
             $cl->SetFilter('mat_code', $filter_arr_mat);
         }
     }
     // Filter by location
     if (count($location_array)) {
         foreach ($location_array as $location) {
             if (strtolower($location) != 'all') {
                 $filter_arr_loc[] = $this->string_poly(trim($location));
             }
         }
         if (count($filter_arr_loc)) {
             $cl->SetFilter('loc_code', $filter_arr_loc);
         }
     }
     // Filter by pub_year
     if ($facet_args['facet_year']) {
         if (strpos($facet_args['facet_year'][0], '-') !== FALSE) {
             $min_year = 1;
             $max_year = 9999;
             $args = explode('-', $facet_args['facet_year'][0]);
             $min_arg = (int) $args[0];
             $max_arg = (int) $args[1];
             if ($min_arg && $min_arg > $min_year) {
                 $min_year = $min_arg;
             }
             if ($max_arg && $max_arg < $max_year) {
                 $max_year = $max_arg;
             }
             $cl->setFilterRange('pub_year', $min_year, $max_year);
         } else {
             $cl->SetFilter('pub_year', $facet_args['facet_year']);
         }
     }
     // Filter by pub_decade
     if ($facet_args['facet_decade']) {
         $cl->SetFilter('pub_decade', $facet_args['facet_decade']);
     }
     // Filter by lexile
     if ($facet_args['facet_lexile']) {
         $cl->SetFilter('lexile', $facet_args['facet_lexile']);
     }
     // Filter by Series
     if (count($facet_args['facet_series'])) {
         foreach ($facet_args['facet_series'] as &$facet_series) {
             $facet_series = $this->string_poly($facet_series);
         }
         $cl->SetFilter('series_attr', $facet_args['facet_series']);
     }
     // Filter by Language
     if (count($facet_args['facet_lang'])) {
         foreach ($facet_args['facet_lang'] as &$facet_lang) {
             $facet_lang = $this->string_poly($facet_lang);
         }
         $cl->SetFilter('lang', $facet_args['facet_lang']);
     }
     // Filter inactive records
     if (!$show_inactive) {
         $cl->SetFilter('active', array('0'), TRUE);
     }
     // Filter by age
     if (count($facet_args['age'])) {
         foreach ($facet_args['age'] as $age_facet) {
             $cl->SetFilter('ages', array($this->string_poly($age_facet)));
         }
     }
     // Filter by availability
     if ($limit_available) {
         $cl->SetFilter('branches', array($this->string_poly($limit_available)));
     }
     $cl->SetRankingMode(SPH_RANK_SPH04);
     $proximity_check = $cl->Query($term, $idx);
     // Quick check on number of results
     // If original match didn't return any results, try a proximity search
     if (empty($proximity_check['matches']) && $bool == FALSE && $term != "*" && $type != "tags") {
         $term = '"' . $term . '"/1';
         $cl->SetMatchMode(SPH_MATCH_EXTENDED);
         $forcedchange = 'yes';
     }
     // Paging/browsing through the result set.
     $sort_limit = 2000;
     if ($offset + $limit > $sort_limit) {
         $sort_limit = $offset + $limit;
     }
     $cl->SetLimits((int) $offset, (int) $limit, (int) $sort_limit);
     // And finally.... we search.
     $cl->AddQuery($term, $idx);
     // CREATE FACETS
     $cl->SetLimits(0, 1000);
     // Up to 1000 facets
     $cl->SetArrayResult(TRUE);
     // Allow duplicate documents in result, for facet grouping
     $cl->SetGroupBy('pub_year', SPH_GROUPBY_ATTR);
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('pub_decade', SPH_GROUPBY_ATTR);
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('mat_code', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('branches', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('ages', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('lang', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('series_attr', SPH_GROUPBY_ATTR, '@count desc');
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $cl->SetGroupBy('lexile', SPH_GROUPBY_ATTR);
     $cl->AddQuery($term, $idx);
     $cl->ResetGroupBy();
     $results = $cl->RunQueries();
     // Include descriptors
     $final_result_set['num_hits'] = $results[0]['total_found'];
     if ($results[0]['total'] <= $this->locum_config['api_config']['suggestion_threshold'] || $forcedchange == 'yes') {
         if ($this->locum_config['api_config']['use_yahoo_suggest'] == TRUE) {
             $final_result_set['suggestion'] = $this->yahoo_suggest($term_prestrip);
         }
     }
     // Pull full records out of Couch
     if ($final_result_set['num_hits']) {
         $skip_avail = $this->csv_parser($this->locum_config['format_special']['skip_avail']);
         $bib_hits = array();
         foreach ($results[0]['matches'] as $match) {
             $bib_hits[] = (string) $match['id'];
         }
         $final_result_set['results'] = $this->get_bib_items_arr($bib_hits);
         foreach ($final_result_set['results'] as &$result) {
             $result = $result['value'];
             if ($result['bnum']) {
                 // Get availability (Only cached)
                 $result['status'] = $this->get_item_status($result['bnum'], FALSE, TRUE);
             }
         }
     }
     $final_result_set['facets'] = $this->sphinx_facetizer($results);
     if ($forcedchange == 'yes') {
         $final_result_set['changed'] = 'yes';
     }
     return $final_result_set;
 }
コード例 #25
0
function do_query($search_str)
{
    //$tmp_var = array(array('itemName' => "test1"), array('itemName' => "test2"), array('itemName' => "test3"));
    //echo implode(",",tmp_var);
    //echo json_encode($tmp_var);
    //return tmp_var;
    $q = "";
    $sql = "";
    $mode = SPH_MATCH_ALL;
    $host = "localhost";
    $port = 9312;
    $index = "*";
    $groupby = "";
    $groupsort = "@group desc";
    $filter = "group_id";
    $filtervals = array();
    $distinct = "";
    $sortby = "";
    $sortexpr = "";
    $limit = 20;
    $ranker = SPH_RANK_PROXIMITY_BM25;
    $select = "*";
    $cl = new SphinxClient();
    $cl->SetServer($host, $port);
    $cl->SetConnectTimeout(1);
    $cl->SetArrayResult(true);
    $cl->SetWeights(array(100, 1));
    $cl->SetMatchMode($mode);
    if (count($filtervals)) {
        $cl->SetFilter($filter, $filtervals);
    }
    if ($groupby) {
        $cl->SetGroupBy($groupby, SPH_GROUPBY_ATTR, $groupsort);
    }
    if ($sortby) {
        $cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);
    }
    if ($sortexpr) {
        $cl->SetSortMode(SPH_SORT_EXPR, $sortexpr);
    }
    if ($distinct) {
        $cl->SetGroupDistinct($distinct);
    }
    if ($select) {
        $cl->SetSelect($select);
    }
    if ($limit) {
        $cl->SetLimits(0, $limit, $limit > 1000 ? $limit : 1000);
    }
    $cl->SetRankingMode($ranker);
    $res = $cl->Query($search_str, $index);
    //return $res;
    if (is_array($res["matches"])) {
        $results = array();
        $n = 1;
        //print "Matches:\n";
        foreach ($res["matches"] as $docinfo) {
            //print "$n. doc_id=$docinfo[id], weight=$docinfo[weight]";
            $attr_array = array();
            $results[$docinfo[id]];
            foreach ($res["attrs"] as $attrname => $attrtype) {
                $value = $docinfo["attrs"][$attrname];
                if ($attrtype == SPH_ATTR_MULTI || $attrtype == SPH_ATTR_MULTI64) {
                    $value = "(" . join(",", $value) . ")";
                } else {
                    if ($attrtype == SPH_ATTR_TIMESTAMP) {
                        $value = date("Y-m-d H:i:s", $value);
                    }
                }
                $attr_array[$attrname] = $value;
                //print $value;
            }
            $results[$docinfo[id]] = $attr_array;
            $n++;
            //print implode("",$results)."\n";
        }
        return $results;
    }
}
コード例 #26
0
ファイル: user.php プロジェクト: snamper/cms
         $keyToSearch = md5($getKey);
         break;
     case 'Normal':
         $keyToSearch = $getKey;
         break;
     default:
         ShowError('ಥ_ಥ,出错啦!!!', 'javascript:closeWindow()', '关闭');
 }
 $sp = new SphinxClient();
 $sp->SetServer('10.211.55.14', 9312);
 //设置spinx的服务器地址和端口
 $sp->SetArrayResult(true);
 //设置 显示结果集方式
 $sp->SetLimits(0, 1000);
 //同sql语句中的LIMIT
 $sp->SetSortMode(SPH_SORT_RELEVANCE);
 //设置默认按照相关性排序
 $sp->SetMatchMode($mod);
 if ($keyToSearch != " ") {
     // 如果关键字为空 不执行 否则程序出错
     $result = $sp->Query($keyToSearch, "*");
 }
 //执行搜索
 $count = $result['total'];
 //计算一共多少页
 //            $pn=(ceil($count / 10));
 if (is_array($result['matches'])) {
     $sql_id = array();
     foreach ($result['matches'] as $k => $v) {
         $sql_id[$i] = $v["id"];
         $i++;
コード例 #27
0
ファイル: list.php プロジェクト: koala87/backup
    $language = $r2["id"];
    //set language
    if ($language == "") {
        echo json_encode(array("result" => null, "status" => false, "error" => "请求的语种不存在"));
        exit;
    }
    $sphinx->SetFilter('language', array($language));
}
if (isset($_REQUEST['words'])) {
    if (intval($_REQUEST['words']) < 9) {
        $sphinx->SetFilter('words', array(intval($_REQUEST['words'])));
    } else {
        $sphinx->SetFilterRange('words', 9, 100);
    }
}
$sphinx->SetSortMode(SPH_SORT_EXTENDED, "lang_part ASC, words ASC, header_sort ASC, count DESC");
//索引源是配置文件中的 index 类,如果有多个索引源可使用,号隔开:'email,diary' 或者使用'*'号代表全部索引源
$result = $sphinx->query($key_word, 'media');
// echo '<pre>';
// print_r($result);
// echo '</pre>';
if (!isset($result['matches'])) {
    include_once '_list.php';
    exit;
    // $finalResult = array(
    // "songs" => array(),
    // "page" => 0,
    // "total" => 0,
    // "totalNumber" => 0
    // );
    // formatResult($finalResult);
コード例 #28
0
ファイル: test.php プロジェクト: jzawodn/Sphinx-at-Craigslist
////////////
// do query
////////////
$cl->SetServer($host, $port);
$cl->SetConnectTimeout(1);
$cl->SetArrayResult(true);
$cl->SetWeights(array(100, 1));
$cl->SetMatchMode($mode);
if (count($filtervals)) {
    $cl->SetFilter($filter, $filtervals);
}
if ($groupby) {
    $cl->SetGroupBy($groupby, SPH_GROUPBY_ATTR, $groupsort);
}
if ($sortby) {
    $cl->SetSortMode(SPH_SORT_EXTENDED, $sortby);
}
if ($sortexpr) {
    $cl->SetSortMode(SPH_SORT_EXPR, $sortexpr);
}
if ($distinct) {
    $cl->SetGroupDistinct($distinct);
}
if ($select) {
    $cl->SetSelect($select);
}
if ($limit) {
    $cl->SetLimits(0, $limit, $limit > 1000 ? $limit : 1000);
}
$cl->SetRankingMode($ranker);
$res = $cl->Query($q, $index);
コード例 #29
0
ファイル: sphinxtest.php プロジェクト: PublicityPort/OpenCATS
if (!file_exists($SphinxAPI)) {
    fwrite($stderr, "Config Error: SPHINX_API could not be found.\n");
    exit(1);
}
include $SphinxAPI;
/* Sphinx API likes to throw PHP errors *AND* use it's own error
 * handling.
 */
assert_options(ASSERT_WARNING, 0);
/* Execute the Sphinx query. */
$sphinx = new SphinxClient();
$sphinx->SetServer(SPHINX_HOST, SPHINX_PORT);
$sphinx->SetWeights(array(0, 100, 0, 0, 50));
$sphinx->SetMatchMode(SPH_MATCH_BOOLEAN);
$sphinx->SetLimits(0, 10);
$sphinx->SetSortMode(SPH_SORT_TIME_SEGMENTS, 'date_added');
$sphinx->SetFilter('site_id', TEST_SITE_ID);
/* Execute the Sphinx query. Sphinx can ask us to retry if its
 * maxed out. Retry up to 5 times.
 */
$tries = 0;
do {
    /* Wait for one second if this isn't out first attempt. */
    if (++$tries > 1) {
        sleep(1);
    }
    $results = $sphinx->Query(TEST_QUERY, SPHINX_INDEX);
    $errorMessage = $sphinx->GetLastError();
} while ($results === false && strpos($errorMessage, 'server maxed out, retry') !== false && $tries <= 5);
/* Throw a fatal error if Sphinx errors occurred. */
if ($results === false) {
コード例 #30
0
ファイル: fulltext_sphinx.php プロジェクト: Voxel37/phpbb
 /**
  * Performs a search on keywords depending on display specific params. You have to run split_keywords() first
  *
  * @param	string		$type				contains either posts or topics depending on what should be searched for
  * @param	string		$fields				contains either titleonly (topic titles should be searched), msgonly (only message bodies should be searched), firstpost (only subject and body of the first post should be searched) or all (all post bodies and subjects should be searched)
  * @param	string		$terms				is either 'all' (use query as entered, words without prefix should default to "have to be in field") or 'any' (ignore search query parts and just return all posts that contain any of the specified words)
  * @param	array		$sort_by_sql		contains SQL code for the ORDER BY part of a query
  * @param	string		$sort_key			is the key of $sort_by_sql for the selected sorting
  * @param	string		$sort_dir			is either a or d representing ASC and DESC
  * @param	string		$sort_days			specifies the maximum amount of days a post may be old
  * @param	array		$ex_fid_ary			specifies an array of forum ids which should not be searched
  * @param	string		$post_visibility	specifies which types of posts the user can view in which forums
  * @param	int			$topic_id			is set to 0 or a topic id, if it is not 0 then only posts in this topic should be searched
  * @param	array		$author_ary			an array of author ids if the author should be ignored during the search the array is empty
  * @param	string		$author_name		specifies the author match, when ANONYMOUS is also a search-match
  * @param	array		&$id_ary			passed by reference, to be filled with ids for the page specified by $start and $per_page, should be ordered
  * @param	int			$start				indicates the first index of the page
  * @param	int			$per_page			number of ids each page is supposed to contain
  * @return	boolean|int						total number of results
  */
 public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key, $sort_dir, $sort_days, $ex_fid_ary, $post_visibility, $topic_id, $author_ary, $author_name, &$id_ary, &$start, $per_page)
 {
     // No keywords? No posts.
     if (!strlen($this->search_query) && !sizeof($author_ary)) {
         return false;
     }
     $id_ary = array();
     $join_topic = $type != 'posts';
     // Sorting
     if ($type == 'topics') {
         switch ($sort_key) {
             case 'a':
                 $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'poster_id ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
                 break;
             case 'f':
                 $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'forum_id ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
                 break;
             case 'i':
             case 's':
                 $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'post_subject ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
                 break;
             case 't':
             default:
                 $this->sphinx->SetGroupBy('topic_id', SPH_GROUPBY_ATTR, 'topic_last_post_time ' . ($sort_dir == 'a' ? 'ASC' : 'DESC'));
                 break;
         }
     } else {
         switch ($sort_key) {
             case 'a':
                 $this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'poster_id');
                 break;
             case 'f':
                 $this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'forum_id');
                 break;
             case 'i':
             case 's':
                 $this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_subject');
                 break;
             case 't':
             default:
                 $this->sphinx->SetSortMode($sort_dir == 'a' ? SPH_SORT_ATTR_ASC : SPH_SORT_ATTR_DESC, 'post_time');
                 break;
         }
     }
     // Most narrow filters first
     if ($topic_id) {
         $this->sphinx->SetFilter('topic_id', array($topic_id));
     }
     $search_query_prefix = '';
     switch ($fields) {
         case 'titleonly':
             // Only search the title
             if ($terms == 'all') {
                 $search_query_prefix = '@title ';
             }
             // Weight for the title
             $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
             // 1 is first_post, 0 is not first post
             $this->sphinx->SetFilter('topic_first_post', array(1));
             break;
         case 'msgonly':
             // Only search the body
             if ($terms == 'all') {
                 $search_query_prefix = '@data ';
             }
             // Weight for the body
             $this->sphinx->SetFieldWeights(array("title" => 1, "data" => 5));
             break;
         case 'firstpost':
             // More relative weight for the title, also search the body
             $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
             // 1 is first_post, 0 is not first post
             $this->sphinx->SetFilter('topic_first_post', array(1));
             break;
         default:
             // More relative weight for the title, also search the body
             $this->sphinx->SetFieldWeights(array("title" => 5, "data" => 1));
             break;
     }
     if (sizeof($author_ary)) {
         $this->sphinx->SetFilter('poster_id', $author_ary);
     }
     // As this is not simply possible at the moment, we limit the result to approved posts.
     // This will make it impossible for moderators to search unapproved and softdeleted posts,
     // but at least it will also cause the same for normal users.
     $this->sphinx->SetFilter('post_visibility', array(ITEM_APPROVED));
     if (sizeof($ex_fid_ary)) {
         // All forums that a user is allowed to access
         $fid_ary = array_unique(array_intersect(array_keys($this->auth->acl_getf('f_read', true)), array_keys($this->auth->acl_getf('f_search', true))));
         // All forums that the user wants to and can search in
         $search_forums = array_diff($fid_ary, $ex_fid_ary);
         if (sizeof($search_forums)) {
             $this->sphinx->SetFilter('forum_id', $search_forums);
         }
     }
     $this->sphinx->SetFilter('deleted', array(0));
     $this->sphinx->SetLimits($start, (int) $per_page, SPHINX_MAX_MATCHES);
     $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
     // Could be connection to localhost:9312 failed (errno=111,
     // msg=Connection refused) during rotate, retry if so
     $retries = SPHINX_CONNECT_RETRIES;
     while (!$result && strpos($this->sphinx->GetLastError(), "errno=111,") !== false && $retries--) {
         usleep(SPHINX_CONNECT_WAIT_TIME);
         $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
     }
     if ($this->sphinx->GetLastError()) {
         add_log('critical', 'LOG_SPHINX_ERROR', $this->sphinx->GetLastError());
         if ($this->auth->acl_get('a_')) {
             trigger_error($this->user->lang('SPHINX_SEARCH_FAILED', $this->sphinx->GetLastError()));
         } else {
             trigger_error($this->user->lang('SPHINX_SEARCH_FAILED_LOG'));
         }
     }
     $result_count = $result['total_found'];
     if ($result_count && $start >= $result_count) {
         $start = floor(($result_count - 1) / $per_page) * $per_page;
         $this->sphinx->SetLimits((int) $start, (int) $per_page, SPHINX_MAX_MATCHES);
         $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
         // Could be connection to localhost:9312 failed (errno=111,
         // msg=Connection refused) during rotate, retry if so
         $retries = SPHINX_CONNECT_RETRIES;
         while (!$result && strpos($this->sphinx->GetLastError(), "errno=111,") !== false && $retries--) {
             usleep(SPHINX_CONNECT_WAIT_TIME);
             $result = $this->sphinx->Query($search_query_prefix . str_replace('&quot;', '"', $this->search_query), $this->indexes);
         }
     }
     $id_ary = array();
     if (isset($result['matches'])) {
         if ($type == 'posts') {
             $id_ary = array_keys($result['matches']);
         } else {
             foreach ($result['matches'] as $key => $value) {
                 $id_ary[] = $value['attrs']['topic_id'];
             }
         }
     } else {
         return false;
     }
     $id_ary = array_slice($id_ary, 0, (int) $per_page);
     return $result_count;
 }