Sphinx并不总是返回字符串属性
在某些情况下,Sphinx返回的结果中没有我声明为sql\u attr\u string的联接字段。以以下源/索引配置为例:Sphinx并不总是返回字符串属性,sphinx,Sphinx,在某些情况下,Sphinx返回的结果中没有我声明为sql\u attr\u string的联接字段。以以下源/索引配置为例: source myapp_recipe { type = pgsql sql_host = sql_user = me sql_pass = secret sql_db = myapp_db sql_p
source myapp_recipe
{
type = pgsql
sql_host =
sql_user = me
sql_pass = secret
sql_db = myapp_db
sql_port =
sql_query = \
SELECT myapp_recipe.id as id, \
myapp_recipe.name as name, \
myapp_recipe.cookbook_id as cookbook_id, \
myapp_cookbook.name as cookbook_name, \
'recipe' as content_type \
FROM myapp_recipe \
INNER JOIN myapp_cookbook \
ON myapp_recipe.cookbook_id = myapp_cookbook.id
#content_type for django
sql_attr_string = content_type
# stored string fields in the document
sql_attr_string = cookbook_name
# stored and indexed string fields
sql_field_string = name
# ForeignKey's
sql_attr_uint = cookbook_id
}
index myapp_recipe
{
source = myapp_recipe
path = /var/data/myapp_recipe
docinfo = extern
morphology = none
stopwords =
min_word_len = 2
charset_type = utf-8
min_prefix_len = 0
min_infix_len = 3
enable_star = 0
}
对于某些搜索,结果文档返回时除了content\u type
和name
之外没有其他属性。对于返回相同文档的不同搜索,Sphinx很可能返回具有所有预期属性的相同结果文档
例如:
对“pizza”的查询将返回一个不完整的结果文档(documentA),其中没有连接字符串属性
查询“pizza pocket”将返回具有所有预期联接属性的同一文档(documentA)
有人能解释这种令人困惑的行为吗?检查您是否没有重复的id
您的sql_查询必须返回具有唯一id的结果,否则Sphinx可以为相同id的多个文档(对于Sphinx,id被视为一个简单的数字,不应用任何唯一性规则)。编制索引时,应发出一条警告,指出存在重复项。我没有看到此配置的任何索引警告。我正在使用如下调用搜索多个索引:client.Query(“pizza”,“myapp\u表1 myapp\u表2 myapp\u表3”)。这可能与这个问题有关吗?我暗自怀疑这就是问题所在,既然你把我放在这条路上——当我有多个索引的匹配项时,问题似乎就出现了。如何避免这个问题?因为“文档id”是postgres中对象的“id”,所以我不确定在查询多个索引时如何避免重复id。解决方案是在需要搜索的每个索引上使用AddQuery()。单行查询(“myquery”、“index1 index2 index3”)要求index1、index2和index3中的每个文档都有唯一的id。因为我的索引代表Django模型表,所以它们将具有重复的id。感谢aditirex。因此,对于其他人的未来参考,传递到查询中的表之间的重复id(“myquery”、“table1 table2 table3”)将以神秘的方式破坏您的搜索结果。:)