【问题标题】:Thinking Sphinx : Multiple indices searchThinking Sphinx : 多索引搜索
【发布时间】:2017-12-12 12:21:10
【问题描述】:

我想为同一个模型创建两个索引并分别搜索

我正在使用

gem 'thinking-sphinx', '3.2.0'
gem 'riddle', '1.5.11'
ThinkingSphinx::Index.define :product, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do
    indexes :field_a
end

ThinkingSphinx::Index.define :product, :name => "active_product", :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta do
    indexes :field_a
    where "(active = 1)"
end

当我尝试以这种方式搜索以仅获取有效产品时

Product.search_for_ids "", :match_mode => :extended, :index => "active_product_core, active_product_delta", :page => params[:page], :per_page => 50, :sort_mode => :extended, :order => "field_a desc"

但它正在运行这样的查询并列出所有产品

 SELECT * FROM `product_core`, `product_delta` WHERE `sphinx_deleted` = 0 ORDER BY `field_a` desc LIMIT 0, 50 OPTION max_matches=50000

我怎样才能只获得有效产品或确保查询像这样运行?

SELECT * FROM `active_product_core`, `active_product_delta` WHERE `sphinx_deleted` = 0 ORDER BY `field_a` desc LIMIT 0, 50 OPTION max_matches=50000

注意:上述功能在 Thinking sphinx 版本 2 中运行良好

gem 'thinking-sphinx', '2.0.14'
gem 'riddle', '1.5.3'

【问题讨论】:

    标签: thinking-sphinx


    【解决方案1】:

    在 TS v3 中,搜索选项现在是 :indices 而不是 :index,并且需要一个索引名称数组。因此,请尝试以下操作:

    Product.search_for_ids(
      :indices  => ["active_product_core", "active_product_delta"],
      :page     => params[:page],
      :per_page => 50,
      :order    => "field_a desc"
    )
    

    我已从您正在使用的选项中删除了 :sort_mode:match_mode - extended 方法是 Sphinx 的 SphinxQL 协议可用的唯一方法(这就是 TS v3 使用的方法) ,因此您无需指定它们。

    【讨论】:

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