2011-12-17 14 views
0

こんにちは私は簡単な検索エンジンを書こうとしています。私のようなURLを取得:フィルターのあるレストランを検索する

.../fragments/get_restaurants?city=London&service=1,2 

と私はこのような検索をしたいと思います:

def get_restaurants 
    regions_find = Region.find(:all, :select => "id", :conditions => ["name LIKE ?", "#{params[:city]}"]).restaurants 
    cities_find = City.find(:all, :select => "id", :conditions => ["name LIKE ?", "%#{params[:city]}%"]).restaurants 
    regions_and_cities = reg.merge!(cit).uniq 
    restaurans_all = regions_and_cities.find(:all, :conditions => ["name LIKE ?", "%#{params[:name]}%" OR TYPE OR KIND]) 

    filtered = filter(restaurans_all) 

    render :partial => "fragments/restaurant", :collection => res 
end 

が、私は本当にそれを動作させる方法がわかりません。ここで

は、レストラン、都市や地域のモデルである:

class Region < ActiveRecord::Base 
    has_many :cities, :dependent => :destroy # dependent only with has_ 
    has_many :restaurants 
end 

class Restaurant < ActiveRecord::Base 
    belongs_to :region 
    belongs_to :city 
    has_many :restaurants_types 
    has_many :types, :through => :restaurants_types 
end 

class City < ActiveRecord::Base 
    belongs_to :region 
    has_many :restaurants 
end 

私はでそれをフィルタリングしたいのですが、結果がある場合:これで

def filter(table) 
    res = table 
    res &= table.filter('types', params[:type].split(','))   unless params[:type].nil? 
    res &= table.filter('cuisines', params[:cuisine].split(',')) unless params[:cuisine].nil? 
    res &= table.filter('facilities', params[:facility].split(',')) unless params[:facility].nil? 
    res &= table.filter('prices', params[:price].split(','))  unless params[:price].nil? 
    return res 
    end 

scope :filter, lambda{|type_name, type_id| includes(type_name.to_sym).where(["#{type_name}.id in (?)", type_id]) } 

でも動作しません。どのように私はこれを行うことができますいくつかのヒントを教えていただけますか?

+0

私の精神的なズボンを履いてみましょう、それから私はそれがあまりにもうまく動作していない知っているよ。 – Trip

答えて

0

これを最初から修正するのではなく、Searchlogicを開始点として使用します。

+0

ありがとうございますが、Raillog 3.1のSearchlogicに問題がありますが、Squeelが見つかりました。それは私には良いことです。 –

+0

Oh no。私はSearchlogicが大好きですが、まだRails 3.1を使用していません。 Squeelのヒントをありがとう。 – jdl

関連する問題