Search 如何使用Thinking sphinx执行sphinx多查询

Search 如何使用Thinking sphinx执行sphinx多查询,search,sphinx,thinking-sphinx,Search,Sphinx,Thinking Sphinx,我的主要目的是一次执行多个Sphinx查询。 它们可以在不同的模型/表上,也可以在一些通用的模型/表上。 最终结果应按查询分组 Sphinx中的多查询似乎支持这一点: 在Rails应用程序中使用ThinkingSphinx,我有没有办法使用此功能 (仅供参考,我的TS版本是2.0.11,但是我想知道如果不是2.x版本,是否可以通过3.x版本实现)在思考Sphinx v1/v2时,它不是特别优雅,但这里有个交易: bundle = ThinkingSphinx::BundledSearch.new

我的主要目的是一次执行多个Sphinx查询。 它们可以在不同的模型/表上,也可以在一些通用的模型/表上。 最终结果应按查询分组

Sphinx中的多查询似乎支持这一点:

在Rails应用程序中使用ThinkingSphinx,我有没有办法使用此功能


(仅供参考,我的TS版本是2.0.11,但是我想知道如果不是2.x版本,是否可以通过3.x版本实现)

在思考Sphinx v1/v2时,它不是特别优雅,但这里有个交易:

bundle = ThinkingSphinx::BundledSearch.new
bundle.search 'foo'
bundle.search 'bar', :classes => [Article]
bundle.search 'baz', :classes => [User, Article], :with => {:active => true}

# as soon as you call `searches` on the bundle, the group of queries is sent
# through to Sphinx.
foo_search, bar_search, baz_search = bundle.searches
对于斯芬克斯v3,它有点不同:

batch      = ThinkingSphinx::BatchedSearch.new
foo_search = ThinkingSphinx.search 'foo'
bar_search = Article.search 'bar'
baz_search = ThinkingSphinx.search 'baz', :classes => [User, Article],
  :with => {:active => true}
batch.searches += [foo_search, bar_search, baz_search]
batch.populate
# Use each of your search results objects now as you normally would.
# If you use any of them to access results before the batch.populate call,
# then that will be a separate call to Sphinx.
除此之外,如果您目前仍坚持使用v2版本,我强烈建议您升级到Thinking Sphinx v2.1.0,因为这仍然是旧语法,但使用连接池,因此即使您没有将所有这些查询批处理在一起,套接字设置开销也会尽可能减少