繁体   English   中英

轮胎弹性搜索过滤问题

[英]Filter issue with tire elasticsearch

Want to search for the title from the board with live_flag true.

class Board < ActiveRecord::Base
   has_many :deals
   include Tire::Model::Search

  tire.mapping do
    indexes :title,  type: 'string'
    indexes :deals do
      indexes :title, type: 'string'
    end
  end

  def to_indexed_json
    {
    :title          => title,
    :deals     => {:title => self.deals.map(&:title)},
    }.to_json
  end

  def self.search(params)
    tire.search(load: true) do
      query  {string params[:query]+"*"}
      filter :term, live_flag: true
      sort { by :created_at, "desc" } if params[:query].blank?
    end
  end

end



Now it will not search anything.


It works properly when below code is used. Difference is that i have removed filter text from it.

   def self.search(params)
    tire.search(load: true) do
      query  {string params[:query]+"*"}
      sort { by :created_at, "desc" } if params[:query].blank?
    end
  end

   **But i want to get boards whose live_flag is true.**

现在你的索引不包含live_flag只需将live_flag添加到你的to_indexed_json并映射

tire.mapping do
    indexes :title,  type: 'string'
    indexes :live_flag, type: 'boolean'
    indexes :deals do
      indexes :title, type: 'string'
    end
  end

  def to_indexed_json
    {
    :title          => title,
    :live_flag     => live_flag,
    :deals     => {:title => self.deals.map(&:title)},
    }.to_json
  end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM