[#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
|
end
|
||||||
|
|
||||||
def self.to_tsquery(search_terms)
|
def self.to_tsquery(search_terms)
|
||||||
search_terms.gsub(/['?\\:&|!]/, "") # drop disallowed characters
|
search_terms.strip
|
||||||
.split(/\s+/) # split words
|
.gsub(/['?\\:&|!]/, "") # drop disallowed characters
|
||||||
.map { |x| "#{x}:*" } # enable prefix matching
|
.split(/\s+/) # split words
|
||||||
|
.map { |x| "#{x}:*" } # enable prefix matching
|
||||||
.join(" & ")
|
.join(" & ")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -73,6 +73,12 @@ describe DossierSearchService do
|
||||||
it { expect(subject.size).to eq(2) }
|
it { expect(subject.size).to eq(2) }
|
||||||
end
|
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
|
describe 'search on multiple fields' do
|
||||||
let(:terms) { 'octo plop' }
|
let(:terms) { 'octo plop' }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue