[openstreetmap/openstreetmap-website] Split text search of notes and note comments in two (PR #6998)
Tom Hughes
notifications at github.com
Thu Apr 16 10:37:59 UTC 2026
@tomhughes 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)
It doesn't seem to make any significant change to the time for my test case but looking at the plan you can see it means that the top of the tree consists of sort+distinct (for the union) following by a second sort+distinct for the sort we have attached to the result.
I don't think we can get of that top one, or can we? What happens if two comments match?
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6998#discussion_r3092553909
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/6998/review/4120197130 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20260416/1fbd8c79/attachment.htm>
More information about the rails-dev
mailing list