Ruby on rails 思考斯芬克斯,用联想过滤?

Ruby on rails 思考斯芬克斯,用联想过滤?,ruby-on-rails,ruby,activerecord,thinking-sphinx,Ruby On Rails,Ruby,Activerecord,Thinking Sphinx,我在Rails应用程序中思考Sphinx时遇到了严重问题。我的应用程序规范如下: 轨道3.2.6 Ruby 1.9.3 斯芬克斯2.0.4(r3135) 思考斯芬克斯2.0.12 在我的应用程序中,我有一个页面模型和一个报价模型,页面有许多报价。页面模型中定义的索引如下所示: define_index do #other indexes defined here #... has offers.width, as: :offers_width has offers.hei

我在Rails应用程序中思考Sphinx时遇到了严重问题。我的应用程序规范如下:

  • 轨道3.2.6
  • Ruby 1.9.3
  • 斯芬克斯2.0.4(r3135)
  • 思考斯芬克斯2.0.12
在我的应用程序中,我有一个
页面
模型和一个
报价
模型,
页面
有许多
报价
页面
模型中定义的索引如下所示:

define_index do

  #other indexes defined here
  #...

  has offers.width, as: :offers_width
  has offers.height, as: :offers_height
  has offers.price, as: :offers_price

  set_property delta: true
end
define_index do

  indexes page(:description), as: :page_description
  indexes page(:address), as: :page_address
  indexes page(:title), as: :page_title
  indexes page(:status), as: :page_status
  indexes page.tags(:name), as: :page_tags_name
  indexes page.category(:id), as: :page_category_id
  indexes page.country(:id), as: :page_country_id
  indexes page(:verified), as: :page_verified

  has page(:id), as: :page_id
  has :width
  has :height
  has :price
end
然后我在
页面
模型上进行搜索,根据搜索查询和条件选择
页面
。然而,当我试图使用带有过滤器的
:时,斯芬克斯给了我错误的结果

当我只使用一个过滤器时,例如
price
width
,结果是正常的,但是当我尝试组合过滤器时,例如
price和width
,我得到的结果包含给定
price
width
,而不是
price
width

当我搜索范围时,大多数时候
:with
参数都是范围,而不仅仅是整数值

编辑1
使用以下命令查询即时消息:

Page.search Riddle.escape(query), conditions: conditions, with: has_cond, star: true, per_page: Page.per_page, page: page
其中,的条件是:

{:offers_height=>[175..200], :offers_width=>[175..200], :offers_price=>[10..80]}

它仍然会给我提供任何报价的高度在该范围内或任何报价的宽度在该范围内或与价格相同的页面。

我相信错误将在您的搜索查询本身内。我只是做了一些测试,一切都正常。。。有射程和无射程

控制器中的搜索代码:

@titles = Title.search(params[:q], 
                              :rank_mode => :bm25,
                              :match_mode => :any,
                              :star => true,
                              :limit => 35,
                              :with_all => {
                                :runtime => [75..100],
                                :year => 1976
                              })
class Title < ActiveRecord::Base
    ...
    define_index do
      # fields
      indexes clean_name, :sortable => true
      # attributes
      has id, year, runtime, created_at, updated_at
    end
    ...
end
索引代码:

@titles = Title.search(params[:q], 
                              :rank_mode => :bm25,
                              :match_mode => :any,
                              :star => true,
                              :limit => 35,
                              :with_all => {
                                :runtime => [75..100],
                                :year => 1976
                              })
class Title < ActiveRecord::Base
    ...
    define_index do
      # fields
      indexes clean_name, :sortable => true
      # attributes
      has id, year, runtime, created_at, updated_at
    end
    ...
end

对于我正在进行的项目,它不使用联接表——但这不重要。索引仍然相同,只是执行了连接。

好的,我找到了解决方案。斯芬克斯给我错误结果的原因是因为他在一个页面中聚合了所有的报价。我不得不将索引从一个页面移动到另一个页面,现在查询工作正常了。我的报价索引如下所示:

define_index do

  #other indexes defined here
  #...

  has offers.width, as: :offers_width
  has offers.height, as: :offers_height
  has offers.price, as: :offers_price

  set_property delta: true
end
define_index do

  indexes page(:description), as: :page_description
  indexes page(:address), as: :page_address
  indexes page(:title), as: :page_title
  indexes page(:status), as: :page_status
  indexes page.tags(:name), as: :page_tags_name
  indexes page.category(:id), as: :page_category_id
  indexes page.country(:id), as: :page_country_id
  indexes page(:verified), as: :page_verified

  has page(:id), as: :page_id
  has :width
  has :height
  has :price
end
我需要先查询sphinx,然后执行活动记录查询

@sphinx_query = Offer.search Riddle.escape(query), with: has_cond, 
    conditions: conditions, group_function: :attr, group_by: 'page_id', 
    star: true, per_page: Page.per_page, page: page
@pages = Page.find(@sphinx_query.map(&:page_id))

你能发布搜索电话吗?当然,我已经编辑了我的帖子。