[英]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 @result
是MetaSearch::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.