Skip to content

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