Pass Best Bet keywords through "filter_query" method#29
Open
dsteelma-umd wants to merge 1 commit intoNCSU-Libraries:masterfrom
Open
Pass Best Bet keywords through "filter_query" method#29dsteelma-umd wants to merge 1 commit intoNCSU-Libraries:masterfrom
dsteelma-umd wants to merge 1 commit intoNCSU-Libraries:masterfrom
Conversation
When loading the Best Bet keywords, pass them through the "filter_query" method in the "QuickSearch::QueryFilter" concern, so that they will be matched with a query term passed through the same method. This takes care of things like a dash (hyphen) being removed from the query term. 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. It is not clear if this is the best way to accomplish this, but it does appear to work. Modified "test/dummy/config/best_bets.yml" to add a new Best Bet entry with a keyword including a dash for use in "test/integration/best_bets_initializer_test.rb" Added "xhr_search" route to "test/dummy/config/routes.rb" so it would be available as a "*_path" helper in the test.
dsteelma-umd
added a commit
to umd-lib/quick_search
that referenced
this pull request
May 31, 2019
Updated the code to match a few editing changes made in the NCSU pull request (NCSU-Libraries#29) https://issues.umd.edu/browse/LIBSEARCH-155
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.