Skip to content

Commit

Permalink
[8.x] [Global Search, Saved Objects Management] Use new parse option …
Browse files Browse the repository at this point in the history
…to specify recognized fields (#190464) (#193448)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Global Search, Saved Objects Management] Use new parse option to
specify recognized fields
(#190464)](#190464)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Tim
Sullivan","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-19T16:02:45Z","message":"[Global
Search, Saved Objects Management] Use new parse option to specify
recognized fields (#190464)\n\nThis PR adds a new option to the
`SchemaType` interface for parsing a\r\nquery from a search in
EuiSearchBar. This new field controls how\r\nEuiSearchBar text is parsed
into a Query object. It enables better\r\naccuracy in how search terms
are parsed when they include a `:`\r\ncharacter.\r\n\r\n## Release
note\r\nFixed an issue when using search bars with a term that includes
a colon\r\n`:` character.\r\n\r\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/184496\r\nDepends on
https://github.com/elastic/eui/pull/7960\r\n\r\n**GLOBAL SEARCH:
BEFORE**\r\n\r\n![akshfgkalsfh-before](https://github.com/user-attachments/assets/22377a3e-394e-43fb-83db-ae2477ce22d7)\r\n\r\n**GLOBAL
SEARCH:
AFTER**\r\n\r\n![akshfgkalsfh-after](https://github.com/user-attachments/assets/406d56eb-c946-493b-94f3-abb0380611f3)\r\n\r\n**SAVED
OBJECTS MANAGEMENT:
BEFORE**\r\n\r\n![okjoyofjiuh-before](https://github.com/user-attachments/assets/c1c56572-31aa-41df-b0c5-3eef421a06c5)\r\n\r\n**SAVED
OBJECTS MANAGEMENT:
AFTER**\r\n\r\n![okjoyofjiuh-after](https://github.com/user-attachments/assets/9e19bbcf-72e7-43d5-a9e7-3c5805632a38)\r\n\r\n**SAVED
OBJECTS FINDER:
BEFORE**\r\n\r\n![lfdgnhklfd-before](https://github.com/user-attachments/assets/b826987d-8af6-4c20-93b0-0d0bb76d9501)\r\n\r\n**SAVED
OBJECTS FINDER:
AFTER**\r\n\r\n![lfdgnhklfd-after](https://github.com/user-attachments/assets/e8e007b9-91f7-4209-bfd5-ce43a2cbc894)\r\n\r\n##
Checklist\r\n - [x] Ensure that filtering using `type:` and `tags:`
still
works","sha":"460ca2a83f0fd14b9d8c78c6b695e742c3f25930","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix","v9.0.0","Team:SharedUX","v8.16.0","backport:version"],"title":"[Global
Search, Saved Objects Management] Use new parse option to specify
recognized
fields","number":190464,"url":"https://github.com/elastic/kibana/pull/190464","mergeCommit":{"message":"[Global
Search, Saved Objects Management] Use new parse option to specify
recognized fields (#190464)\n\nThis PR adds a new option to the
`SchemaType` interface for parsing a\r\nquery from a search in
EuiSearchBar. This new field controls how\r\nEuiSearchBar text is parsed
into a Query object. It enables better\r\naccuracy in how search terms
are parsed when they include a `:`\r\ncharacter.\r\n\r\n## Release
note\r\nFixed an issue when using search bars with a term that includes
a colon\r\n`:` character.\r\n\r\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/184496\r\nDepends on
https://github.com/elastic/eui/pull/7960\r\n\r\n**GLOBAL SEARCH:
BEFORE**\r\n\r\n![akshfgkalsfh-before](https://github.com/user-attachments/assets/22377a3e-394e-43fb-83db-ae2477ce22d7)\r\n\r\n**GLOBAL
SEARCH:
AFTER**\r\n\r\n![akshfgkalsfh-after](https://github.com/user-attachments/assets/406d56eb-c946-493b-94f3-abb0380611f3)\r\n\r\n**SAVED
OBJECTS MANAGEMENT:
BEFORE**\r\n\r\n![okjoyofjiuh-before](https://github.com/user-attachments/assets/c1c56572-31aa-41df-b0c5-3eef421a06c5)\r\n\r\n**SAVED
OBJECTS MANAGEMENT:
AFTER**\r\n\r\n![okjoyofjiuh-after](https://github.com/user-attachments/assets/9e19bbcf-72e7-43d5-a9e7-3c5805632a38)\r\n\r\n**SAVED
OBJECTS FINDER:
BEFORE**\r\n\r\n![lfdgnhklfd-before](https://github.com/user-attachments/assets/b826987d-8af6-4c20-93b0-0d0bb76d9501)\r\n\r\n**SAVED
OBJECTS FINDER:
AFTER**\r\n\r\n![lfdgnhklfd-after](https://github.com/user-attachments/assets/e8e007b9-91f7-4209-bfd5-ce43a2cbc894)\r\n\r\n##
Checklist\r\n - [x] Ensure that filtering using `type:` and `tags:`
still
works","sha":"460ca2a83f0fd14b9d8c78c6b695e742c3f25930"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/190464","number":190464,"mergeCommit":{"message":"[Global
Search, Saved Objects Management] Use new parse option to specify
recognized fields (#190464)\n\nThis PR adds a new option to the
`SchemaType` interface for parsing a\r\nquery from a search in
EuiSearchBar. This new field controls how\r\nEuiSearchBar text is parsed
into a Query object. It enables better\r\naccuracy in how search terms
are parsed when they include a `:`\r\ncharacter.\r\n\r\n## Release
note\r\nFixed an issue when using search bars with a term that includes
a colon\r\n`:` character.\r\n\r\n## Summary\r\n\r\nCloses
https://github.com/elastic/kibana/issues/184496\r\nDepends on
https://github.com/elastic/eui/pull/7960\r\n\r\n**GLOBAL SEARCH:
BEFORE**\r\n\r\n![akshfgkalsfh-before](https://github.com/user-attachments/assets/22377a3e-394e-43fb-83db-ae2477ce22d7)\r\n\r\n**GLOBAL
SEARCH:
AFTER**\r\n\r\n![akshfgkalsfh-after](https://github.com/user-attachments/assets/406d56eb-c946-493b-94f3-abb0380611f3)\r\n\r\n**SAVED
OBJECTS MANAGEMENT:
BEFORE**\r\n\r\n![okjoyofjiuh-before](https://github.com/user-attachments/assets/c1c56572-31aa-41df-b0c5-3eef421a06c5)\r\n\r\n**SAVED
OBJECTS MANAGEMENT:
AFTER**\r\n\r\n![okjoyofjiuh-after](https://github.com/user-attachments/assets/9e19bbcf-72e7-43d5-a9e7-3c5805632a38)\r\n\r\n**SAVED
OBJECTS FINDER:
BEFORE**\r\n\r\n![lfdgnhklfd-before](https://github.com/user-attachments/assets/b826987d-8af6-4c20-93b0-0d0bb76d9501)\r\n\r\n**SAVED
OBJECTS FINDER:
AFTER**\r\n\r\n![lfdgnhklfd-after](https://github.com/user-attachments/assets/e8e007b9-91f7-4209-bfd5-ce43a2cbc894)\r\n\r\n##
Checklist\r\n - [x] Ensure that filtering using `type:` and `tags:`
still
works","sha":"460ca2a83f0fd14b9d8c78c6b695e742c3f25930"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Tim Sullivan <[email protected]>
  • Loading branch information
kibanamachine and tsullivan committed Sep 19, 2024
1 parent c5ff79a commit 446d593
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,9 @@ export class SavedObjectFinderUi extends React.Component<
box: {
incremental: true,
'data-test-subj': 'savedObjectFinderSearchInput',
schema: {
recognizedFields: ['type', 'tag'],
},
},
filters: this.props.showFilter
? [
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,12 @@ export class Table extends PureComponent<TableProps, TableState> {
<Fragment>
{activeActionContents}
<EuiSearchBar
box={{ 'data-test-subj': 'savedObjectSearchBar' }}
box={{
'data-test-subj': 'savedObjectSearchBar',
schema: {
recognizedFields: ['type', 'tag'],
},
}}
filters={filters as any}
onChange={this.onChange}
defaultQuery={this.props.initialQuery}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ describe('parseSearchParams', () => {
const searchParams = parseSearchParams('tag:((()^invalid');
expect(searchParams).toEqual({
term: 'tag:((()^invalid',
filters: {
unknowns: {},
},
filters: {},
});
});

Expand All @@ -33,7 +31,6 @@ describe('parseSearchParams', () => {
expect(searchParams.filters).toEqual({
tags: undefined,
types: undefined,
unknowns: {},
});
});

Expand All @@ -44,20 +41,16 @@ describe('parseSearchParams', () => {
filters: {
tags: ['foo', 'dolly'],
types: ['bar'],
unknowns: {},
},
});
});

it('handles unknowns field clauses', () => {
it('considers unknown field clauses to be part of the raw search term', () => {
const searchParams = parseSearchParams('tag:foo unknown:bar hello');
expect(searchParams).toEqual({
term: 'hello',
term: 'unknown:bar hello',
filters: {
tags: ['foo'],
unknowns: {
unknown: ['bar'],
},
},
});
});
Expand All @@ -69,7 +62,6 @@ describe('parseSearchParams', () => {
filters: {
tags: ['foo', 'bar'],
types: ['dash', 'board'],
unknowns: {},
},
});
});
Expand All @@ -81,7 +73,6 @@ describe('parseSearchParams', () => {
filters: {
tags: ['42', 'true'],
types: ['69', 'false'],
unknowns: {},
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,24 @@ const aliasMap = {
};

export const parseSearchParams = (term: string): ParsedSearchParams => {
const recognizedFields = knownFilters.concat(...Object.values(aliasMap));
let query: Query;

try {
query = Query.parse(term);
query = Query.parse(term, {
schema: { recognizedFields },
});
} catch (e) {
// if the query fails to parse, we just perform the search against the raw search term.
return {
term,
filters: {
unknowns: {},
},
filters: {},
};
}

const searchTerm = getSearchTerm(query);
const filterValues = applyAliases(getFieldValueMap(query), aliasMap);

const unknownFilters = [...filterValues.entries()]
.filter(([key]) => !knownFilters.includes(key))
.reduce((unknowns, [key, value]) => {
return {
...unknowns,
[key]: value,
};
}, {} as Record<string, FilterValues>);

const tags = filterValues.get('tag');
const types = filterValues.get('type');

Expand All @@ -51,7 +43,6 @@ export const parseSearchParams = (term: string): ParsedSearchParams => {
filters: {
tags: tags ? valuesToString(tags) : undefined,
types: types ? valuesToString(types) : undefined,
unknowns: unknownFilters,
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,5 @@ export interface ParsedSearchParams {
* Aggregation of `type` and `types` field clauses
*/
types?: FilterValues<string>;
/**
* All unknown field clauses
*/
unknowns: Record<string, FilterValues>;
};
}

0 comments on commit 446d593

Please sign in to comment.