Merge pull request #8116 from ainhoaL/user-search-displayname

Add User entities displayName to default catalog collator to be able to search by user's full name
This commit is contained in:
Ainhoa
2021-11-22 15:32:26 +00:00
committed by GitHub
2 changed files with 25 additions and 2 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-catalog-backend': patch
---
Index User entities by displayName to be able to search by full name. Added displayName (if present) to the 'text' field in the indexed document.
@@ -15,7 +15,7 @@
*/
import { PluginEndpointDiscovery } from '@backstage/backend-common';
import { Entity } from '@backstage/catalog-model';
import { Entity, UserEntity } from '@backstage/catalog-model';
import { IndexableDocument, DocumentCollator } from '@backstage/search-common';
import { Config } from '@backstage/config';
import {
@@ -81,6 +81,24 @@ export class DefaultCatalogCollator implements DocumentCollator {
return formatted.toLowerCase();
}
private isUserEntity(entity: Entity): entity is UserEntity {
return entity.kind.toLocaleUpperCase('en-US') === 'USER';
}
private getDocumentText(entity: Entity): string {
let documentText = entity.metadata.description || '';
if (this.isUserEntity(entity)) {
if (entity.spec?.profile?.displayName && documentText) {
// combine displayName and description
const displayName = entity.spec?.profile?.displayName;
documentText = displayName.concat(' : ', documentText);
} else {
documentText = entity.spec?.profile?.displayName || documentText;
}
}
return documentText;
}
async execute() {
const response = await this.catalogClient.getEntities({
filter: this.filter,
@@ -93,7 +111,7 @@ export class DefaultCatalogCollator implements DocumentCollator {
kind: entity.kind,
name: entity.metadata.name,
}),
text: entity.metadata.description || '',
text: this.getDocumentText(entity),
componentType: entity.spec?.type?.toString() || 'other',
namespace: entity.metadata.namespace || 'default',
kind: entity.kind,