我有一个MySql数据库,其中包含一个名为'table'的表。比如说。
该表有两个字段:ID(自动增量主键)和字段(varchar)。
网站通过搜索栏访问数据库,搜索栏向php发送ajax调用,然后查询sphinx:
// Sphinx Query
$sphinx = new SphinxClient();
$sphinx_index = 'index_field';
$mode = SPH_MATCH_BOOLEAN;
$sphinx->SetServer("127.0.0.1", 122381);
$sphinx->setLimits(0,1000); // max search results sphinx can return
$sphinx->setMaxQueryTime(5000); // 5 seconds || 5000 milliseconds
$sphinx->setMatchMode($mode);
$sphinx->setFieldWeights(array('name' => 100));
$sphinx->setArrayResult(true);
$res = $sphinx->query($searchString,$sphinx_index);
测试时,我发现查询$searchString = 'target';
会返回614结果。
当我转到MySql命令行并输入:select count(*) from table where field='target';
时,它返回624个结果...
这根本不好。
这是Sphinx的来源:
source src_field
{
# data source type. mandatory, no default value
# known types are 'mysql', 'pgsql', 'xmlpipe', 'xmlpipe2'
type = mysql
#####################################################################
## SQL settings (for 'mysql' and 'pgsql' types)
#####################################################################
# some straightforward parameters for SQL source types
sql_host = localhost
sql_user = root
sql_pass = NotForYouToKnow
sql_db = myDatabase
sql_port = 3306 # optional, default is 3306
sql_query = \
SELECT a.ID AS ID, a.field AS field FROM table AS a;
sql_ranged_throttle = 0
sql_query_info = SELECT a.ID AS ID, a.field AS field FROM table AS a WHERE a.ID=$ID;
}
这是斯芬克斯指数:
index index_field
{
# document source(s) to index
# multi-value, mandatory
# document IDs must be globally unique across all sources
source = src_field
path = C:\sphinx\data\index_field
docinfo = extern
mlock = 0
morphology = none
min_word_len = 1
charset_type = sbcs
html_strip = 0
min_infix_len = 2
enable_star = 1
}
我不知道为什么它会返回几乎适量的数据而不是全部数据......
Sphinx吐出的数组长度:count($res) == 614
。
有什么想法吗?