pr comments
This commit is contained in:
parent
b232371eff
commit
eb00ce401f
|
@ -12,6 +12,7 @@ import {
|
||||||
import dayjs from "dayjs"
|
import dayjs from "dayjs"
|
||||||
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
|
import { OperatorOptions, SqlNumberTypeRangeMap } from "./constants"
|
||||||
import { deepGet } from "./helpers"
|
import { deepGet } from "./helpers"
|
||||||
|
import test from "node:test"
|
||||||
|
|
||||||
const HBS_REGEX = /{{([^{].*?)}}/g
|
const HBS_REGEX = /{{([^{].*?)}}/g
|
||||||
|
|
||||||
|
@ -359,6 +360,7 @@ export const runLuceneQuery = (docs: any[], query?: SearchQuery) => {
|
||||||
const oneOf = match(
|
const oneOf = match(
|
||||||
SearchQueryOperators.ONE_OF,
|
SearchQueryOperators.ONE_OF,
|
||||||
(docValue: any, testValue: any) => {
|
(docValue: any, testValue: any) => {
|
||||||
|
console.log(testValue)
|
||||||
if (typeof testValue === "string") {
|
if (typeof testValue === "string") {
|
||||||
testValue = testValue.split(",")
|
testValue = testValue.split(",")
|
||||||
if (typeof docValue === "number") {
|
if (typeof docValue === "number") {
|
||||||
|
@ -410,13 +412,13 @@ export const runLuceneQuery = (docs: any[], query?: SearchQuery) => {
|
||||||
.filter(
|
.filter(
|
||||||
([key, value]: [string, any]) =>
|
([key, value]: [string, any]) =>
|
||||||
!["allOr", "onEmptyFilter"].includes(key) &&
|
!["allOr", "onEmptyFilter"].includes(key) &&
|
||||||
|
value &&
|
||||||
Object.keys(value as Record<string, any>).length > 0
|
Object.keys(value as Record<string, any>).length > 0
|
||||||
)
|
)
|
||||||
.map(([key]) => key as any)
|
.map(([key]) => key as any)
|
||||||
|
|
||||||
const results: boolean[] = activeFilterKeys.map(filterKey => {
|
const results: boolean[] = activeFilterKeys.map(filterKey => {
|
||||||
const filterFunction = filterFunctions[filterKey]
|
return filterFunctions[filterKey]?.(doc) ?? false
|
||||||
return filterFunction ? filterFunction(doc) : true
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (query!.allOr) {
|
if (query!.allOr) {
|
||||||
|
@ -425,7 +427,6 @@ export const runLuceneQuery = (docs: any[], query?: SearchQuery) => {
|
||||||
return results.every(result => result === true)
|
return results.every(result => result === true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return docs.filter(docMatch)
|
return docs.filter(docMatch)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -240,6 +240,16 @@ describe("runLuceneQuery", () => {
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([])
|
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should handle when a value is null or undefined", () => {
|
||||||
|
const query = buildQuery({
|
||||||
|
allOr: true,
|
||||||
|
equal: { order_status: null },
|
||||||
|
oneOf: { label: ["FRAGILE"] },
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([2])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("buildLuceneQuery", () => {
|
describe("buildLuceneQuery", () => {
|
||||||
|
|
Loading…
Reference in New Issue