当在单个模型上使用多个索引文件时,思维sphinx搜索不返回任何内容

时间:2015-05-17 14:21:07

标签: ruby-on-rails sphinx thinking-sphinx

当我的狮身人面像指数在一个模型中被分成多个文件时,搜索有时不会产生任何结果。

我使用的版本:

  • Rails - 4.1
  • 思考狮身人面像 - 3.0.6
  • Sphinx - 2.0.9

我在这个模型上有五个指数:

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字段(在不同的索引文件中定义),则它不起作用。

1 个答案:

答案 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索引文件之间平均分配,而不会在多个索引文件中存在文档。