From 663459d1c1e5e097c9b6d3f6742682eaff3f86e7 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Thu, 6 Feb 2025 22:01:21 +0100 Subject: [PATCH 1/2] Adds index to notes on description column Adds text index to description column to table notes. --- app/models/note.rb | 7 ++++--- db/migrate/20250206202905_add_text_index_to_notes.rb | 7 +++++++ db/structure.sql | 8 ++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 db/migrate/20250206202905_add_text_index_to_notes.rb diff --git a/app/models/note.rb b/app/models/note.rb index 807ee9ec8b..b7215d6f77 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -16,9 +16,10 @@ # # Indexes # -# notes_created_at_idx (created_at) -# notes_tile_status_idx (tile,status) -# notes_updated_at_idx (updated_at) +# index_notes_on_description (to_tsvector('english'::regconfig, description)) USING gin +# notes_created_at_idx (created_at) +# notes_tile_status_idx (tile,status) +# notes_updated_at_idx (updated_at) # # Foreign Keys # diff --git a/db/migrate/20250206202905_add_text_index_to_notes.rb b/db/migrate/20250206202905_add_text_index_to_notes.rb new file mode 100644 index 0000000000..7798f22874 --- /dev/null +++ b/db/migrate/20250206202905_add_text_index_to_notes.rb @@ -0,0 +1,7 @@ +class AddTextIndexToNotes < ActiveRecord::Migration[7.2] + disable_ddl_transaction! + + def change + add_index :notes, "to_tsvector('english', description)", :using => "GIN", :name => "index_notes_on_description", :algorithm => :concurrently + end +end diff --git a/db/structure.sql b/db/structure.sql index 9093c47fe7..d23c2d7487 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -2540,6 +2540,13 @@ CREATE INDEX index_note_comments_on_created_at ON public.note_comments USING btr CREATE INDEX index_note_subscriptions_on_note_id ON public.note_subscriptions USING btree (note_id); +-- +-- Name: index_notes_on_description; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX index_notes_on_description ON public.notes USING gin (to_tsvector('english'::regconfig, description)); + + -- -- Name: index_oauth_access_grants_on_application_id; Type: INDEX; Schema: public; Owner: - -- @@ -3422,6 +3429,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('23'), ('22'), ('21'), +('20250206202905'), ('20250121191749'), ('20250105154621'), ('20250104140952'), From 4133936c6304b7d1a57c85d53fb7c3a906190164 Mon Sep 17 00:00:00 2001 From: Nenad Vujicic Date: Fri, 17 Jan 2025 18:53:05 +0100 Subject: [PATCH 2/2] Updates notes filtering to search description too Updates notes filtering to search for query text in both note comments and note's description. --- app/controllers/api/notes_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/notes_controller.rb b/app/controllers/api/notes_controller.rb index eca0728b65..f6d6dede9b 100644 --- a/app/controllers/api/notes_controller.rb +++ b/app/controllers/api/notes_controller.rb @@ -263,7 +263,9 @@ def search end # Add any text filter - @notes = @notes.joins(:comments).where("to_tsvector('english', note_comments.body) @@ plainto_tsquery('english', ?)", params[:q]) if params[:q] + 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]) + end # Add any date filter if params[:from]