Pass Best Bet keywords through "filter_query" method #29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Query terms entered by the user are passed through the "filter_query" method in the "QuickSearch::QueryFilter" concern to remove problematic characters such as dashes/asterisks/exclamation points, as well as converting the query term to lower-case.
This modification changes the Best Bet initializer to pass the keywords through the same "filter_query" method. This ensures that keywords with problematic characters are treated in the same way as query terms. Without this change, any keyword with a dash/asterisk/exclamation point, or upper-case letter would never be matched.
We have encountered this problem in practice, when attempting to use ISSN numbers (which include dashes) as keywords for serial publications.
Implementation Notes
The implementation modifies the "lib/quick_search/engine.rb" class to pass each Best Bet keyword from the "config/best_bets.yml" file through the "filter_query" method in the "QuickSearch::QueryFilter" concern.
The implementation was somewhat complicated by the fact that the "filter_query" method is a private method on a Rails concern. This was handled by creating a helper class in the initializer that delegates to the concern. Not sure if this was really the "Ruby way" to do this, but it does appear to work -- any suggestions for improvement are welcome.
For unit testing, modified "test/dummy/config/best_bets.yml" to add a new Best Bet entry with a keyword including a dash for use by "test/integration/best_bets_initializer_test.rb"
Also added the "xhr_search" route to "test/dummy/config/routes.rb" so it would be available as a "*_path" helper in the test.