gpt4 book ai didi

php - sphinx 搜索 : Partial keyword

转载 作者:行者123 更新时间:2023-11-29 13:20:04 30 4
gpt4 key购买 nike

我已经开始使用Sphinx并尝试安装sphinx。一切正常,但我想搜索部分关键字。我想知道如何在网页中显示结果。
例如
我搜索“
结果应该是:“ate”、“update”、“late”、“hate”等.
我的 sphinx.con :

source src1
{
type = mysql
sql_host = localhost
sql_user = username
sql_pass = *******
sql_db = db_name
sql_port = 3306 # optional, default is 3306

sql_query = \
SELECT id, msgtext, created \
FROM agi_sms

sql_attr_string = msgtext
sql_attr_timestamp = created

sql_query_info = SELECT * FROM agi_sms WHERE id=$id

}

   index test1
{
source = src1
path = C:/Sphinx/data/test1
docinfo = extern
charset_type = sbcs
enable_star = 1
morphology = stem_en
min_infix_len = 2
infix_fields = msgtext
dict = keywords

}



indexer
{
mem_limit = 32M
}


searchd
{
listen = 9312
listen = 9306:mysql41
log = C:/Sphinx/log/searchd.log
query_log = C:/Sphinx/log/query.log
read_timeout = 5
max_children = 30
pid_file = C:/Sphinx/log/searchd.pid
max_matches = 1000
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
binlog_path = C:/Sphinx/data
}

这是我的 php 文件:

$cl = new SphinxClient ();
$q = $_POST['search'];
$sql = "";
$mode = SPH_MATCH_EXTENDED2;
$host = "localhost";
$port = 9312;
$index = "*";
$groupby = "";
$filter = "created";
$filtervals = array();
$distinct = "";
$sortby = "";

$sortexpr = "";
$limit = 20;
$ranker = SPH_RANK_PROXIMITY_BM25;
$select = "";

////////////
// do query
////////////

$cl = new SphinxClient();
$cl->SetServer( "localhost", 9312 );
$cl->SetMatchMode( SPH_MATCH_ANY );
$cl->SetFilter( 'created', array( 3 ) );

$res = $cl->Query ( $q, $index );
////////////////
// print me out
////////////////

if ( $res===false )
{
print "Query failed: " . $cl->GetLastError() . ".\n";

} else
{
if ( $cl->GetLastWarning() )
print "WARNING: " . $cl->GetLastWarning() . "\n\n";

print "<li>Query '$q' retrieved $res[total] of $res[total_found] matches in $res[time] sec.\n</li>";
print "<li>Query stats:\n";
if ( is_array($res["words"]) )
foreach ( $res["words"] as $word => $info )
print " '$word' found $info[hits] times in $info[docs] documents\n</li>";
print "\n";


}

结果:

Query 'good' retrieved 0 of 0 matches in 0.007 sec.
Query stats: 'good' found 7534 times in 7534 documents

但是如果我尝试搜索“goo”,它什么也没搜索到。

Query 'goo' retrieved 0 of 0 matches in 0.000 sec.
Query stats: 'goo' found 0 times in 0 documents

我想得到所有包含单词/字母“goo”的结果。

像这样:

Array(1 element) {
0 Object {
id = 1,
message = Good Morning
}
2 Object {
id = 2,
message = Good Day!
}
}

最佳答案

$cl->SetFilter( 'created', array( 3 ) ); are you sure you have records with created=3? Also for wildcard searching you should do 'goo*' ( mark the * ) or set expand_keywords = 1.

关于php - sphinx 搜索 : Partial keyword,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20966281/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com