Remove the word 'lucene' from runLuceneQuery and buildLuceneQuery.
This commit is contained in:
parent
7761c15172
commit
bc8791e91e
|
@ -343,7 +343,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveFilters(key) {
|
function saveFilters(key) {
|
||||||
const filters = LuceneUtils.buildLuceneQuery(tempFilters)
|
const filters = LuceneUtils.buildQuery(tempFilters)
|
||||||
const defKey = `${key}-def`
|
const defKey = `${key}-def`
|
||||||
onChange({ detail: filters }, key)
|
onChange({ detail: filters }, key)
|
||||||
// need to store the builder definition in the automation
|
// need to store the builder definition in the automation
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
exportFormat = Array.isArray(options) ? options[0]?.key : []
|
exportFormat = Array.isArray(options) ? options[0]?.key : []
|
||||||
}
|
}
|
||||||
|
|
||||||
$: luceneFilter = LuceneUtils.buildLuceneQuery(appliedFilters)
|
$: luceneFilter = LuceneUtils.buildQuery(appliedFilters)
|
||||||
$: exportOpDisplay = buildExportOpDisplay(
|
$: exportOpDisplay = buildExportOpDisplay(
|
||||||
sorting,
|
sorting,
|
||||||
filterDisplay,
|
filterDisplay,
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
|
|
||||||
// We need to manage our lucene query manually as we want to allow components
|
// We need to manage our lucene query manually as we want to allow components
|
||||||
// to extend it
|
// to extend it
|
||||||
$: defaultQuery = LuceneUtils.buildLuceneQuery(filter)
|
$: defaultQuery = LuceneUtils.buildQuery(filter)
|
||||||
$: query = extendQuery(defaultQuery, queryExtensions)
|
$: query = extendQuery(defaultQuery, queryExtensions)
|
||||||
$: fetch = createFetch(dataSource)
|
$: fetch = createFetch(dataSource)
|
||||||
$: fetch.update({
|
$: fetch.update({
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
// Add query extension to data provider
|
// Add query extension to data provider
|
||||||
$: {
|
$: {
|
||||||
if (filters?.length) {
|
if (filters?.length) {
|
||||||
const queryExtension = LuceneUtils.buildLuceneQuery(filters)
|
const queryExtension = LuceneUtils.buildQuery(filters)
|
||||||
addExtension?.($component.id, queryExtension)
|
addExtension?.($component.id, queryExtension)
|
||||||
} else {
|
} else {
|
||||||
removeExtension?.($component.id)
|
removeExtension?.($component.id)
|
||||||
|
|
|
@ -33,8 +33,8 @@ export const getActiveConditions = conditions => {
|
||||||
value: condition.referenceValue,
|
value: condition.referenceValue,
|
||||||
}
|
}
|
||||||
|
|
||||||
const query = LuceneUtils.buildLuceneQuery([luceneCondition])
|
const query = LuceneUtils.buildQuery([luceneCondition])
|
||||||
const result = LuceneUtils.runLuceneQuery([luceneCondition], query)
|
const result = LuceneUtils.runQuery([luceneCondition], query)
|
||||||
return result.length > 0
|
return result.length > 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { cloneDeep } from "lodash/fp"
|
||||||
import { LuceneUtils } from "../utils"
|
import { LuceneUtils } from "../utils"
|
||||||
import { convertJSONSchemaToTableSchema } from "../utils/json"
|
import { convertJSONSchemaToTableSchema } from "../utils/json"
|
||||||
|
|
||||||
const { buildLuceneQuery, luceneLimit, runLuceneQuery, luceneSort } =
|
const { buildQuery, luceneLimit, runQuery, luceneSort } = LuceneUtils
|
||||||
LuceneUtils
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parent class which handles the implementation of fetching data from an
|
* Parent class which handles the implementation of fetching data from an
|
||||||
|
@ -180,7 +179,7 @@ export default class DataFetch {
|
||||||
// Build the lucene query
|
// Build the lucene query
|
||||||
let query = this.options.query
|
let query = this.options.query
|
||||||
if (!query) {
|
if (!query) {
|
||||||
query = buildLuceneQuery(filter)
|
query = buildQuery(filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update store
|
// Update store
|
||||||
|
@ -229,7 +228,7 @@ export default class DataFetch {
|
||||||
|
|
||||||
// If we don't support searching, do a client search
|
// If we don't support searching, do a client search
|
||||||
if (!this.features.supportsSearch && clientSideSearching) {
|
if (!this.features.supportsSearch && clientSideSearching) {
|
||||||
rows = runLuceneQuery(rows, query)
|
rows = runQuery(rows, query)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we don't support sorting, do a client-side sort
|
// If we don't support sorting, do a client-side sort
|
||||||
|
|
|
@ -31,7 +31,7 @@ export async function searchView(
|
||||||
// Enrich saved query with ephemeral query params.
|
// Enrich saved query with ephemeral query params.
|
||||||
// We prevent searching on any fields that are saved as part of the query, as
|
// We prevent searching on any fields that are saved as part of the query, as
|
||||||
// that could let users find rows they should not be allowed to access.
|
// that could let users find rows they should not be allowed to access.
|
||||||
let query = dataFilters.buildLuceneQuery(view.query || [])
|
let query = dataFilters.buildQuery(view.query || [])
|
||||||
if (body.query) {
|
if (body.query) {
|
||||||
// Extract existing fields
|
// Extract existing fields
|
||||||
const existingFields =
|
const existingFields =
|
||||||
|
|
|
@ -566,7 +566,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
|
||||||
query.filters.equal[`_${GOOGLE_SHEETS_PRIMARY_KEY}`] = id
|
query.filters.equal[`_${GOOGLE_SHEETS_PRIMARY_KEY}`] = id
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let filtered = dataFilters.runLuceneQuery(rows, query.filters)
|
let filtered = dataFilters.runQuery(rows, query.filters)
|
||||||
if (hasFilters && query.paginate) {
|
if (hasFilters && query.paginate) {
|
||||||
filtered = filtered.slice(offset, offset + limit)
|
filtered = filtered.slice(offset, offset + limit)
|
||||||
}
|
}
|
||||||
|
|
|
@ -138,10 +138,10 @@ export const removeKeyNumbering = (key: string): string => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds a lucene JSON query from the filter structure generated in the builder
|
* Builds a JSON query from the filter structure generated in the builder
|
||||||
* @param filter the builder filter structure
|
* @param filter the builder filter structure
|
||||||
*/
|
*/
|
||||||
export const buildLuceneQuery = (filter: SearchFilter[]) => {
|
export const buildQuery = (filter: SearchFilter[]) => {
|
||||||
let query: SearchFilters = {
|
let query: SearchFilters = {
|
||||||
string: {},
|
string: {},
|
||||||
fuzzy: {},
|
fuzzy: {},
|
||||||
|
@ -260,11 +260,11 @@ export const buildLuceneQuery = (filter: SearchFilter[]) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a client-side lucene search on an array of data
|
* Performs a client-side search on an array of data
|
||||||
* @param docs the data
|
* @param docs the data
|
||||||
* @param query the JSON lucene query
|
* @param query the JSON query
|
||||||
*/
|
*/
|
||||||
export const runLuceneQuery = (docs: any[], query?: SearchFilters) => {
|
export const runQuery = (docs: any[], query?: SearchFilters) => {
|
||||||
if (!docs || !Array.isArray(docs)) {
|
if (!docs || !Array.isArray(docs)) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,9 @@ import {
|
||||||
FieldType,
|
FieldType,
|
||||||
SearchFilter,
|
SearchFilter,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { buildLuceneQuery, runLuceneQuery } from "../filters"
|
import { buildQuery, runQuery } from "../filters"
|
||||||
|
|
||||||
describe("runLuceneQuery", () => {
|
describe("runQuery", () => {
|
||||||
const docs = [
|
const docs = [
|
||||||
{
|
{
|
||||||
order_id: 1,
|
order_id: 1,
|
||||||
|
@ -70,14 +70,14 @@ describe("runLuceneQuery", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
it("should return input docs if no search query is provided", () => {
|
it("should return input docs if no search query is provided", () => {
|
||||||
expect(runLuceneQuery(docs)).toBe(docs)
|
expect(runQuery(docs)).toBe(docs)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return matching rows for equal filter", () => {
|
it("should return matching rows for equal filter", () => {
|
||||||
const query = buildQuery({
|
const query = buildQuery({
|
||||||
equal: { order_status: 4 },
|
equal: { order_status: 4 },
|
||||||
})
|
})
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([1, 2])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([1, 2])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return matching row for notEqual filter", () => {
|
it("should return matching row for notEqual filter", () => {
|
||||||
|
@ -85,12 +85,12 @@ describe("runLuceneQuery", () => {
|
||||||
notEqual: { order_status: 4 },
|
notEqual: { order_status: 4 },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([3])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([3])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return starts with matching rows for fuzzy and string filters", () => {
|
it("should return starts with matching rows for fuzzy and string filters", () => {
|
||||||
expect(
|
expect(
|
||||||
runLuceneQuery(
|
runQuery(
|
||||||
docs,
|
docs,
|
||||||
buildQuery({
|
buildQuery({
|
||||||
fuzzy: { description: "sm" },
|
fuzzy: { description: "sm" },
|
||||||
|
@ -98,7 +98,7 @@ describe("runLuceneQuery", () => {
|
||||||
).map(row => row.description)
|
).map(row => row.description)
|
||||||
).toEqual(["Small box"])
|
).toEqual(["Small box"])
|
||||||
expect(
|
expect(
|
||||||
runLuceneQuery(
|
runQuery(
|
||||||
docs,
|
docs,
|
||||||
buildQuery({
|
buildQuery({
|
||||||
string: { description: "SM" },
|
string: { description: "SM" },
|
||||||
|
@ -117,7 +117,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([3])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([3])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return rows with numeric strings within a range filter", () => {
|
it("should return rows with numeric strings within a range filter", () => {
|
||||||
|
@ -129,7 +129,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([3])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([3])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return rows with ISO date strings within a range filter", () => {
|
it("should return rows with ISO date strings within a range filter", () => {
|
||||||
|
@ -142,7 +142,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([2])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([2])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return return all docs if an invalid doc value is passed into a range filter", async () => {
|
it("should return return all docs if an invalid doc value is passed into a range filter", async () => {
|
||||||
|
@ -170,7 +170,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query)).toEqual(docs)
|
expect(runQuery(docs, query)).toEqual(docs)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return rows with matches on empty filter", () => {
|
it("should return rows with matches on empty filter", () => {
|
||||||
|
@ -180,7 +180,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([1])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([1])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return rows with matches on notEmpty filter", () => {
|
it("should return rows with matches on notEmpty filter", () => {
|
||||||
|
@ -190,7 +190,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([2, 3])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([2, 3])
|
||||||
})
|
})
|
||||||
|
|
||||||
it.each([[523, 259], "523,259"])(
|
it.each([[523, 259], "523,259"])(
|
||||||
|
@ -202,7 +202,7 @@ describe("runLuceneQuery", () => {
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.customer_id)).toEqual([
|
expect(runQuery(docs, query).map(row => row.customer_id)).toEqual([
|
||||||
259, 523,
|
259, 523,
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ describe("runLuceneQuery", () => {
|
||||||
contains: { description: ["box"] },
|
contains: { description: ["box"] },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual(
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual(
|
||||||
expectedResult
|
expectedResult
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -230,7 +230,7 @@ describe("runLuceneQuery", () => {
|
||||||
oneOf: { label: ["FRAGILE"] },
|
oneOf: { label: ["FRAGILE"] },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([1, 2])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([1, 2])
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle when a value is null or undefined", () => {
|
it("should handle when a value is null or undefined", () => {
|
||||||
|
@ -240,14 +240,14 @@ describe("runLuceneQuery", () => {
|
||||||
oneOf: { label: ["FRAGILE"] },
|
oneOf: { label: ["FRAGILE"] },
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(runLuceneQuery(docs, query).map(row => row.order_id)).toEqual([2])
|
expect(runQuery(docs, query).map(row => row.order_id)).toEqual([2])
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("buildLuceneQuery", () => {
|
describe("buildQuery", () => {
|
||||||
it("should return a basic search query template if the input is not an array", () => {
|
it("should return a basic search query template if the input is not an array", () => {
|
||||||
const filter: any = "NOT_AN_ARRAY"
|
const filter: any = "NOT_AN_ARRAY"
|
||||||
expect(buildLuceneQuery(filter)).toEqual({
|
expect(buildQuery(filter)).toEqual({
|
||||||
string: {},
|
string: {},
|
||||||
fuzzy: {},
|
fuzzy: {},
|
||||||
range: {},
|
range: {},
|
||||||
|
@ -277,7 +277,7 @@ describe("buildLuceneQuery", () => {
|
||||||
value: "1000,1212,3400",
|
value: "1000,1212,3400",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(buildLuceneQuery(filter)).toEqual({
|
expect(buildQuery(filter)).toEqual({
|
||||||
string: {},
|
string: {},
|
||||||
fuzzy: {},
|
fuzzy: {},
|
||||||
range: {},
|
range: {},
|
||||||
|
@ -311,7 +311,7 @@ describe("buildLuceneQuery", () => {
|
||||||
value: "{{ list_of_customer_ids }}",
|
value: "{{ list_of_customer_ids }}",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(buildLuceneQuery(filter)).toEqual({
|
expect(buildQuery(filter)).toEqual({
|
||||||
string: {},
|
string: {},
|
||||||
fuzzy: {},
|
fuzzy: {},
|
||||||
range: {},
|
range: {},
|
||||||
|
@ -351,7 +351,7 @@ describe("buildLuceneQuery", () => {
|
||||||
value: "true",
|
value: "true",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(buildLuceneQuery(filter)).toEqual({
|
expect(buildQuery(filter)).toEqual({
|
||||||
string: {},
|
string: {},
|
||||||
fuzzy: {},
|
fuzzy: {},
|
||||||
range: {},
|
range: {},
|
||||||
|
@ -392,7 +392,7 @@ describe("buildLuceneQuery", () => {
|
||||||
value: "Large box,Heavy box,Small box",
|
value: "Large box,Heavy box,Small box",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(buildLuceneQuery(filter)).toEqual({
|
expect(buildQuery(filter)).toEqual({
|
||||||
string: {},
|
string: {},
|
||||||
fuzzy: {},
|
fuzzy: {},
|
||||||
range: {},
|
range: {},
|
||||||
|
|
Loading…
Reference in New Issue