Question

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.**
Was it helpful?

Solution

Right now your index does not include the live_flag just add live_flag to your to_indexed_json and mapping

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top