Skip to content

Commit

Permalink
fix(es): fixes invalid queries when non-word termes are surrounded by…
Browse files Browse the repository at this point in the history
… spaces
  • Loading branch information
naholyr committed Sep 7, 2017
1 parent bcdd636 commit 171161a
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion server/lib/elasticsearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ client.q.forSuggestions = ({ type, query, size = config.elasticsearch.defaultSiz
// TODO support complex queries with quotes 'n co
query.split(/\s+/)
.map(s => s.trim())
.filter(s => s.length > 0)
// Remove terms without actual words (cf. https://stackoverflow.com/questions/5436824/matching-accented-characters-with-javascript-regexes#comment22195688_11550799)
.filter(s => s.length > 0 && s.match(/[0-9a-zA-Z\u00C0-\u017F]/))
// Duplicate each term to create a query based on prefixes + fuzzy matching
.reduce((terms, term) => term.match(/(\*|\~.+?)$/)
? terms.concat([term]) // already an advanced term, don't modify
Expand Down

0 comments on commit 171161a

Please sign in to comment.