[#2179] Tolerate spurious spaces around search terms
This commit is contained in:
parent
1134877d59
commit
cef0eafb1a
2 changed files with 10 additions and 3 deletions
|
@ -39,9 +39,10 @@ class DossierSearchService
|
|||
end
|
||||
|
||||
def self.to_tsquery(search_terms)
|
||||
search_terms.gsub(/['?\\:&|!]/, "") # drop disallowed characters
|
||||
.split(/\s+/) # split words
|
||||
.map { |x| "#{x}:*" } # enable prefix matching
|
||||
search_terms.strip
|
||||
.gsub(/['?\\:&|!]/, "") # drop disallowed characters
|
||||
.split(/\s+/) # split words
|
||||
.map { |x| "#{x}:*" } # enable prefix matching
|
||||
.join(" & ")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -73,6 +73,12 @@ describe DossierSearchService do
|
|||
it { expect(subject.size).to eq(2) }
|
||||
end
|
||||
|
||||
describe 'search terms surrounded with spurious spaces' do
|
||||
let(:terms) { ' OCTO ' }
|
||||
|
||||
it { expect(subject.size).to eq(2) }
|
||||
end
|
||||
|
||||
describe 'search on multiple fields' do
|
||||
let(:terms) { 'octo plop' }
|
||||
|
||||
|
|
Loading…
Reference in a new issue