轮胎返回空阵列

时间:2014-06-03 18:15:29

标签: ruby-on-rails ruby-on-rails-4 elasticsearch tire

我正在使用elasticsearch来快速搜索,但不幸的是我不知道它返回空数组结果的原因。期待你们的帮助。

class Post < ActiveRecord::Base
    include Tire::Model::Search
    include Tire::Model::Callbacks

    has_many :attachments, as: :attachable
    accepts_nested_attributes_for :attachments, allow_destroy: true

    mapping do
        indexes :work_type
        indexes :title
        indexes :location
        indexes :industry_type
        indexes :key_words
        indexes :type       
    end

    after_save { update_index }

    def self.search(params)
        tire.search(load: true) do
            query do
                boolean do
                    must   { string                              params[:query] }         if params[:query].present?
                    must   { match :type,          params[:type] }          if params[:type].present? && params[:type] != "all"
                    must   { match :title,         params[:title] }         if params[:title].present?
                    must   { match :industry_type, params[:industry_type] } if params[:industry_type].present?
                    must   { match :key_words,     params[:key_words] }     if params[:key_words].present?
                end
            end

            sort { by :title, 'desc' }
        end
    end


params = {"utf8"=>"✓",
 "type"=>"Job",
 "query"=>"",
 "location"=>"",
 "post"=>{"work_type"=>""},
 "action"=>"index",
 "controller"=>"posts"}

0 个答案:

没有答案