Skip to content

Commit

Permalink
Add simple string query flags options to find method
Browse files Browse the repository at this point in the history
Signed-off-by: Hailong Cui <[email protected]>
  • Loading branch information
Hailong-am committed Oct 17, 2023
1 parent f00cb3c commit af07ba0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ export class SavedObjectsRepository {
preference,
workspaces,
ACLSearchParams,
flags,
} = options;

if (!type && !typeToNamespacesMap) {
Expand Down Expand Up @@ -963,6 +964,7 @@ export class SavedObjectsRepository {
kueryNode,
workspaces,
ACLSearchParams,
flags,
}),
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ interface QueryParams {
kueryNode?: KueryNode;
workspaces?: string[];
ACLSearchParams?: SavedObjectsFindOptions['ACLSearchParams'];
flags?: string;
}

export function getClauseForReference(reference: HasReferenceQueryParams) {
Expand Down Expand Up @@ -226,6 +227,7 @@ export function getQueryParams({
kueryNode,
workspaces,
ACLSearchParams,
flags,
}: QueryParams) {
const types = getTypes(
registry,
Expand Down Expand Up @@ -269,6 +271,7 @@ export function getQueryParams({
searchFields,
rootSearchFields,
defaultSearchOperator,
flags,
});

if (useMatchPhrasePrefix) {
Expand Down Expand Up @@ -417,18 +420,21 @@ const getSimpleQueryStringClause = ({
searchFields,
rootSearchFields,
defaultSearchOperator,
flags,
}: {
search: string;
types: string[];
searchFields?: string[];
rootSearchFields?: string[];
defaultSearchOperator?: string;
flags?: string;
}) => {
return {
simple_query_string: {
query: search,
...getSimpleQueryStringTypeFields(types, searchFields, rootSearchFields),
...(defaultSearchOperator ? { default_operator: defaultSearchOperator } : {}),
...(flags ? { flags } : {}),
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ interface GetSearchDslOptions {
kueryNode?: KueryNode;
workspaces?: string[];
ACLSearchParams?: SavedObjectsFindOptions['ACLSearchParams'];
flags?: string;
}

export function getSearchDsl(
Expand All @@ -76,6 +77,7 @@ export function getSearchDsl(
kueryNode,
workspaces,
ACLSearchParams,
flags,
} = options;

if (!type) {
Expand All @@ -100,6 +102,7 @@ export function getSearchDsl(
kueryNode,
workspaces,
ACLSearchParams,
flags,
}),
...getSortingParams(mappings, type, sortField, sortOrder),
};
Expand Down
2 changes: 2 additions & 0 deletions src/core/server/saved_objects/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ export interface SavedObjectsFindOptions {
search?: string;
/** The fields to perform the parsed query against. See OpenSearch Simple Query String `fields` argument for more information */
searchFields?: string[];
/** The enabled operators for OpenSearch Simple Query String. See OpenSearch Simple Query String `flags` argument for more information */
flags?: string;
/**
* The fields to perform the parsed query against. Unlike the `searchFields` argument, these are expected to be root fields and will not
* be modified. If used in conjunction with `searchFields`, both are concatenated together.
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/workspace/server/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl {
type: WORKSPACE_TYPE,
search: attributes.name,
searchFields: ['name'],
flags: 'NONE', // disable all operators, treat workspace as literal string
}
);
if (existingWorkspaceRes && existingWorkspaceRes.total > 0) {
Expand Down Expand Up @@ -353,6 +354,7 @@ export class WorkspaceClientWithSavedObject implements IWorkspaceDBImpl {
search: attributes.name,
searchFields: ['name'],
fields: ['_id'],
flags: 'NONE', // disable all operators, treat workspace as literal string
});
if (existingWorkspaceRes && existingWorkspaceRes.total > 0) {
throw new Error(DUPLICATE_WORKSPACE_NAME_ERROR);
Expand Down

0 comments on commit af07ba0

Please sign in to comment.