Sphinx搜索结果给出了0场匹配

时间:2012-09-11 06:04:02

标签: sphinx java-api

我有720个狮身人面像指数,大小为1.21 GB。这里附加了一个服务的所有索引。它需要800MB的RAM。我已经使用sql_attr_str2ordinal来存储字符串,因此RAM减少了,现在只需要17MB。但这里的问题是搜索结果给出0匹配。使用来自sphinx索引的java api应用搜索。 Conf文件和java代码如下:

searchd{    
 listen         = 516   
 log                =    D:\programs\spinx\spinxexperiment\project\log\searchd.log
query_log       = D:\programs\spinx\spinxexperiment\project\log\query.log
read_timeout    = 5
max_children    = 30
pid_file        = D:\programs\spinx\spinxexperiment\project\log\searchd.pid
max_matches     = 1000
seamless_rotate = 0
preopen_indexes = 0
unlink_old      = 1
ondisk_dict_default = 1
mva_updates_pool   = 1M
workers         = threads # for RT to work}

source webusagedatagroup20120301{
type            = pgsql
    sql_host        = 127.0.0.1
    sql_user        = postgres
sql_pass        = 
sql_db          = iviewdb
sql_port        = 5432
sql_query       = SELECT id,username as username_ord,domain as  domain_ord,application,hits,bytes from webusagedata1        
sql_attr_str2ordinal    = username_ord
sql_attr_str2ordinal    = domain_ord
sql_attr_str2ordinal    = application
sql_attr_bigint     = hits
sql_attr_bigint     = bytes}

  index webusagedatagroup20120301{
source  = webusagedatagroup20120301
path    = D:\programs\spinx\spinxexperiment\project\data\20120301\group\webusagedatagroup20120301
preopen         = 0
docinfo         = inline
ondisk_dict     = 1
charset_type        = sbcs
rt_field        = username
rt_field        = domain
rt_field        = application
rt_attr_bigint      = hits
rt_attr_bigint      = bytes}

client = new SphinxClient("127.0.0.1",516);         
client.SetMatchMode(SphinxClient.SPH_MATCH_PHRASE);
query=prepareQuery();
client.SetLimits(0, 20);            
client.SetMaxQueryTime(0);
client.SetConnectTimeout(60000);
client.SetSelect("*, SUM(bytes) as bytes_total");           
client.SetGroupBy("application", SphinxClient.SPH_GROUPBY_ATTR,"username asc");
SphinxResult res = client.Query("divyesh.modi", "webusagedatagroup20120130");

1 个答案:

答案 0 :(得分:0)

正如狮身人面像论坛所讨论的那样。索引需要一个字段才能工作。您的索引没有字段,因此无效。

由于您似乎希望能够通过用户名进行搜索,因此需要将用户名设置为字段和ordinaal属性(这样您就可以进行分组而无需使用字符串属性)

您需要在sql_query中记录两次列,一次为字段,一次为属性。