在Sunspot solr搜索中跳过字段

时间:2012-02-09 11:51:25

标签: ruby-on-rails search solr sunspot-solr

我已经在我的rails应用程序的2个位置实现了solr搜索(ruby 1.8.7和rails 2.3.4)。我已经为搜索字段编制索引,但它运行正常。现在我想再添加一个字段,我可以在第一个搜索栏中搜索但不能在第二个搜索栏中搜索。如何在第二个字段中跳过字段搜索。有任何排除选项,因为存在字段选项。相同的模型用于搜索和下面的相同代码。

宝石版

rsolr 0.12.1

太阳黑子(1.0.1)

search = Sunspot.search(Food) do
  keywords reference if reference.present?
  with(:vendor_id).any_of(vendor_ids) if vendor_ids.present?
  order_by :created_at, :desc
  paginate(:page => page, :per_page => per_page)
end

1 个答案:

答案 0 :(得分:5)

我能够按照预期使用

解决此问题

keywords reference, :fields => [:user_name, :food_habits, :age] if reference.present?

keywords reference, :fields => [:calorie_content, :user_name, :age] if vitamins.present?