1
0
Fork 0
mirror of synced 2024-08-07 14:18:02 +12:00

Merge pull request #13929 from Budibase/budi-8338-refactor-in-memory-filter-naming

Remove the word 'lucene' from runLuceneQuery and buildLuceneQuery.
This commit is contained in:
Sam Rose 2024-06-12 15:33:33 +01:00 committed by GitHub
commit e2726998df
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 62 additions and 63 deletions

View file

@ -41,7 +41,7 @@
EditorModes, EditorModes,
} from "components/common/CodeEditor" } from "components/common/CodeEditor"
import FilterBuilder from "components/design/settings/controls/FilterEditor/FilterBuilder.svelte" import FilterBuilder from "components/design/settings/controls/FilterEditor/FilterBuilder.svelte"
import { LuceneUtils, Utils } from "@budibase/frontend-core" import { QueryUtils, Utils } from "@budibase/frontend-core"
import { import {
getSchemaForDatasourcePlus, getSchemaForDatasourcePlus,
getEnvironmentBindings, getEnvironmentBindings,
@ -343,7 +343,7 @@
} }
function saveFilters(key) { function saveFilters(key) {
const filters = LuceneUtils.buildLuceneQuery(tempFilters) const filters = QueryUtils.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

View file

@ -8,7 +8,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import download from "downloadjs" import download from "downloadjs"
import { API } from "api" import { API } from "api"
import { LuceneUtils } from "@budibase/frontend-core" import { QueryUtils } from "@budibase/frontend-core"
import { utils } from "@budibase/shared-core" import { utils } from "@budibase/shared-core"
import { ROW_EXPORT_FORMATS } from "constants/backend" import { ROW_EXPORT_FORMATS } from "constants/backend"
@ -49,7 +49,7 @@
exportFormat = Array.isArray(options) ? options[0]?.key : [] exportFormat = Array.isArray(options) ? options[0]?.key : []
} }
$: luceneFilter = LuceneUtils.buildLuceneQuery(appliedFilters) $: query = QueryUtils.buildQuery(appliedFilters)
$: exportOpDisplay = buildExportOpDisplay( $: exportOpDisplay = buildExportOpDisplay(
sorting, sorting,
filterDisplay, filterDisplay,
@ -139,7 +139,7 @@
tableId: view, tableId: view,
format: exportFormat, format: exportFormat,
search: { search: {
query: luceneFilter, query,
sort: sorting?.sortColumn, sort: sorting?.sortColumn,
sortOrder: sorting?.sortOrder, sortOrder: sorting?.sortOrder,
paginate: false, paginate: false,

View file

@ -12,7 +12,7 @@
import { dndzone } from "svelte-dnd-action" import { dndzone } from "svelte-dnd-action"
import { generate } from "shortid" import { generate } from "shortid"
import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte" import DrawerBindableInput from "components/common/bindings/DrawerBindableInput.svelte"
import { LuceneUtils, Constants } from "@budibase/frontend-core" import { QueryUtils, Constants } from "@budibase/frontend-core"
import { selectedComponent, componentStore } from "stores/builder" import { selectedComponent, componentStore } from "stores/builder"
import { getComponentForSetting } from "components/design/settings/componentSettings" import { getComponentForSetting } from "components/design/settings/componentSettings"
import PropertyControl from "components/design/settings/controls/PropertyControl.svelte" import PropertyControl from "components/design/settings/controls/PropertyControl.svelte"
@ -119,7 +119,7 @@
} }
const getOperatorOptions = condition => { const getOperatorOptions = condition => {
return LuceneUtils.getValidOperatorsForType({ type: condition.valueType }) return QueryUtils.getValidOperatorsForType({ type: condition.valueType })
} }
const onOperatorChange = (condition, newOperator) => { const onOperatorChange = (condition, newOperator) => {
@ -138,7 +138,7 @@
condition.referenceValue = null condition.referenceValue = null
// Ensure a valid operator is set // Ensure a valid operator is set
const validOperators = LuceneUtils.getValidOperatorsForType({ const validOperators = QueryUtils.getValidOperatorsForType({
type: newType, type: newType,
}).map(x => x.value) }).map(x => x.value)
if (!validOperators.includes(condition.operator)) { if (!validOperators.includes(condition.operator)) {

View file

@ -1,7 +1,7 @@
<script> <script>
import { getContext } from "svelte" import { getContext } from "svelte"
import { Pagination, ProgressCircle } from "@budibase/bbui" import { Pagination, ProgressCircle } from "@budibase/bbui"
import { fetchData, LuceneUtils } from "@budibase/frontend-core" import { fetchData, QueryUtils } from "@budibase/frontend-core"
export let dataSource export let dataSource
export let filter export let filter
@ -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 = QueryUtils.buildQuery(filter)
$: query = extendQuery(defaultQuery, queryExtensions) $: query = extendQuery(defaultQuery, queryExtensions)
$: fetch = createFetch(dataSource) $: fetch = createFetch(dataSource)
$: fetch.update({ $: fetch.update({

View file

@ -3,7 +3,7 @@
import { getContext, onDestroy } from "svelte" import { getContext, onDestroy } from "svelte"
import { ModalContent, Modal } from "@budibase/bbui" import { ModalContent, Modal } from "@budibase/bbui"
import FilterModal from "./FilterModal.svelte" import FilterModal from "./FilterModal.svelte"
import { LuceneUtils } from "@budibase/frontend-core" import { QueryUtils } from "@budibase/frontend-core"
import Button from "../Button.svelte" import Button from "../Button.svelte"
export let dataProvider export let dataProvider
@ -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 = QueryUtils.buildQuery(filters)
addExtension?.($component.id, queryExtension) addExtension?.($component.id, queryExtension)
} else { } else {
removeExtension?.($component.id) removeExtension?.($component.id)

View file

@ -31,7 +31,7 @@ import { enrichButtonActions } from "./utils/buttonActions.js"
import { processStringSync, makePropSafe } from "@budibase/string-templates" import { processStringSync, makePropSafe } from "@budibase/string-templates"
import { import {
fetchData, fetchData,
LuceneUtils, QueryUtils,
Constants, Constants,
RowUtils, RowUtils,
memo, memo,
@ -65,7 +65,7 @@ export default {
getAction, getAction,
fetchDatasourceSchema, fetchDatasourceSchema,
fetchData, fetchData,
LuceneUtils, QueryUtils,
ContextScopes: Constants.ContextScopes, ContextScopes: Constants.ContextScopes,
getAPIKey, getAPIKey,
enrichButtonActions, enrichButtonActions,

View file

@ -1,4 +1,4 @@
import { LuceneUtils } from "@budibase/frontend-core" import { QueryUtils } from "@budibase/frontend-core"
export const getActiveConditions = conditions => { export const getActiveConditions = conditions => {
if (!conditions?.length) { if (!conditions?.length) {
@ -33,8 +33,8 @@ export const getActiveConditions = conditions => {
value: condition.referenceValue, value: condition.referenceValue,
} }
const query = LuceneUtils.buildLuceneQuery([luceneCondition]) const query = QueryUtils.buildQuery([luceneCondition])
const result = LuceneUtils.runLuceneQuery([luceneCondition], query) const result = QueryUtils.runQuery([luceneCondition], query)
return result.length > 0 return result.length > 0
}) })
} }

View file

@ -13,7 +13,7 @@
} from "@budibase/bbui" } from "@budibase/bbui"
import { FieldType, SearchFilterOperator } from "@budibase/types" import { FieldType, SearchFilterOperator } from "@budibase/types"
import { generate } from "shortid" import { generate } from "shortid"
import { LuceneUtils, Constants } from "@budibase/frontend-core" import { QueryUtils, Constants } from "@budibase/frontend-core"
import { getContext } from "svelte" import { getContext } from "svelte"
import FilterUsers from "./FilterUsers.svelte" import FilterUsers from "./FilterUsers.svelte"
import { getFields } from "../utils/searchFields" import { getFields } from "../utils/searchFields"
@ -112,7 +112,7 @@
return [] return []
} }
return LuceneUtils.getValidOperatorsForType( return QueryUtils.getValidOperatorsForType(
filter, filter,
filter.field || filter.name, filter.field || filter.name,
datasource datasource

View file

@ -1,10 +1,9 @@
import { writable, derived, get } from "svelte/store" import { writable, derived, get } from "svelte/store"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { LuceneUtils } from "../utils" import { QueryUtils } from "../utils"
import { convertJSONSchemaToTableSchema } from "../utils/json" import { convertJSONSchemaToTableSchema } from "../utils/json"
const { buildLuceneQuery, luceneLimit, runLuceneQuery, luceneSort } = const { buildQuery, limit: queryLimit, runQuery, sort } = QueryUtils
LuceneUtils
/** /**
* Parent class which handles the implementation of fetching data from an * Parent class which handles the implementation of fetching data from an
@ -177,10 +176,10 @@ export default class DataFetch {
} }
} }
// Build the lucene query // Build the 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,17 +228,17 @@ 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
if (!this.features.supportsSort && clientSideSorting) { if (!this.features.supportsSort && clientSideSorting) {
rows = luceneSort(rows, sortColumn, sortOrder, sortType) rows = sort(rows, sortColumn, sortOrder, sortType)
} }
// If we don't support pagination, do a client-side limit // If we don't support pagination, do a client-side limit
if (!this.features.supportsPagination && clientSideLimiting) { if (!this.features.supportsPagination && clientSideLimiting) {
rows = luceneLimit(rows, limit) rows = queryLimit(rows, limit)
} }
return { return {

View file

@ -1,7 +1,7 @@
import { get } from "svelte/store" import { get } from "svelte/store"
import DataFetch from "./DataFetch.js" import DataFetch from "./DataFetch.js"
import { TableNames } from "../constants" import { TableNames } from "../constants"
import { LuceneUtils } from "../utils" import { QueryUtils } from "../utils"
export default class UserFetch extends DataFetch { export default class UserFetch extends DataFetch {
constructor(opts) { constructor(opts) {
@ -33,7 +33,7 @@ export default class UserFetch extends DataFetch {
let finalQuery let finalQuery
// convert old format to new one - we now allow use of the lucene format // convert old format to new one - we now allow use of the lucene format
const { appId, paginated, ...rest } = query const { appId, paginated, ...rest } = query
if (!LuceneUtils.hasFilters(query) && rest.email != null) { if (!QueryUtils.hasFilters(query) && rest.email != null) {
finalQuery = { string: { email: rest.email } } finalQuery = { string: { email: rest.email } }
} else { } else {
finalQuery = rest finalQuery = rest

View file

@ -1,4 +1,4 @@
export { dataFilters as LuceneUtils } from "@budibase/shared-core" export { dataFilters as QueryUtils } from "@budibase/shared-core"
export * as JSONUtils from "./json" export * as JSONUtils from "./json"
export * as CookieUtils from "./cookies" export * as CookieUtils from "./cookies"
export * as RoleUtils from "./roles" export * as RoleUtils from "./roles"

View file

@ -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 =

View file

@ -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)
} }
@ -585,7 +585,7 @@ class GoogleSheetsIntegration implements DatasourcePlus {
}) })
} }
const [sortField, sortInfo] = Object.entries(query.sort)[0] const [sortField, sortInfo] = Object.entries(query.sort)[0]
response = dataFilters.luceneSort( response = dataFilters.sort(
response, response,
sortField, sortField,
sortInfo.direction, sortInfo.direction,

View file

@ -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 []
} }
@ -451,7 +451,7 @@ export const runLuceneQuery = (docs: any[], query?: SearchFilters) => {
* @param sortOrder the sort order ("ascending" or "descending") * @param sortOrder the sort order ("ascending" or "descending")
* @param sortType the type of sort ("string" or "number") * @param sortType the type of sort ("string" or "number")
*/ */
export const luceneSort = ( export const sort = (
docs: any[], docs: any[],
sort: string, sort: string,
sortOrder: SortDirection, sortOrder: SortDirection,
@ -481,7 +481,7 @@ export const luceneSort = (
* @param docs the data * @param docs the data
* @param limit the number of docs to limit to * @param limit the number of docs to limit to
*/ */
export const luceneLimit = (docs: any[], limit: string) => { export const limit = (docs: any[], limit: string) => {
const numLimit = parseFloat(limit) const numLimit = parseFloat(limit)
if (isNaN(numLimit)) { if (isNaN(numLimit)) {
return docs return docs

View file

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