Support NOT lucene queries and escape whitespace

This commit is contained in:
Andrew Kingston 2021-04-29 14:55:51 +01:00
parent 35f9dcf3f6
commit 3a601d76ce
1 changed files with 10 additions and 1 deletions

View File

@ -34,6 +34,7 @@ class QueryBuilder {
fuzzy: {}, fuzzy: {},
range: {}, range: {},
equal: {}, equal: {},
notEqual: {},
...base, ...base,
} }
this.limit = 50 this.limit = 50
@ -73,6 +74,11 @@ class QueryBuilder {
return this return this
} }
addNotEqual(key, value) {
this.query.notEqual[key] = value
return this
}
addTable(tableId) { addTable(tableId) {
this.query.equal.tableId = tableId this.query.equal.tableId = tableId
return this return this
@ -85,7 +91,7 @@ class QueryBuilder {
if (output.length !== 0) { if (output.length !== 0) {
output += " AND " output += " AND "
} }
output += queryFn(key, value) output += queryFn(key, value).replace(/ /, "\\ ")
} }
} }
@ -104,6 +110,9 @@ class QueryBuilder {
if (this.query.equal) { if (this.query.equal) {
build(this.query.equal, (key, value) => `${key}:${value}`) build(this.query.equal, (key, value) => `${key}:${value}`)
} }
if (this.query.notEqual) {
build(this.query.notEqual, (key, value) => `!${key}:${value}`)
}
if (rawQuery) { if (rawQuery) {
output = output.length === 0 ? rawQuery : `&${rawQuery}` output = output.length === 0 ? rawQuery : `&${rawQuery}`
} }