forked from joeybaker/lucene-escape-query
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (27 loc) · 772 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
// special characters via http://lucene.apache.org/core/7_6_0/queryparser/org/apache/lucene/queryparser/classic/package-summary.html#package.description Special Characters
exports.escape = function escape(str){
return [].map.call(str, function escapeSpecialCharacter(char){
if (char === '+'
|| char === '-'
|| char === '&'
|| char === '|'
|| char === '!'
|| char === '('
|| char === ')'
|| char === '{'
|| char === '}'
|| char === '['
|| char === ']'
|| char === '^'
|| char === '"'
|| char === '~'
|| char === '*'
|| char === '?'
|| char === ':'
|| char === '\\'
|| char === '/'
) return '\\' + char
else return char
}).join('')
}