-
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
[Content Management] Cross Type Search (savedObjects.find()
based)
#154464
Conversation
savedObjects.find()
based)
…o d/2023-04-05-msearch-1
Pinging @elastic/appex-sharedux (Team:SharedUX) |
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.
Awesome work @Dosant ! I left a small comment about readability but otherwise looks good. Looking forward to see some integration 👍
contentTypes: input.contentTypes.map((contentType) => | ||
addVersion(contentType, this.contentTypeRegistry) | ||
), | ||
}) as Promise<MSearchResult<T>>; |
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.
You can avoid this casting by typing the CrudClient
export interface CrudClient {
...
delete(input: DeleteIn): Promise<unknown>;
search(input: SearchIn): Promise<unknown>;
mSearch?<T = unknown>(input: MSearchIn): Promise<MSearchResult<T>>; // here
}
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.
I agree, thanks. I plan to clean up all the client-side types in the separate pr
} | ||
) {} | ||
|
||
async search( |
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.
Looks good. I had to put a few comments and spaces to make it slightly more readable (quite a few Map
around!).
That's how I left it in local
async search(
contentTypes: Array<{ contentTypeId: string; ctx: StorageContext }>,
query: SearchQuery
): Promise<MSearchResult> {
// Map: contentTypeId -> StorageContext
const contentTypeToCtx = new Map(contentTypes.map((ct) => [ct.contentTypeId, ct.ctx]));
// Map: contentTypeId -> MSearchConfig
const contentTypeToMSearchConfig = new Map(
contentTypes.map((ct) => {
const mSearchConfig = this.deps.contentRegistry.getDefinition(ct.contentTypeId).storage
.mSearch;
if (!mSearchConfig) {
throw new Error(`Content type ${ct.contentTypeId} does not support mSearch`);
}
return [ct.contentTypeId, mSearchConfig];
})
);
// Map: Saved object type -> [contentTypeId, MSearchConfig]
const soTypeToMSearchConfig = new Map(
Array.from(contentTypeToMSearchConfig.entries()).map(([ct, mSearchConfig]) => {
return [mSearchConfig.savedObjectType, [ct, mSearchConfig] as const];
})
);
const mSearchConfigs = Array.from(contentTypeToMSearchConfig.values());
const soSearchTypes = mSearchConfigs.map((mSearchConfig) => mSearchConfig.savedObjectType);
const additionalSearchFields = new Set<string>();
mSearchConfigs.forEach((mSearchConfig) => {
(mSearchConfig.additionalSearchFields ?? []).forEach(additionalSearchFields.add);
});
const savedObjectsClient = await this.deps.getSavedObjectsClient();
const soResult = await savedObjectsClient.find({
type: soSearchTypes,
search: query.text,
searchFields: [`title^3`, `description`, ...additionalSearchFields],
defaultSearchOperator: 'AND',
// TODO: tags
// TODO: pagination
// TODO: sort
});
...
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Public APIs missing exports
Page load bundle
Unknown metric groupsAPI count
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: |
Summary
Partially addresses #152224
Tech Doc (private)
Introduce
mSearch
- temporary cross-content type search layer for content management backed bysavedObjects.find
Until we have a dedicated search layer in CM services, we want to provide a temporary solution to replace client-side or naive server proxy usages of
savedObjects.find()
across multiple types with Content Management API to prepare these places for backward compatibility compliance.Later we plan to use the new API together with shared components that work across multiple types like
SavedObjectFinder
orTableListView
The api would only work with content types that use saved objects as a backend.
To opt-in a saved object backed content type to
mSearch
need to provideMSearchConfig
onContentStorage
:Out of scope of this PR: