简体   繁体   English

链meta_search结果

[英]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 我们可以像这样在ActiveRecord上调用链方法

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的搜索方法返回meta_search MetaSearch::Search::ModelName ,其中ModelName是模型的名称。 Meta_search provides a method relation for this object. Meta_search为此对象提供了一种方法relation You can call relation method to get an ActiveRecord::Relation object and then you can call the search method again on that object. 您可以调用relation方法来获取ActiveRecord::Relation对象,然后可以对该对象再次调用搜索方法。 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 @resultMetaSearch::Search::User的实例,因此我们可以调用relation方法来获取ActiveRecord::Relation的实例,即

@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])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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