Typing improvements and fixing issue detected by test cases (old lucene syntax).
This commit is contained in:
parent
9ea74dcb45
commit
9ea3aca5e4
|
@ -39,9 +39,9 @@ export async function searchView(
|
|||
// Enrich saved query with ephemeral query params.
|
||||
// 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.
|
||||
let query: any = supportsLogicalOperators
|
||||
let query = supportsLogicalOperators
|
||||
? dataFilters.buildQuery(view.query)
|
||||
: dataFilters.buildQueryLegacy(view.query as SearchFilter[])
|
||||
: dataFilters.buildQueryLegacy(view.query)
|
||||
|
||||
delete query?.onEmptyFilter
|
||||
|
||||
|
@ -51,8 +51,10 @@ export async function searchView(
|
|||
|
||||
if (!supportsLogicalOperators) {
|
||||
// In the unlikely event that a Grouped Filter is in a non-SQS environment
|
||||
// It needs to be ignored. Entirely
|
||||
let queryFilters: SearchFilter[] = Array.isArray(query) ? query : []
|
||||
// It needs to be ignored entirely
|
||||
let queryFilters: SearchFilter[] = Array.isArray(view.query)
|
||||
? view.query
|
||||
: []
|
||||
|
||||
// Extract existing fields
|
||||
const existingFields =
|
||||
|
@ -64,15 +66,16 @@ export async function searchView(
|
|||
Object.keys(body.query).forEach(key => {
|
||||
const operator = key as Exclude<SearchFilterKey, LogicalOperator>
|
||||
Object.keys(body.query[operator] || {}).forEach(field => {
|
||||
if (!existingFields.includes(db.removeKeyNumbering(field))) {
|
||||
if (query && !existingFields.includes(db.removeKeyNumbering(field))) {
|
||||
query[operator]![field] = body.query[operator]![field]
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
const conditions = query ? [query] : []
|
||||
query = {
|
||||
$and: {
|
||||
conditions: [query, body.query],
|
||||
conditions: [...conditions, body.query],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -80,7 +83,7 @@ export async function searchView(
|
|||
|
||||
await context.ensureSnippetContext(true)
|
||||
|
||||
const enrichedQuery = await enrichSearchContext(query, {
|
||||
const enrichedQuery = await enrichSearchContext(query || {}, {
|
||||
user: sdk.users.getUserContextBindings(ctx.user),
|
||||
})
|
||||
|
||||
|
|
|
@ -428,8 +428,9 @@ const builderFilter = (expression: SearchFilter) => {
|
|||
return query
|
||||
}
|
||||
|
||||
export const buildQueryLegacy = (filter: SearchFilter[]) => {
|
||||
//
|
||||
export const buildQueryLegacy = (
|
||||
filter?: SearchFilterGroup | SearchFilter[]
|
||||
): SearchFilters | undefined => {
|
||||
let query: SearchFilters = {
|
||||
string: {},
|
||||
fuzzy: {},
|
||||
|
@ -523,7 +524,6 @@ export const buildQueryLegacy = (filter: SearchFilter[]) => {
|
|||
}
|
||||
}
|
||||
} else if (isLogicalSearchOperator(queryOperator)) {
|
||||
// TODO
|
||||
} else if (query[queryOperator] && operator !== "onEmptyFilter") {
|
||||
if (type === "boolean") {
|
||||
// Transform boolean filters to cope with null.
|
||||
|
@ -548,7 +548,9 @@ export const buildQueryLegacy = (filter: SearchFilter[]) => {
|
|||
return query
|
||||
}
|
||||
|
||||
export const buildQuery = (filter?: SearchFilterGroup | SearchFilter[]) => {
|
||||
export const buildQuery = (
|
||||
filter?: SearchFilterGroup | SearchFilter[]
|
||||
): SearchFilters | undefined => {
|
||||
if (!filter) {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue