【问题标题】:How to perform sphinx Multi-queries with Thinking Sphinx如何使用 Thinking Sphinx 执行 sphinx 多查询
【发布时间】:2013-05-20 11:32:21
【问题描述】:

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

Sphinx 似乎支持多查询:http://sphinxsearch.com/docs/2.0.7/multi-queries.html

将 ThinkingSphinx 与 Rails 应用程序一起使用,有什么方法可以使用此功能吗?

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

【问题讨论】:

    标签: search sphinx thinking-sphinx


    【解决方案1】:

    在 Thinking 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
    

    Thinking Sphinx 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,因为这仍然是旧语法,但使用了连接池,因此即使您没有将所有这些查询批处理在一起,也会尽可能减少套接字设置开销。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-03
      相关资源
      最近更新 更多