Skip to content

Commit

Permalink
search: fixed a bit more the ordering of things
Browse files Browse the repository at this point in the history
Signed-off-by: Miquel Sabaté Solà <[email protected]>
  • Loading branch information
mssola committed Mar 15, 2024
1 parent 5975dec commit 38c383b
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/models/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def results
# 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, created_at'), comments: [] } if body.blank?
return { things: Thing.order('rate DESC, title, created_at'), comments: [] } if body.blank?

# Parse the body of the search, and return early if nothing was able to be
# parsed (e.g. user wrote unknown identifiers).
Expand Down Expand Up @@ -109,8 +109,10 @@ def find_by_tags(res:, tags:)

query = TagReference.where(tag: tags, taggable_type: 'Thing')
query = query.where(taggable_id: res[:things].pluck(:id)) if res[:things].present?
res[:things] = query.group(:taggable_id)
res[:things] = query.joins('INNER JOIN things ON things.id = tag_references.taggable_id')
.group(:taggable_id)
.having('count(taggable_id) = ?', tags.size)
.order('things.rate DESC, things.title, things.created_at')
.map(&:taggable)

query = TagReference.where(tag: tags, taggable_type: 'Comment')
Expand Down

0 comments on commit 38c383b

Please sign in to comment.