Skip to content

Commit

Permalink
Merge branch 'unstemmed-are-normal-search-terms' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Apr 9, 2024
2 parents 44a7e4e + 4bb708c commit 3c8f5b6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
1 change: 1 addition & 0 deletions doc/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Highlighted Features

* Treat unstemmed words as normal search terms. (Matthew Somerville)
* Update `/alaveteli_pro` base path to `/pro` (Alexander Griffen, Graeme
Porteous)
* Change use of `/alaveteli_pro/info_requests/{request}` to instead appear as
Expand Down
7 changes: 2 additions & 5 deletions lib/acts_as_xapian/acts_as_xapian.rb
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,8 @@ 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
end
# normal terms begin Z (for stemmed), or have no capital letter prefix
ret = true if term[0..0] == 'Z' || term[0..0] == term[0..0].downcase
end
ret
end
Expand Down
24 changes: 24 additions & 0 deletions spec/lib/acts_as_xapian_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,28 @@
expect(s.spelling_correction).to eq("bôbby")
end
end

describe '#has_normal_search_terms?' do
it 'return false for prefixed search queries' do
search = ActsAsXapian::Search.new([PublicBody], 'tag:foo', limit: 1)
expect(search.has_normal_search_terms?).to eq(false)
end

it 'return true for prefixed search queries with normal search term' do
search = ActsAsXapian::Search.new([PublicBody], 'tag:foo nhs', limit: 1)
expect(search.has_normal_search_terms?).to eq(true)
end

it 'return true for normal search term' do
search = ActsAsXapian::Search.new([PublicBody], 'nhs', limit: 1)
expect(search.has_normal_search_terms?).to eq(true)
end

it 'treats unstemmed words as normal search terms' do
search = ActsAsXapian::Search.new([PublicBody], 'NHS', limit: 1)
expect(search.has_normal_search_terms?).to eq(true)
search = ActsAsXapian::Search.new([PublicBody], 'tag:foo NHS', limit: 1)
expect(search.has_normal_search_terms?).to eq(true)
end
end
end

0 comments on commit 3c8f5b6

Please sign in to comment.