开发者

How can I have a single search field form that outputs all records from all models?

I want to create a really simple search form, basically a single field, that appears in the header of every page in my application.

My application has several models, each with several fields.

I'd like to know how to have that search get passed as a parameter into an output which shows all instances of that text item or items (meaning, if there are t开发者_运维知识库wo elements, a first name and a last name, for example, that it pulls up records that have both values).

I currently use searchlogic, but I think that's really field specific. Looked into texticle since I am on heroku, but I still not clear what to do or if this is right way to go. Thank you.


Try out SOLR -- it will create an index of your models, and you can search on it. SOLR is the search engine -- use the following gems in rails: 'sunspot', 'sunspot_rails'

You'll do something like:

@sunspot_search = Sunspot.search User, Event, Coupon do |query| 
  query.keywords @search_query
  query.with(:starts_at).greater_than Time.now
  query.order_by(:starts_at, :asc)
  query.paginate(:page => @page_number, :per_page => 200)
end

@sunspot_search will have your results array that you'll iterate over.

http://websolr.com/ gets you setup easily; works on Heroku.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜