当我的狮身人面像指数在一个模型中被分成多个文件时,搜索有时不会产生任何结果。
我使用的版本:
我在这个模型上有五个指数:
ThinkingSphinx::Index.define :incident, name: "incident_index_1" ... do
indexes name
end
ThinkingSphinx::Index.define :incident, name: "incident_index_5" ... do
indexes tags.name, as: :tag
indexes custom_fields_values.value, as: :custom
end
单独搜索,查询返回正确的结果:
Incident.search(conditions: { custom: "dd" })
Incident.search("some string")
但是,将特定于字段的查询与通用查询相结合有时不会返回任何内容:
Incident.search("some string", conditions: { custom: "dd" })
如果"某些字符串"它位于tag
字段(在同一索引文件中定义),它可以工作。如果它在name
字段(在不同的索引文件中定义),则它不起作用。
答案 0 :(得分:1)
As clarified via discussions on the Sphinx forums,这里的问题是字段在不同的索引中,并且Sphinx文档(索引中的记录,在Thinking Sphinx / Rails上下文中是ActiveRecord模型实例)应该只存在于一个 Sphinx索引,不会跨越几个。
修改强>
要在SO中完成答案并使问题独立,索引现在看起来像这样:
- (BOOL) webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
{
NSURL *url = [request URL];
if (![url isFileURL] && navigationType == UIWebViewNavigationTypeLinkClicked)
{
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
return NO;
}
}
return [super webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType];
}
因此,文档在五个sphinx索引文件之间平均分配,而不会在多个索引文件中存在文档。