aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <msabate@suse.com>2024-03-15 17:20:29 +0100
committerMiquel Sabaté Solà <msabate@suse.com>2024-03-15 17:20:29 +0100
commit38c383b22d3999f0c1184dbc7b1d80573e4ee278 (patch)
tree9eae9d8baf57f2340b28af6d0828aafad6dd6462 /app
parent5975dec5d7cddfa88caa1e78c2ca8b41d4a0cd5c (diff)
downloadoperum-38c383b22d3999f0c1184dbc7b1d80573e4ee278.tar.gz
operum-38c383b22d3999f0c1184dbc7b1d80573e4ee278.zip
search: fixed a bit more the ordering of things
Signed-off-by: Miquel Sabaté Solà <msabate@suse.com>
Diffstat (limited to 'app')
-rw-r--r--app/models/search.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/app/models/search.rb b/app/models/search.rb
index 053e641..e1c3a9b 100644
--- a/app/models/search.rb
+++ b/app/models/search.rb
@@ -12,7 +12,7 @@ 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, 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).
@@ -109,8 +109,10 @@ class Search < ApplicationRecord
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')