Skip to content

Commit

Permalink
Searching for fact-checks should match claim fields too. (#2020)
Browse files Browse the repository at this point in the history
Now searching for fact-checks matches the claim fields "description" and "context".

Fixes: CV2-5194.
  • Loading branch information
caiosba authored Sep 4, 2024
1 parent f6eb4c0 commit 0679cb3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
6 changes: 3 additions & 3 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions test/models/team_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0679cb3

Please sign in to comment.