我已经使用地理编码器实现了基于位置的搜索,并且无法集成meta_search gem。我正在尝试将meta_search集成到我的object_controller
index
中,以允许用户在按位置搜索后按对象:attributes
对搜索结果进行过滤和排序。
我的object_controller:
def index
if params[:search].present?
@objects = Object.near(params[:search], 50, :order => :distance).paginate(:page => params[:page], :per_page => 9)
else
@objects = Object.paginate(:page => params[:page], :per_page => 9)
end
end
知道如何最好地将@search集成到meta_search gem所需的索引中吗?
以下是meta_search github为索引推荐的内容:
def index
@search = Article.search(params[:search])
@articles = @search.all # load all matching records
# @articles = @search.relation # Retrieve the relation, to lazy-load in view
# @articles = @search.paginate(:page => params[:page]) # Who doesn't love will_paginate?
end
非常感谢,
威尔
答案 0 :(得分:1)
我相信geocoder
和meta_search
查询方法都会返回ActiveRecord::Relation
,因此您应该可以将它们链接起来:
@objects = Object.near(params[:search], 50, :order => :distance).search(params[:search]).relation.paginate(:page => params[:page], :per_page => 9)
或者如果您需要将搜索对象分开:
@search = Object.near(params[:search], 50, :order => :distance).search(params[:search])
@objects = @search.relation.paginate(:page => params[:page], :per_page => 9)