[英]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正在從備份文件中加載searchs_controller代碼,因此它看起來似乎無法正常工作。
有了這個注意事項,以上兩個代碼都可以正常工作而沒有任何問題....因此Model.solr_search
與geospatial filter
Model.solr_search
無關。
刪除備份文件或將擴展名更改為.rb
以外的其他文件解決了我的問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.