[openstreetmap/openstreetmap-website] Split text search of notes and note comments in two (PR #6998)

Marwin Hochfelsner notifications at github.com
Thu Apr 16 10:49:38 UTC 2026


@hlfan commented on this pull request.



> @@ -263,7 +263,10 @@ def search
 
       # Add any text filter
       if params[:q]
-        @notes = @notes.joins(:comments).where("to_tsvector('english', note_comments.body) @@ plainto_tsquery('english', ?) OR to_tsvector('english', notes.description) @@ plainto_tsquery('english', ?)", params[:q], params[:q])
+        matched_notes = @notes.where("to_tsvector('english', notes.description) @@ plainto_tsquery('english', ?)", params[:q])
+        matched_note_comments = @notes.joins(:comments).where("to_tsvector('english', note_comments.body) @@ plainto_tsquery('english', ?)", params[:q])
+
+        @notes = matched_notes.union_all(matched_note_comments)

That's why I usually stray far from SQL ¯\\\__(_ツ_)_\_/¯
But with the distinct, I think it's fine.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6998#discussion_r3092617370
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6998/review/4120263686 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260416/dcf959ce/attachment.htm>


More information about the rails-dev mailing list