Skip to content

Commit

Permalink
Add exception notifications when wildcard searches fail
Browse files Browse the repository at this point in the history
It's unclear if this is a big problem or if we could mitigate failed
wildcard searches by adjusting Xapian's max expansion limit.

This is also changes the  Rails logging level to warn.
  • Loading branch information
gbp committed Feb 16, 2021
1 parent 0d3fa47 commit 0e0fe30
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/typeahead_search.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class TypeaheadSearch

include ConfigHelper

attr_accessor :query, :model, :page, :per_page, :wildcard, :run_search

def initialize(query, opts = {})
Expand All @@ -22,7 +24,12 @@ def xapian_search
xapian_search = run_query
rescue ActsAsXapian::UnhandledRuntimeError => e
# Wildcard expands to too many terms
Rails.logger.info "Wildcard query '#{query}' caused: #{e.message.force_encoding('UTF-8')}"
Rails.logger.warn "Wildcard query '#{query}' caused: #{e.message.force_encoding('UTF-8')}"

if send_exception_notifications?
ExceptionNotifier.notify_exception(e, env: options)
end

@wildcard = false
xapian_search = run_query
end
Expand Down
6 changes: 6 additions & 0 deletions spec/lib/typeahead_search_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ def search_bodies(xapian_search)
)
end

it 'sends a notification' do
TypeaheadSearch.new('dog', options).xapian_search
mail = ActionMailer::Base.deliveries.first
expect(mail.subject).to match(/dog\* expands to more than 1 term/)
end

end
end
end
Expand Down

0 comments on commit 0e0fe30

Please sign in to comment.