From 0679cb356e80cfed75acfafd0670c08095f3839b Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Wed, 4 Sep 2024 10:14:57 -0300 Subject: [PATCH] Searching for fact-checks should match claim fields too. (#2020) Now searching for fact-checks matches the claim fields "description" and "context". Fixes: CV2-5194. --- app/models/team.rb | 6 +++--- test/models/team_2_test.rb | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/models/team.rb b/app/models/team.rb index 9facc8b32..be43ee2c7 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -545,11 +545,11 @@ def filtered_fact_checks(filters = {}) end def filter_by_keywords(query, filters, type = 'FactCheck') - tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text]]) # FIXME: May not work for all languages + tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text]]) if type == 'FactCheck' - tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(summary, '') || coalesce(url, ''))" + tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(summary, '') || ' ' || coalesce(url, '') || ' ' || coalesce(claim_descriptions.description, '') || ' ' || coalesce(claim_descriptions.context, ''))" else - tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(description, '') || coalesce(url, ''))" + tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(description, '') || ' ' || coalesce(url, ''))" end query.where(Arel.sql("#{tsvector} @@ #{tsquery}")) end diff --git a/test/models/team_2_test.rb b/test/models/team_2_test.rb index 3906def15..5b2df9544 100644 --- a/test/models/team_2_test.rb +++ b/test/models/team_2_test.rb @@ -1528,12 +1528,13 @@ def setup Sidekiq::Testing.fake! t = create_team # Fact-checks - create_fact_check title: 'Some Other Test', claim_description: create_claim_description(project_media: create_project_media(team: t)) - create_fact_check title: 'Bar Bravo Foo Test', claim_description: create_claim_description(project_media: create_project_media(team: t)) + create_fact_check title: 'Some Other Test', claim_description: create_claim_description(description: 'Claim', project_media: create_project_media(team: t)) + create_fact_check title: 'Bar Bravo Foo Test', claim_description: create_claim_description(context: 'Claim', project_media: create_project_media(team: t)) create_fact_check title: 'Foo Alpha Bar Test', claim_description: create_claim_description(project_media: create_project_media(team: t)) assert_equal 3, t.filtered_fact_checks.count assert_equal 3, t.filtered_fact_checks(text: 'Test').count assert_equal 2, t.filtered_fact_checks(text: 'Foo Bar').count + assert_equal 2, t.filtered_fact_checks(text: 'Claim').count assert_equal 1, t.filtered_fact_checks(text: 'Foo Bar Bravo').count assert_equal 1, t.filtered_fact_checks(text: 'Foo Bar Alpha').count assert_equal 0, t.filtered_fact_checks(text: 'Foo Bar Delta').count