简体   繁体   中英

Chain meta_search results

How can I chain metasearchs' search method ?

@result = User.search(params[:search]).search(params[:filters])

We can call chain method on ActiveRecord like

User.active.male.where( age: 14..20)

its chaining is possible on meta search's result ?

I got it working.. If you had the same problem, you can try following.

The search method of meta_search returns MetaSearch::Search::ModelName where ModelName is the name of your model. Meta_search provides a method relation for this object. You can call relation method to get an ActiveRecord::Relation object and then you can call the search method again on that object. See the code below to see what I am exactly talking about.

@result = User.search(params[:search])
@search = @result.relation.search(params[:filters])

Here @result is the instance of MetaSearch::Search::User so we can call relation method to get an instance of ActiveRecord::Relation ie

@result.relation

and then we can call search method again on this instance. ie

@result.relation.search(params[:filters])

一口气搜索

@result = User.search  params[:search].merge(params[:filters])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM