Skip to content

Commit

Permalink
No need to split, strip, and join with websearch_to_tsquery
Browse files Browse the repository at this point in the history
  • Loading branch information
computermacgyver committed Aug 28, 2024
1 parent 5012694 commit 0aef3e9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def filtered_explainers(filters = {})

# Filter by text
if filters[:text].to_s.size > 2
tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text].split(/\s+/).map(&:strip).join(' & ')]) # FIXME: May not work for all languages
tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text]]) # FIXME: May not work for all languages
tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(url, '') || coalesce(description, ''))"
query = query.where(Arel.sql("#{tsvector} @@ #{tsquery}"))
end
Expand Down Expand Up @@ -540,7 +540,7 @@ def filtered_fact_checks(filters = {})

# Filter by text
if filters[:text].to_s.size > 2
tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text].split(/\s+/).map(&:strip).join(' & ')]) # FIXME: May not work for all languages
tsquery = Team.sanitize_sql_array(["websearch_to_tsquery(?)", filters[:text]]) # FIXME: May not work for all languages
tsvector = "to_tsvector('simple', coalesce(title, '') || ' ' || coalesce(summary, '') || coalesce(url, ''))"
query = query.where(Arel.sql("#{tsvector} @@ #{tsquery}"))
end
Expand Down
2 changes: 2 additions & 0 deletions test/models/team_2_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,7 @@ def setup
assert_equal 2, t.filtered_fact_checks(text: 'Foo Bar').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
# Explainer
create_explainer title: 'Some Other Test', team: t
create_explainer title: 'Bar Bravo Foo Test', team: t
Expand All @@ -1549,5 +1550,6 @@ def setup
assert_equal 2, t.filtered_explainers(text: 'Foo Bar').count
assert_equal 1, t.filtered_explainers(text: 'Foo Bar Bravo').count
assert_equal 1, t.filtered_explainers(text: 'Foo Bar Alpha').count
assert_equal 0, t.filtered_fact_checks(text: 'Foo Bar Delta').count
end
end

0 comments on commit 0aef3e9

Please sign in to comment.