Contains now works for internalSearch array type
This commit is contained in:
parent
ff18e8c1c7
commit
6a1867939c
|
@ -35,7 +35,7 @@ export const OperatorOptions = {
|
||||||
label: "Less than",
|
label: "Less than",
|
||||||
},
|
},
|
||||||
Contains: {
|
Contains: {
|
||||||
value: "equal",
|
value: "contains",
|
||||||
label: "Contains",
|
label: "Contains",
|
||||||
},
|
},
|
||||||
NotContains: {
|
NotContains: {
|
||||||
|
|
|
@ -19,6 +19,7 @@ class QueryBuilder {
|
||||||
empty: {},
|
empty: {},
|
||||||
notEmpty: {},
|
notEmpty: {},
|
||||||
oneOf: {},
|
oneOf: {},
|
||||||
|
contains: {},
|
||||||
...base,
|
...base,
|
||||||
}
|
}
|
||||||
this.limit = 50
|
this.limit = 50
|
||||||
|
@ -119,6 +120,11 @@ class QueryBuilder {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addContains(key, value) {
|
||||||
|
this.query.contains[key] = value
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preprocesses a value before going into a lucene search.
|
* Preprocesses a value before going into a lucene search.
|
||||||
* Transforms strings to lowercase and wraps strings and bools in quotes.
|
* Transforms strings to lowercase and wraps strings and bools in quotes.
|
||||||
|
@ -164,6 +170,31 @@ class QueryBuilder {
|
||||||
return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`
|
return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const contains = (key, value) => {
|
||||||
|
if (!value && value !== 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return `${key}:${builder.preprocess(value, { escape: true })}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const oneOf = (key, value) => {
|
||||||
|
if (!Array.isArray(value)) {
|
||||||
|
if (typeof value === "string") {
|
||||||
|
value = value.split(",")
|
||||||
|
} else {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let orStatement = `${builder.preprocess(value[0], allPreProcessingOpts)}`
|
||||||
|
for (let i = 1; i < value.length; i++) {
|
||||||
|
orStatement += ` OR ${builder.preprocess(
|
||||||
|
value[i],
|
||||||
|
allPreProcessingOpts
|
||||||
|
)}`
|
||||||
|
}
|
||||||
|
return `${key}:(${orStatement})`
|
||||||
|
}
|
||||||
|
|
||||||
function build(structure, queryFn) {
|
function build(structure, queryFn) {
|
||||||
for (let [key, value] of Object.entries(structure)) {
|
for (let [key, value] of Object.entries(structure)) {
|
||||||
key = builder.preprocess(key.replace(/ /g, "_"), {
|
key = builder.preprocess(key.replace(/ /g, "_"), {
|
||||||
|
@ -239,26 +270,10 @@ class QueryBuilder {
|
||||||
build(this.query.notEmpty, key => `${key}:["" TO *]`)
|
build(this.query.notEmpty, key => `${key}:["" TO *]`)
|
||||||
}
|
}
|
||||||
if (this.query.oneOf) {
|
if (this.query.oneOf) {
|
||||||
build(this.query.oneOf, (key, value) => {
|
build(this.query.oneOf, oneOf)
|
||||||
if (!Array.isArray(value)) {
|
}
|
||||||
if (typeof value === "string") {
|
if (this.query.contains) {
|
||||||
value = value.split(",")
|
build(this.query.contains, contains)
|
||||||
} else {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let orStatement = `${builder.preprocess(
|
|
||||||
value[0],
|
|
||||||
allPreProcessingOpts
|
|
||||||
)}`
|
|
||||||
for (let i = 1; i < value.length; i++) {
|
|
||||||
orStatement += ` OR ${builder.preprocess(
|
|
||||||
value[i],
|
|
||||||
allPreProcessingOpts
|
|
||||||
)}`
|
|
||||||
}
|
|
||||||
return `${key}:(${orStatement})`
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
// make sure table ID is always added as an AND
|
// make sure table ID is always added as an AND
|
||||||
if (tableId) {
|
if (tableId) {
|
||||||
|
|
Loading…
Reference in New Issue