簡體   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