diff options
Diffstat (limited to 'app')
| -rw-r--r-- | app/models/search.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/app/models/search.rb b/app/models/search.rb index 22a282d..8a780bb 100644 --- a/app/models/search.rb +++ b/app/models/search.rb @@ -14,7 +14,10 @@ class Search < ApplicationRecord # This can happen as part of an empty Search.new instance. That is, it's # still invalid, but it's the object being initialized for the default # search (i.e. just show me everything). - return { things: Thing.order('rate DESC, title, created_at'), comments: [] } if body.blank? + if body.blank? + return { things: Thing.order(rate: :desc, title: :asc, created_at: :asc), + comments: [] } + end # Parse the body of the search, and return early if nothing was able to be # parsed (e.g. user wrote unknown identifiers). @@ -90,9 +93,10 @@ class Search < ApplicationRecord plain.each do |text| res[:things] = if res[:things].any? - res[:things].and(Thing.like(text:)).order('rate DESC, title, created_at') + res[:things].and(Thing.like(text:)) + .order(rate: :desc, title: :asc, created_at: :asc) else - Thing.like(text:).order('rate DESC, title, created_at') + Thing.like(text:).order(rate: :desc, title: :asc, created_at: :asc) end res[:comments] = if res[:comments].any? res[:comments].and(Comment.like(text:)).order(:created_at) |
