Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Best Bet keywords through "filter_query" method #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dsteelma-umd
Copy link
Contributor

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.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant