From 651c9d6800e1f9036ae2485b8e67a982417cc6bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20Adel=C3=B6w?= Date: Thu, 25 Aug 2022 14:38:50 +0200 Subject: [PATCH] index a null for large values as well MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fredrik Adelöw --- .changeset/gold-hounds-vanish.md | 5 +++++ .../src/stitching/buildEntitySearch.test.ts | 4 ++-- .../catalog-backend/src/stitching/buildEntitySearch.ts | 8 ++++++-- 3 files changed, 13 insertions(+), 4 deletions(-) create mode 100644 .changeset/gold-hounds-vanish.md diff --git a/.changeset/gold-hounds-vanish.md b/.changeset/gold-hounds-vanish.md new file mode 100644 index 0000000000..d221f0f5e9 --- /dev/null +++ b/.changeset/gold-hounds-vanish.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-catalog-backend': minor +--- + +The search index now does retain fields that have a very long value, but in the form of just a null. This makes it possible to at least filter for their existence. diff --git a/plugins/catalog-backend/src/stitching/buildEntitySearch.test.ts b/plugins/catalog-backend/src/stitching/buildEntitySearch.test.ts index e18f1c0c48..7364486f06 100644 --- a/plugins/catalog-backend/src/stitching/buildEntitySearch.test.ts +++ b/plugins/catalog-backend/src/stitching/buildEntitySearch.test.ts @@ -109,10 +109,10 @@ describe('buildEntitySearch', () => { expect(output).toEqual([]); }); - it('skips very large values', () => { + it('replaces very large values with null', () => { const input = [{ key: 'foo', value: 'a'.repeat(10000) }]; const output = mapToRows(input, 'eid'); - expect(output).toEqual([]); + expect(output).toEqual([{ entity_id: 'eid', key: 'foo', value: null }]); }); }); diff --git a/plugins/catalog-backend/src/stitching/buildEntitySearch.ts b/plugins/catalog-backend/src/stitching/buildEntitySearch.ts index 54e5ffa738..88a87df134 100644 --- a/plugins/catalog-backend/src/stitching/buildEntitySearch.ts +++ b/plugins/catalog-backend/src/stitching/buildEntitySearch.ts @@ -137,8 +137,12 @@ export function mapToRows(input: Kv[], entityId: string): DbSearchRow[] { result.push({ entity_id: entityId, key, value: null }); } else { const value = String(rawValue).toLocaleLowerCase('en-US'); - if (key.length <= MAX_KEY_LENGTH && value.length <= MAX_VALUE_LENGTH) { - result.push({ entity_id: entityId, key, value }); + if (key.length <= MAX_KEY_LENGTH) { + result.push({ + entity_id: entityId, + key, + value: value.length <= MAX_VALUE_LENGTH ? value : null, + }); } } }