我不想对一组类进行全局搜索,但我想指定它应该使用的索引数组,这可能吗?我用谷歌搜索并尝试了不同的解决方案,但还没有成功。
这可以正常工作(尽管对于一个索引)。
ThinkingSphinx.search "query", :classes => [Foo, Bar], :index => "my_foo_index"
这会引发错误:
ThinkingSphinx.search "query", :classes => [Foo, Bar], :index => "my_foo_index,my_bar_index"
> ThinkingSphinx::SphinxError: distributed index 'my_foo_index' in multi-index query found
这样做:
ThinkingSphinx.search "query", :classes => [Foo, Bar], :index => ["my_foo_index", "my_bar_index"]
> NoMethodError: undefined method `force_encoding' for ["my_foo_index", "my_bar_index"]:Array
我还尝试将模型索引命名为相同的名称,例如 Foo-model 和 Bar-model 上的“my_index”,但在重建索引时出现此错误:
ERROR: section 'my_index_core_0' (type='source') already exists in /dev/config/development.sphinx.conf line 116 col 1.
我能想到的唯一解决方案是对每个模型进行多次搜索,然后合并结果。不过这有点打击,因为我将在搜索中失去相关性......
有什么想法吗?
最佳答案
尝试以下操作:
ThinkingSphinx.search 'query', :classes => [Foo, Bar],
:index => 'my_foo_index_core,my_bar_index_core'
如果您有增量,请将 my_foo_index_delta
和 my_bar_index_delta
添加到列表中。这将避免分布式索引。
关于ruby-on-rails - 使用 Thinking Sphinx 进行多索引全局搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10331066/