Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

Sorting Results

Konstantin Zub edited this page Nov 7, 2013 · 2 revisions

Single Sort

Event.tire.search({}) do |s|
  s.query do |q|
    q.string 'Concert'
  end
  s.sort do |t|
    t.by :name, 'desc'
  end
end

Multiple Sort

Event.tire.search({}) do |s|
  s.query do |q|
    q.string 'Concert'
  end
  s.filter :geo_distance, {distance: "5mi", coordinates: [-15, 35]}
  s.sort do |t|
    t.by :name, 'desc'
    t.by :_geo_distance, coordinates: [-15, 35], unit: 'mi', order: 'asc'
  end
end

No Mapping Found Error

Event.tire.search({}) do |s|
  s.query do |q|
    q.string 'Concert'
  end
  s.filter :geo_distance, {distance: "5mi", coordinates: [-15, 35]}
  s.sort do |t|
    t.by :starting_time, ignore_unmapped: true, order: :asc
    t.by :_geo_distance, coordinates: [-15, 35], unit: 'mi', order: :asc
  end
end