[英]Not showing results for single character search
我试图在控制台上查看使用sphinx / php的单字符搜索结果。 但是它没有显示结果。 理想情况下,应使所有结果均以该特定字符开头
标签表
mysql>从标签中选择*;
+ -------- + --------- + -------------------- +
| tag_id | 关键字| 属于表名|
+ -------- + --------- + -------------------- +
| 1 | 鹿| 种类|
| 2 | 狩猎 活动|
+ -------- + --------- + -------------------- +
设置2行(0.00秒)
php文件
<?php
include_once 'sphinxapi.php';
// Build search query
$cl = new SphinxClient();
$cl->SetServer('127.0.0.1', 9312);
$cl->SetMatchMode(SPH_MATCH_EXTENDED);
$cl->SetRankingMode (SPH_RANK_SPH04);
// Execute the query
$query = 'hun';
$partialQueryStr = " @keyword $query";
$cl->AddQuery($partialQueryStr, 'customsearch');
$result = $cl->RunQueries();
print_r($result);
if ( $result === false ) {
echo "Query failed: " . $cl->GetLastError() . ".\n";
}
else {
if ( $cl->GetLastWarning() ) {
echo "WARNING: " . $cl->GetLastWarning() . "<br>";
}
if ($result['matches'] > 0) {
print_r($result['matches']);
} else {
echo 'No results found';
}
}
exit;
?>
Sphinx.conf
source customsearch {
type = mysql
sql_host = localhost
sql_user = root
sql_pass = hello123
sql_db = testsphinx
sql_port = 3306
sql_query = \
SELECT \
UUID_SHORT() AS sphinxid, \
tg.keyword AS keyword, \
tg.belongstotablename AS ref \
FROM tags AS tg;
sql_attr_uint = sphinxid
sql_field_string = keyword
sql_field_string = ref
}
index customsearch {
source = customsearch
path = /etc/sphinx/data/customsearch
docinfo = extern
dict = keywords
morphology = stem_en
#morphology = soundex
min_stemming_len = 1
min_prefix_len = 1
}
searchd {
listen = 9312
listen = 9306:mysql41
log = /home/xxx/www/log/searchd.log
query_log = /home/xxx/sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = /home/xxx/sphinx/log/searchd.pid
preopen_indexes = 1
unlink_old = 1
}
indexer
{
mem_limit = 136M
}
控制台结果
vikas@vikas-pc:~$ php /www/fwv2/php/search/practicesearch.php
Array
(
[0] => Array
(
[error] =>
[warning] =>
[status] => 0
[fields] => Array
(
[0] => keyword
[1] => ref
)
[attrs] => Array
(
[keyword] => 7
[ref] => 7
)
[total] => 0
[total_found] => 0
[time] => 0.000
[words] => Array
(
[hun] => Array
(
[docs] => 0
[hits] => 0
)
)
)
)
PHP Notice: Undefined index: matches in /home/xxx//practicesearch.php on line 24
No results found
根据我的理解,应该为“ hun”查询带来1条记录。
你确实有min_prefix_len
,它启用“部分单词匹配”或至少“单词开始匹配”-默认情况下,狮身人面像仅匹配整个单词。
因此,要进行实际匹配,需要使用*
通配符,例如
$query = 'hun*';
然后,您应该获得匹配。
...或查看expand_keywords
选项,该选项一旦在索引上启用,实际上会透明/自动添加*。
...但也要注意,设置min_prefix_len=1
可能不适用于dict=keywords
其更改为min_prefix_len=2
。
参见: http : //sphinxsearch.com/forum/view.html?id=14123
...该线程有一些解决方法(包括使用dict=crc
或以某种方式计算掩码)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.