To search according to passed parameters
# File app/models/concerns/trade_search.rb, line 71 def self.search(params) @search_definition = {query: {filtered: {}}} if !params[:without_fixxpert_existence] @search_definition[:query][:filtered] = { filter: { exists: { field: "fixxperts" } } } end unless params[:query].blank? if !params[:without_fixxpert_existence] @search_definition[:query][:filtered][:query] = { multi_match: { query: params[:query], fields: [ "name", "subtrades.name", "subtrades.teachers", "subtrades.mini_description" ], type: "phrase_prefix" } } else @search_definition[:query][:filtered][:query] = { multi_match: { query: params[:query], fields: [ "name", "subtrades.name", "fixxperts.name", "subtrades.teachers", "subtrades.mini_description" ], type: "phrase_prefix" } } end end __elasticsearch__.search(@search_definition) end
This will return all the relevant rows from the database in json format
# File app/models/concerns/trade_search.rb, line 30 def as_indexed_json(options={}) { id: id, name: name, description: description, subtrades: subtrades.map { |c| { _type: 'subtrade', _id: c.id, name: c.name, teachers: c.teachers, mini_description: c.mini_description } }, fixxperts: fixxperts.map { |t| { _type: 'fixxpert', _id: t.id, name: t.name } } } end
Calls Superclass Method
# File app/models/concerns/trade_search.rb, line 55 def as_json(options={}) json = super(options) json[:_type] = "trade" json end