From 38c383b22d3999f0c1184dbc7b1d80573e4ee278 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 15 Mar 2024 17:20:29 +0100 Subject: search: fixed a bit more the ordering of things MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Miquel Sabaté Solà --- app/models/search.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'app/models/search.rb') 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') -- cgit v1.2.3