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 arr = field.constraints.inclusion
|
||||||
let newArr = []
|
let newArr = []
|
||||||
newArr.push(arr)
|
newArr.push(arr)
|
||||||
console.log(newArr)
|
|
||||||
field.constraints.inclusion = newArr
|
field.constraints.inclusion = newArr
|
||||||
}
|
}
|
||||||
tables.saveField({
|
tables.saveField({
|
||||||
|
|
|
@ -35,7 +35,10 @@ export const OperatorOptions = {
|
||||||
value: "contains",
|
value: "contains",
|
||||||
label: "Contains",
|
label: "Contains",
|
||||||
},
|
},
|
||||||
|
NotContains: {
|
||||||
|
value: "notContains",
|
||||||
|
label: "Does Not Contain",
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getValidOperatorsForType = type => {
|
export const getValidOperatorsForType = type => {
|
||||||
|
@ -61,7 +64,7 @@ export const getValidOperatorsForType = type => {
|
||||||
} else if (type === "options") {
|
} else if (type === "options") {
|
||||||
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty]
|
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty]
|
||||||
} else if (type === "array") {
|
} else if (type === "array") {
|
||||||
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty, Op.Contains]
|
return [Op.Contains, Op.NotContains]
|
||||||
} else if (type === "boolean") {
|
} else if (type === "boolean") {
|
||||||
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty]
|
return [Op.Equals, Op.NotEquals, Op.Empty, Op.NotEmpty]
|
||||||
} else if (type === "longform") {
|
} else if (type === "longform") {
|
||||||
|
|
|
@ -18,6 +18,7 @@ class QueryBuilder {
|
||||||
empty: {},
|
empty: {},
|
||||||
notEmpty: {},
|
notEmpty: {},
|
||||||
contains: {},
|
contains: {},
|
||||||
|
notContains: {},
|
||||||
...base,
|
...base,
|
||||||
}
|
}
|
||||||
this.limit = 50
|
this.limit = 50
|
||||||
|
@ -110,6 +111,10 @@ class QueryBuilder {
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addNotContains(key, value) {
|
||||||
|
this.query.notContains[key] = value
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Preprocesses a value before going into a lucene search.
|
* 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
|
return query
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,7 +292,7 @@ const runQuery = async (url, body) => {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
})
|
})
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
console.log(json)
|
|
||||||
let output = {
|
let output = {
|
||||||
rows: [],
|
rows: [],
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ export const buildLuceneQuery = filter => {
|
||||||
notEqual: {},
|
notEqual: {},
|
||||||
empty: {},
|
empty: {},
|
||||||
notEmpty: {},
|
notEmpty: {},
|
||||||
contains: {}
|
contains: {},
|
||||||
|
notContains: {},
|
||||||
}
|
}
|
||||||
if (Array.isArray(filter)) {
|
if (Array.isArray(filter)) {
|
||||||
filter.forEach(expression => {
|
filter.forEach(expression => {
|
||||||
|
|
Loading…
Reference in New Issue