1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

Internal table support for oneOf

This commit is contained in:
Mel O'Hagan 2022-06-24 21:15:41 +01:00
parent 36a59632c4
commit 40a2e95185

View file

@ -17,6 +17,7 @@ class QueryBuilder {
notEqual: {},
empty: {},
notEmpty: {},
oneOf: {},
...base,
}
this.limit = 50
@ -112,6 +113,11 @@ class QueryBuilder {
return this
}
addOneOf(key, value) {
this.query.oneOf[key] = value
return this
}
/**
* Preprocesses a value before going into a lucene search.
* Transforms strings to lowercase and wraps strings and bools in quotes.
@ -220,6 +226,28 @@ class QueryBuilder {
if (this.query.notEmpty) {
build(this.query.notEmpty, key => `${key}:["" TO *]`)
}
if (this.query.oneOf) {
build(this.query.oneOf, (key, value) => {
if (!Array.isArray(value)) {
if (typeof value === "string") {
value = value.replace(/(\s)*,(\s)*/g, ",").split(",")
} else {
return ""
}
}
const preprocess = item => {
return builder.preprocess(item, {
escape: true,
lowercase: true,
})
}
let orStatement = `"${preprocess(value[0])}"`
for (let i = 1; i < value.length; i++) {
orStatement += ` OR "${preprocess(value[i])}"`
}
return `${key}:(${orStatement})`
})
}
return query
}