Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates notes filtering to search description too #5622

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/controllers/api/notes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
7 changes: 4 additions & 3 deletions app/models/note.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20250206202905_add_text_index_to_notes.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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: -
--
Expand Down Expand Up @@ -3422,6 +3429,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('23'),
('22'),
('21'),
('20250206202905'),
('20250121191749'),
('20250105154621'),
('20250104140952'),
Expand Down
Loading