Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions app/models/filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ def cards
result = result.where(cards: { created_at: creation_window }) if creation_window
result = result.closed_at_window(closure_window) if closure_window
result = result.closed_by(closers) if closers.present?
result = terms.reduce(result) do |result, term|
result.mentioning(term, user: creator)
end

result = result.mentioning(combined_fts_query, user: creator) if terms.present?
result.distinct
end
end

def combined_fts_query
terms.map { |term| sanitize_fts_term(term) }.join(' AND ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will the AND and the sanitization logic work for MySQL FTS too?

cc @djmb in case he has insight here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to what AI said, it will not work in MySQL FTS and should be handled seprately

end

def sanitize_fts_term(term)
term.gsub('"', '""').then { |t| "\"#{t}\"*" }
end

def empty?
self.class.normalize_params(as_params).blank?
end
Expand Down
9 changes: 7 additions & 2 deletions test/controllers/cards_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end

test "filtered index" do
get cards_path(filters(:jz_assignments).as_params.merge(term: "haggis"))
test "filtered index with single term" do
get cards_path(filters(:jz_assignments).as_params.merge(terms: ["haggis"]))
assert_response :success
end

test "filtered index with several terms" do
get cards_path(filters(:jz_assignments).as_params.merge(terms: ["haggis", "other"]))
assert_response :success
end

Expand Down