How to index boolean column in thinking sphinx using Ruby 1.8.7

让人想犯罪 __ 提交于 2019-12-23 15:19:36

问题


I am new to ROR. i am using thinking sphinx. I need to index with one boolean field. that is, i list out records which are active is true.

define_index do
  indexes car.name, :as => :car
  indexes car_model.car_make.name, :as => :car_make
  indexes city_name.city , :as=> :city_name
  indexes car_active, :as=>:is_active, :type=>:boolean, :default=>true
end

I need to list out car details which are belong to active is true. can you help me?


回答1:


If you want to filter on a boolean, then it's much better to have it as an attribute in Sphinx, instead of a field. Fields are the text data people will search for, attributes are the things you as a developer will order and filter by.

So, to set up that boolean column as an attribute:

define_index do
  # fields
  indexes car.name, :as => :car
  indexes car_model.car_make.name, :as => :car_make
  indexes city_name.city , :as=> :city_name

  # attributes
  has car_active
end

And then filtering:

Model.search 'foo', :with => {:car_active => true}


来源:https://stackoverflow.com/questions/6443975/how-to-index-boolean-column-in-thinking-sphinx-using-ruby-1-8-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!