Model.solr_search 不适用于地理空间过滤器
Model.solr_search not working for geospatial filter
我已配置sunspot-2.1.1
。
问题
我想搜索半径 20 英里内的所有产品,以下是我为 Product
型号
执行此操作的代码
Product.search do
fulltext(params[:search][:keyword])
order_by_geodist(:location, current_user.lat, current_user.lng)
with(:location).in_radius(current_user.lat, current_user.lng, mile_to_km)
paginate page: params[:page], per_page: GlobalConstant::SEARCH_RESULT_PER_PAGE
end
注意:以上代码在开发环境中工作正常,但在生产环境中不工作。我也尝试过重新索引 solr,但没有成功:(
我在显示基于半径的产品列表的搜索页面之外添加了以下代码并且它正在运行:
Sunspot.search [Product] do
without(:sale_status, 'draft')
with(:user_id, current_user.id)
unless current_user.location.blank?
order_by_geodist(:location, current_user.lat, current_user.lng)
with(:location).in_radius(current_user.lat, current_user.lng, (mile_to_km))
end
paginate page: params[:page], per_page: GlobalConstant::TIMELINE_PER_PAGE
end
我错过了什么,为什么它在生产环境中不起作用而在开发环境中起作用。?
谢谢
我真的很抱歉打开这个问题,我是一个愚蠢的人,我创建了 searches_controller_backup.rb
,其中的旧代码没有配置 geospatial
过滤器功能。
问题是 一切正常 但是因为 rails 正在从备份文件加载 searches_controller 代码,所以它看起来好像没有工作.
请注意,以上两个代码都可以正常工作,没有任何问题....因此 Model.solr_search
与 geospatial filter
不工作无关。
删除备份文件或将扩展名更改为 .rb
以外的扩展名解决了我的问题
我已配置sunspot-2.1.1
。
问题
我想搜索半径 20 英里内的所有产品,以下是我为
执行此操作的代码Product
型号Product.search do fulltext(params[:search][:keyword]) order_by_geodist(:location, current_user.lat, current_user.lng) with(:location).in_radius(current_user.lat, current_user.lng, mile_to_km) paginate page: params[:page], per_page: GlobalConstant::SEARCH_RESULT_PER_PAGE end
注意:以上代码在开发环境中工作正常,但在生产环境中不工作。我也尝试过重新索引 solr,但没有成功:(
我在显示基于半径的产品列表的搜索页面之外添加了以下代码并且它正在运行:
Sunspot.search [Product] do
without(:sale_status, 'draft')
with(:user_id, current_user.id)
unless current_user.location.blank?
order_by_geodist(:location, current_user.lat, current_user.lng)
with(:location).in_radius(current_user.lat, current_user.lng, (mile_to_km))
end
paginate page: params[:page], per_page: GlobalConstant::TIMELINE_PER_PAGE
end
我错过了什么,为什么它在生产环境中不起作用而在开发环境中起作用。?
谢谢
我真的很抱歉打开这个问题,我是一个愚蠢的人,我创建了 searches_controller_backup.rb
,其中的旧代码没有配置 geospatial
过滤器功能。
问题是 一切正常 但是因为 rails 正在从备份文件加载 searches_controller 代码,所以它看起来好像没有工作.
请注意,以上两个代码都可以正常工作,没有任何问题....因此 Model.solr_search
与 geospatial filter
不工作无关。
删除备份文件或将扩展名更改为 .rb
以外的扩展名解决了我的问题