From efe1eab1ecf870946c3152be1e897c243d1a3da5 Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Wed, 17 Nov 2021 16:46:10 +0000 Subject: [PATCH] add displayName to text in indexed document for user entities Signed-off-by: Ainhoa Larumbe --- .../src/search/DefaultCatalogCollator.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index a28a7645c4..5458b9054a 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -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,23 @@ export class DefaultCatalogCollator implements DocumentCollator { return formatted.toLowerCase(); } + protected isUserEntity(entity: Entity): entity is UserEntity { + return entity.kind === 'User'; + } + + protected getDocumentText(entity: Entity): string { + let documentText = entity.metadata.description || ''; + if (this.isUserEntity(entity)) { + if (entity.spec?.profile?.displayName && entity.metadata.description) { + // combine displayName and description + documentText = `${entity.spec?.profile?.displayName} : ${entity.metadata.description}`; + } else { + documentText = entity.spec?.profile?.displayName || documentText; + } + } + return documentText; + } + async execute() { const response = await this.catalogClient.getEntities({ filter: this.filter, @@ -93,7 +110,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,