[#2179] Tolerate spurious spaces around search terms

This commit is contained in:
Frederic Merizen 2018-08-22 18:36:24 +02:00
parent 1134877d59
commit cef0eafb1a
2 changed files with 10 additions and 3 deletions

View file

@ -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

View file

@ -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' }