1
0
Fork 0
mirror of synced 2024-08-23 05:51:29 +12:00

Respond to PR feedback.

This commit is contained in:
Sam Rose 2024-05-07 10:38:47 +01:00
parent ae281c3e7a
commit 32bd505ef9
No known key found for this signature in database

View file

@ -12,6 +12,14 @@ import { dataFilters } from "@budibase/shared-core"
export const removeKeyNumbering = dataFilters.removeKeyNumbering
function isEmpty(value: any) {
return (
value == null ||
value === "" ||
(Array.isArray(value) && value.length === 0)
)
}
/**
* Class to build lucene query URLs.
* Optionally takes a base lucene query object.
@ -282,14 +290,14 @@ export class QueryBuilder<T> {
}
const equal = (key: string, value: any) => {
if (value === null || value === undefined) {
if (isEmpty(value)) {
return null
}
return `${key}:${builder.preprocess(value, allPreProcessingOpts)}`
}
const contains = (key: string, value: any, mode = "AND") => {
if (!value || (Array.isArray(value) && value.length === 0)) {
if (isEmpty(value)) {
return null
}
if (!Array.isArray(value)) {
@ -305,7 +313,7 @@ export class QueryBuilder<T> {
}
const fuzzy = (key: string, value: any) => {
if (!value) {
if (isEmpty(value)) {
return null
}
value = builder.preprocess(value, {
@ -327,7 +335,7 @@ export class QueryBuilder<T> {
}
const oneOf = (key: string, value: any) => {
if (!value) {
if (isEmpty(value)) {
return `*:*`
}
if (!Array.isArray(value)) {
@ -385,7 +393,7 @@ export class QueryBuilder<T> {
// Construct the actual lucene search query string from JSON structure
if (this.#query.string) {
build(this.#query.string, (key: string, value: any) => {
if (!value) {
if (isEmpty(value)) {
return null
}
value = builder.preprocess(value, {
@ -398,7 +406,7 @@ export class QueryBuilder<T> {
}
if (this.#query.range) {
build(this.#query.range, (key: string, value: any) => {
if (!value) {
if (isEmpty(value)) {
return null
}
if (value.low == null || value.low === "") {
@ -420,7 +428,7 @@ export class QueryBuilder<T> {
}
if (this.#query.notEqual) {
build(this.#query.notEqual, (key: string, value: any) => {
if (value === null || value === undefined) {
if (isEmpty(value)) {
return null
}
if (typeof value === "boolean") {