From efe1eab1ecf870946c3152be1e897c243d1a3da5 Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Wed, 17 Nov 2021 16:46:10 +0000 Subject: [PATCH 1/6] 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, From eddb82ab7cb8143ccc91c1cb4b48d6989fb398cc Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Wed, 17 Nov 2021 16:51:07 +0000 Subject: [PATCH 2/6] add changeset Signed-off-by: Ainhoa Larumbe --- .changeset/smooth-vans-boil.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/smooth-vans-boil.md diff --git a/.changeset/smooth-vans-boil.md b/.changeset/smooth-vans-boil.md new file mode 100644 index 0000000000..39b2ea386f --- /dev/null +++ b/.changeset/smooth-vans-boil.md @@ -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. From 000c12384e83726d0cac3bf24424b0dc3be34a2b Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Thu, 18 Nov 2021 09:46:09 +0000 Subject: [PATCH 3/6] update api-report Signed-off-by: Ainhoa Larumbe --- plugins/catalog-backend/api-report.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 6660912dda..6c8c9a8f82 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -32,6 +32,7 @@ import { Router } from 'express'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { ScmIntegrations } from '@backstage/integration'; import { UrlReader } from '@backstage/backend-common'; +import { UserEntity } from '@backstage/catalog-model'; import { Validators } from '@backstage/catalog-model'; // Warning: (ae-missing-release-tag) "AddLocationResult" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -764,6 +765,10 @@ export class DefaultCatalogCollator implements DocumentCollator { }, ): DefaultCatalogCollator; // (undocumented) + protected getDocumentText(entity: Entity): string; + // (undocumented) + protected isUserEntity(entity: Entity): entity is UserEntity; + // (undocumented) protected locationTemplate: string; // (undocumented) readonly type: string; From 73438d1ff10b751701e948d5be01b800916cd7fc Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Mon, 22 Nov 2021 09:41:00 +0000 Subject: [PATCH 4/6] change methods to private Signed-off-by: Ainhoa Larumbe --- plugins/catalog-backend/api-report.md | 5 ----- .../catalog-backend/src/search/DefaultCatalogCollator.ts | 9 +++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/catalog-backend/api-report.md b/plugins/catalog-backend/api-report.md index 6c8c9a8f82..6660912dda 100644 --- a/plugins/catalog-backend/api-report.md +++ b/plugins/catalog-backend/api-report.md @@ -32,7 +32,6 @@ import { Router } from 'express'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { ScmIntegrations } from '@backstage/integration'; import { UrlReader } from '@backstage/backend-common'; -import { UserEntity } from '@backstage/catalog-model'; import { Validators } from '@backstage/catalog-model'; // Warning: (ae-missing-release-tag) "AddLocationResult" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal) @@ -765,10 +764,6 @@ export class DefaultCatalogCollator implements DocumentCollator { }, ): DefaultCatalogCollator; // (undocumented) - protected getDocumentText(entity: Entity): string; - // (undocumented) - protected isUserEntity(entity: Entity): entity is UserEntity; - // (undocumented) protected locationTemplate: string; // (undocumented) readonly type: string; diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index 5458b9054a..751ea30832 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -81,16 +81,17 @@ export class DefaultCatalogCollator implements DocumentCollator { return formatted.toLowerCase(); } - protected isUserEntity(entity: Entity): entity is UserEntity { + private isUserEntity(entity: Entity): entity is UserEntity { return entity.kind === 'User'; } - protected getDocumentText(entity: Entity): string { + private getDocumentText(entity: Entity): string { let documentText = entity.metadata.description || ''; if (this.isUserEntity(entity)) { - if (entity.spec?.profile?.displayName && entity.metadata.description) { + if (entity.spec?.profile?.displayName && documentText) { // combine displayName and description - documentText = `${entity.spec?.profile?.displayName} : ${entity.metadata.description}`; + const displayName = entity.spec?.profile?.displayName; + documentText = displayName.concat(' : ', documentText); } else { documentText = entity.spec?.profile?.displayName || documentText; } From e5bff80f786841550d024968d7182d14d8bbdfdd Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Mon, 22 Nov 2021 11:44:54 +0000 Subject: [PATCH 5/6] uppercase kind Signed-off-by: Ainhoa Larumbe --- plugins/catalog-backend/src/search/DefaultCatalogCollator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index 751ea30832..0f7cdb62b4 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -82,7 +82,7 @@ export class DefaultCatalogCollator implements DocumentCollator { } private isUserEntity(entity: Entity): entity is UserEntity { - return entity.kind === 'User'; + return entity.kind.toUpperCase() === 'USER'; } private getDocumentText(entity: Entity): string { From 4167f6ed7ec80e0b34da2aee78aa537e5a4b4232 Mon Sep 17 00:00:00 2001 From: Ainhoa Larumbe Date: Mon, 22 Nov 2021 12:42:22 +0000 Subject: [PATCH 6/6] change uppercase method Signed-off-by: Ainhoa Larumbe --- plugins/catalog-backend/src/search/DefaultCatalogCollator.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts index 0f7cdb62b4..3e19b38ea6 100644 --- a/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts +++ b/plugins/catalog-backend/src/search/DefaultCatalogCollator.ts @@ -82,7 +82,7 @@ export class DefaultCatalogCollator implements DocumentCollator { } private isUserEntity(entity: Entity): entity is UserEntity { - return entity.kind.toUpperCase() === 'USER'; + return entity.kind.toLocaleUpperCase('en-US') === 'USER'; } private getDocumentText(entity: Entity): string {