index a null for large values as well

Signed-off-by: Fredrik Adelöw <freben@gmail.com>
This commit is contained in:
Fredrik Adelöw
2022-08-25 14:38:50 +02:00
parent cd19357e4c
commit 651c9d6800
3 changed files with 13 additions and 4 deletions
+5
View File
@@ -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.
@@ -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 }]);
});
});
@@ -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,
});
}
}
}