Skip to content

Commit

Permalink
Treat unstemmed words as normal search terms.
Browse files Browse the repository at this point in the history
has_normal_search_terms? was only returning true if the query had a
stemmed search term in it, such as Zterm. Searching for a word with
capital letters, such as NHS, translates to an unstemmed query term
“nhs”. This would not match and the search would default to sorting
by newest rather than relevance. Unstemmed query terms should still
match as a normal search term, not a prefixed one.
  • Loading branch information
dracos committed Jan 23, 2024
1 parent 1446f26 commit f54e0c5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
Porteous)
* Don't show users that have closed their account or been banned on leaderboards
(Chris Mytton)
* Treat unstemmed words as normal search terms. (Matthew Somerville)


## Upgrade Notes
Expand Down
7 changes: 3 additions & 4 deletions lib/acts_as_xapian/acts_as_xapian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,9 @@ def has_normal_search_terms?
#x = ''
query.terms.each do |t|
term = t.term
#x = x + term.to_yaml + term.size.to_s + term[0..0] + "*"
if term.size >= 2 && term[0..0] == 'Z'
# normal terms begin Z (for stemmed), then have no capital letter prefix
ret = true if term[1..1] == term[1..1].downcase
# normal terms begin Z (for stemmed), or have no capital letter prefix
if term[0..0] == 'Z' || term[0..0] == term[0..0].downcase

Check warning on line 415 in lib/acts_as_xapian/acts_as_xapian.rb

View workflow job for this annotation

GitHub Actions / build

[rubocop] reported by reviewdog 🐶 Favor modifier `if` usage when having a single-line body. Another good alternative is the usage of control flow `&&`/`||`. (https://rubystyle.guide#if-as-a-modifier) Raw Output: lib/acts_as_xapian/acts_as_xapian.rb:415:9: C: Style/IfUnlessModifier: Favor modifier `if` usage when having a single-line body. Another good alternative is the usage of control flow `&&`/`||`. (https://rubystyle.guide#if-as-a-modifier)
ret = true
end
end
ret
Expand Down

0 comments on commit f54e0c5

Please sign in to comment.