Add not contains option to lucene query builder
This commit is contained in:
parent
d55218e813
commit
04ce0abd46
|
@ -86,7 +86,6 @@
|
|||
let arr = field.constraints.inclusion
|
||||
let newArr = []
|
||||
newArr.push(arr)
|
||||
console.log(newArr)
|
||||
field.constraints.inclusion = newArr
|
||||
}
|
||||
tables.saveField({
|
||||
|
|
|
@ -35,7 +35,10 @@ export const OperatorOptions = {
|
|||
value: "contains",
|
||||
label: "Contains",
|
||||
},
|
||||
|
||||
NotContains: {
|
||||
value: "notContains",
|
||||
label: "Does Not Contain",
|
||||
}
|
||||
}
|
||||
|
||||
export const getValidOperatorsForType = type => {
|
||||
|
@ -61,7 +64,7 @@ export const getValidOperatorsForType = type => {
|
|||
} else if (type === "options") {
|
||||
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty]
|
||||
} else if (type === "array") {
|
||||
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.Contains]
|
||||
return [Op.Contains, Op.NotContains]
|
||||
} else if (type === "boolean") {
|
||||
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty]
|
||||
} else if (type === "longform") {
|
||||
|
|
|
@ -18,6 +18,7 @@ class QueryBuilder {
|
|||
empty: {},
|
||||
notEmpty: {},
|
||||
contains: {},
|
||||
notContains: {},
|
||||
...base,
|
||||
}
|
||||
this.limit = 50
|
||||
|
@ -110,6 +111,10 @@ class QueryBuilder {
|
|||
return this
|
||||
}
|
||||
|
||||
addNotContains(key, value) {
|
||||
this.query.notContains[key] = value
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
* Preprocesses a value before going into a lucene search.
|
||||
|
@ -232,6 +237,20 @@ class QueryBuilder {
|
|||
|
||||
}
|
||||
|
||||
if (this.query.notContains) {
|
||||
build(this.query.notContains, (key, value) => {
|
||||
if (!value) {
|
||||
return null
|
||||
}
|
||||
let opts = []
|
||||
value.forEach(val => opts.push(`!${key}.${val}:${builder.preprocess(val, allPreProcessingOpts)}`))
|
||||
const joined = opts.join(' AND ')
|
||||
return joined
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
return query
|
||||
}
|
||||
|
||||
|
@ -273,7 +292,7 @@ const runQuery = async (url, body) => {
|
|||
method: "POST",
|
||||
})
|
||||
const json = await response.json()
|
||||
console.log(json)
|
||||
|
||||
let output = {
|
||||
rows: [],
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ export const buildLuceneQuery = filter => {
|
|||
notEqual: {},
|
||||
empty: {},
|
||||
notEmpty: {},
|
||||
contains: {}
|
||||
contains: {},
|
||||
notContains: {},
|
||||
}
|
||||
if (Array.isArray(filter)) {
|
||||
filter.forEach(expression => {
|
||||
|
|
Loading…
Reference in New Issue