-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Global Search, Saved Objects Management] Use new parse option to specify recognized fields #190464
Changes from 5 commits
43701bb
0611d8a
fbc5028
fbcf86f
7c85105
482267e
2ce26d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -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()] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the previous code, nothing was handling the |
||
.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'); | ||
|
||
|
@@ -51,7 +43,6 @@ export const parseSearchParams = (term: string): ParsedSearchParams => { | |
filters: { | ||
tags: tags ? valuesToString(tags) : undefined, | ||
types: types ? valuesToString(types) : undefined, | ||
unknowns: unknownFilters, | ||
}, | ||
}; | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment below for explanation