From 63021ead513b04b33bff125bdd4dd06948584b29 Mon Sep 17 00:00:00 2001 From: Draconic NEO <44508470+DraconicNEO@users.noreply.github.com> Date: Sun, 23 Feb 2025 11:23:34 +0900 Subject: [PATCH 1/5] Add Alt-Text Filter to post_view.rs Added Alt-text filter to search --- crates/db_views/src/post/post_view.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/db_views/src/post/post_view.rs b/crates/db_views/src/post/post_view.rs index 68c838f8af..7dbdf8fd08 100644 --- a/crates/db_views/src/post/post_view.rs +++ b/crates/db_views/src/post/post_view.rs @@ -489,6 +489,7 @@ impl<'a> PostQuery<'a> { let searcher = fuzzy_search(search_term); let name_filter = post::name.ilike(searcher.clone()); let body_filter = post::body.ilike(searcher.clone()); + let alt_text_filter = post::alt_text.ilike(searcher.clone()); query = if o.title_only.unwrap_or_default() { query.filter(name_filter) } else { From 3dd6a022d3a137db09c8fb8ffc73de6b339cecd0 Mon Sep 17 00:00:00 2001 From: Draconic NEO <44508470+DraconicNEO@users.noreply.github.com> Date: Sun, 23 Feb 2025 14:26:28 +0900 Subject: [PATCH 2/5] Actually use the Alt-text filter I added Add the call to actually use the alt-text filter I added. --- crates/db_views/src/post/post_view.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/db_views/src/post/post_view.rs b/crates/db_views/src/post/post_view.rs index 7dbdf8fd08..8539896213 100644 --- a/crates/db_views/src/post/post_view.rs +++ b/crates/db_views/src/post/post_view.rs @@ -493,7 +493,7 @@ impl<'a> PostQuery<'a> { query = if o.title_only.unwrap_or_default() { query.filter(name_filter) } else { - query.filter(name_filter.or(body_filter)) + query.filter(name_filter.or(body_filter).or(alt_text_filter)) } .filter(not(post::removed.or(post::deleted))); } From 2f03691a8d3ec97de47b5dc43264f74d06288a55 Mon Sep 17 00:00:00 2001 From: Draconic NEO <44508470+DraconicNEO@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:36:24 +0900 Subject: [PATCH 3/5] Create down.sql of migration --- migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql diff --git a/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql b/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql new file mode 100644 index 0000000000..c5bf1a7fb1 --- /dev/null +++ b/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql @@ -0,0 +1,3 @@ +DROP INDEX idx_post_trigram; + +CREATE INDEX IF NOT EXISTS idx_post_trigram ON post USING gin (name gin_trgm_ops, body gin_trgm_ops); From 65e790796df9a3812989a0fbb5539461c95e29a8 Mon Sep 17 00:00:00 2001 From: Draconic NEO <44508470+DraconicNEO@users.noreply.github.com> Date: Mon, 24 Feb 2025 17:36:54 +0900 Subject: [PATCH 4/5] Create up.sql --- migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql diff --git a/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql b/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql new file mode 100644 index 0000000000..23f40bd7c6 --- /dev/null +++ b/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql @@ -0,0 +1,3 @@ +DROP INDEX idx_post_trigram; + +CREATE INDEX IF NOT EXISTS idx_post_trigram ON post USING gin (name gin_trgm_ops, body gin_trgm_ops, alt_text gin_trgm_ops); From c184f82a80ade4d3e736069617b48279f63a77e9 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 24 Feb 2025 12:11:39 -0500 Subject: [PATCH 5/5] Fixing SQL format. --- migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql | 1 + migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql b/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql index c5bf1a7fb1..5d1b726118 100644 --- a/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql +++ b/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql @@ -1,3 +1,4 @@ DROP INDEX idx_post_trigram; CREATE INDEX IF NOT EXISTS idx_post_trigram ON post USING gin (name gin_trgm_ops, body gin_trgm_ops); + diff --git a/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql b/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql index 23f40bd7c6..21eb206337 100644 --- a/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql +++ b/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql @@ -1,3 +1,4 @@ DROP INDEX idx_post_trigram; CREATE INDEX IF NOT EXISTS idx_post_trigram ON post USING gin (name gin_trgm_ops, body gin_trgm_ops, alt_text gin_trgm_ops); +