Sphinx returns 个空结果

Sphinx returns empty results

我有一个使用 Sphinx 搜索引擎的项目。

问题是直接搜索(当用户输入查询并按下回车键时)效果很好,但是当我尝试实现自动完成时 returns 零结果。

Sphinx版本为2.0.8(由于某些原因无法更新)

我使用此代码进行自动竞争(取自here

<?php
$ln_sph = new PDO("mysql:host=127.0.0.1;port={$confs['port2']}",
            '',
            '',
            array
            (
                PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"  
            )
        );

$stmt = $ln_sph->prepare("SELECT * FROM ".implode(",", $used_indexes)." WHERE MATCH(':match') LIMIT 0,10 OPTION ranker=sph04");

$aq = explode(' ', $query);
if(mb_strlen($aq[count($aq) - 1]) < 3)
{
    $query = $query;
}
else
{
    $query = $query.'*';
}

$stmt->bindValue(':match', $query, PDO::PARAM_STR);         
$stmt->execute();
$products_ids = array();
foreach($stmt->fetchAll() as $data)
{
    //Reading data from sphinx              
}

如果我通过 mysql

直接从服务器连接到 Sphinx
mysql -P10006 --protocol=tcp

并执行相同的查询,例如:

SELECT * FROM `app_catalog_prod_suggests` WHERE MATCH('пирс*') LIMIT 0, 10 OPTION ranker=sph04;

它也很好用。

来自 sphinx.conf

的索引
index app_catalog_prod_suggests {
    source=app_catalog_prod_suggests
    path=/path/to/index
    enable_star=1
    min_word_len=3
    min_prefix_len=3
    morphology=stem_ru,stem_en,soundex
    charset_type=utf-8
    html_strip=1
}

我做错了什么?

P.S。如果需要,我可以提供额外的数据

更新。搜索部分

searchd {
        listen=127.0.0.1:10005
        listen=127.0.0.1:10006:mysql41
        log=/path/to/log
        query_log=/path/to/querylog
        binlog_path = #
        pid_file=/path/to/pid
}

经过一些尝试,我找到了这种行为的原因。它不在 Sphinx 中,而是在 PDO 中。

首先,我测试了查询是否有效,例如使用某个常量值 - пирс*。令我非常惊讶的是,Sphinx 返回的正是我所需要的。

因此,问题不在 Sphinx 中。但那又在哪里呢?只有一行可能导致它 - $stmt->bindValue(':match', $query, PDO::PARAM_STR);.

我已将 bindValue 替换为 bindParam,它开始处理任何查询。

我不知道这种行为的真正原因,如果有人能解释一下就好了

UPD

经过一些额外的测试,错误不在 bindParambindValue 中,而是在参数名称中

我以为你必须使用那个代码

$indexes = 'simplecomplete';
$query = trim($_GET['term']);

$stmt = $ln_sph->prepare("SELECT * FROM $indexes WHERE MATCH(:match)  LIMIT $start,$offset OPTION ranker=sph04,field_weights=(title=100,content=1)");
$stmt->bindValue(':match', $query,PDO::PARAM_STR);
    $stmt->execute();
$rows = $stmt->fetchAll();
   $meta = $ln_sph->query("SHOW META")->fetchAll();
foreach($meta as $m) {
    $meta_map[$m['Variable_name']] = $m['Value'];
}

数据库连接

define ( "FREQ_THRESHOLD", 40 );
define ( "SUGGEST_DEBUG", 0);
define ( "LENGTH_THRESHOLD", 2 );
define ( "LEVENSHTEIN_THRESHOLD", 2 );
define ( "TOP_COUNT", 1 );
define ("SPHINX_20",false);
//database PDO
$ln = new PDO( 'mysql:host=127.0.0.1;dbname=test_database;charset=utf8', 'root', '' );

//Sphinx PDO
$ln_sph = new PDO( 'mysql:host=127.0.0.1;port=9306' );