1
0
Fork 0
mirror of synced 2024-07-03 05:20:32 +12:00

Add not contains option to lucene query builder

This commit is contained in:
Peter Clement 2021-08-25 14:05:00 +01:00
parent f000d44e39
commit 05568295b5
4 changed files with 27 additions and 5 deletions

View file

@ -86,7 +86,6 @@
let arr = field.constraints.inclusion
let newArr = []
newArr.push(arr)
console.log(newArr)
field.constraints.inclusion = newArr
}
tables.saveField({

View file

@ -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") {

View file

@ -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: [],
}

View file

@ -11,7 +11,8 @@ export const buildLuceneQuery = filter => {
notEqual: {},
empty: {},
notEmpty: {},
contains: {}
contains: {},
notContains: {},
}
if (Array.isArray(filter)) {
filter.forEach(expression => {