在思考狮身人面像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,因为这仍然是旧的语法,但是使用连接池,所以即使你没有将所有这些查询集中在一起,套接字设置开销也会尽可能地减少尽可能。
来源
2013-05-20 13:52:55
pat