1

我想使用搜索與可選參數(思維獅身人面像)。獅身人面像搜索與可選參數

在我的控制器我有3個PARAMS:

params[:model_id], params[:engine_id], params[:city_id] 

控制器

def search 
    @search = Car.search :conditions => { 
     :model_id => params[:model_id], 
     :engine_id => params[:engine_id], 
     :city_id => params[:city_id] 
     } 
    end 

型號

define_index do 
    indexes model_id 
    indexes city_id 
    indexes area_id 
    indexes engine_id 
    indexes mileage 
    end 

當參數之一是零,我得到一個錯誤:

提取的源(左右線#4):

1: Result: 
2: %br 
3: %br 
4: = render :partial => "search_item", :collection => @search, :as => :item 

index car_core: syntax error, unexpected TOK_FIELDLIMIT near ' @engine_id @city_id' 

UPD1:

我的形式

= form_tag search_adverts_path, :method => :get, :id => 'admin_quick_filter' do 
    %label 
    = t('form.mileage') 
    = text_field_tag :min_mileage, params[:min_mileage] 
    = text_field_tag :max_mileage, params[:max_mileage] 
    %br 
    = select_tag :model_id, options_for_select(Model.all.collect{|c| [c.name, c.id]} , params[:model_id]), :include_blank => true 
    %br 
    = select_tag :engine_id, options_for_select(Engine.all.collect{|c| [c.name, c.id]} , params[:engine_id]), :include_blank => true 
    %br 
    = select_tag :city_id, options_for_select(City.all.collect{|c| [c.name, c.id]} , params[:city_id]), :include_blank => true 
    %br 
    %br 
    = submit_tag t('form.search') 


= render "search_result" 
+0

也許我應該用sphinx_scope? –

回答

0
define_index do 
    indexes name 

    has mileage 
end 

Car.search:用=> {:里程=> 100..150000}

曾爲

1

搜索時,當你提供:conditions,ThinkingSphinx附加@filedname在查詢範圍搜索那個領域。而獅身人面像不處理nil values。所以你應該在將它傳遞給search()方法之前檢查零值。

Please keep in mind that Sphinx does not support SQL comparison operators – it has its own query language. The :conditions option must be a hash, with each key a field and each value a string.