From 1a299ba6284edc4cefb7507d84d01cd30649a28c Mon Sep 17 00:00:00 2001 From: Draconic NEO <44508470+DraconicNEO@users.noreply.github.com> Date: Wed, 26 Feb 2025 03:28:15 +0900 Subject: [PATCH] Include image alt text in post search (#5449) * Add Alt-Text Filter to post_view.rs Added Alt-text filter to search * Actually use the Alt-text filter I added Add the call to actually use the alt-text filter I added. * Create down.sql of migration * Create up.sql * Fixing SQL format. --------- Co-authored-by: Dessalines --- crates/db_views/src/post/post_view.rs | 3 ++- .../2025-02-24-173152_search-alt-text-of-posts/down.sql | 4 ++++ migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql create mode 100644 migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql diff --git a/crates/db_views/src/post/post_view.rs b/crates/db_views/src/post/post_view.rs index 68c838f8a..853989621 100644 --- a/crates/db_views/src/post/post_view.rs +++ b/crates/db_views/src/post/post_view.rs @@ -489,10 +489,11 @@ 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 { - 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))); } 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 000000000..5d1b72611 --- /dev/null +++ b/migrations/2025-02-24-173152_search-alt-text-of-posts/down.sql @@ -0,0 +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 new file mode 100644 index 000000000..21eb20633 --- /dev/null +++ b/migrations/2025-02-24-173152_search-alt-text-of-posts/up.sql @@ -0,0 +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); +