2015-05-21 59 views
0

我已配置sunspot-2.1.1Model.solr_search不適用於地理空間過濾器

問題

  • 我想搜索在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 

上午什麼我錯過了,爲什麼沒有在生產環境中工作,並正在努力在開發環境中它?

感謝

回答

0

真是對不起打開這個問題,我傻誰創造searches_controller_backup.rb其中有醇d代碼未配置geospatial過濾功能。

問題是一切正常工作但由於軌道從備份文件加載searching_controller代碼,它被認爲看起來它不起作用。

有了這個說明,以上兩個代碼工作完美沒有任何問題....所以Model.solr_searchgeospatial filter沒有任何關係。

刪除備份文件或更改擴展名爲.rb以外的問題修復了我的問題