在思考獅身人面像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