From e3f163877dbefa07fb7d4983154ab88b532e079d Mon Sep 17 00:00:00 2001 From: Daniel von Atzigen Date: Wed, 12 Jun 2024 15:13:33 +0200 Subject: [PATCH] Fix search by field not working --- .../src/app/search/asset-search-service.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/apps/server-asset-sg/src/app/search/asset-search-service.ts b/apps/server-asset-sg/src/app/search/asset-search-service.ts index 652438be..88d9cd90 100644 --- a/apps/server-asset-sg/src/app/search/asset-search-service.ts +++ b/apps/server-asset-sg/src/app/search/asset-search-service.ts @@ -133,16 +133,9 @@ export class AssetSearchService { query: { bool: { should: [ - { - multi_match: { - query, - fields: scope, - fuzziness: 'AUTO', - }, - }, { query_string: { - query: `*${query}*`, + query: normalizeFieldQuery(query), fields: scope, }, }, @@ -337,3 +330,11 @@ export class AssetSearchService { } } } + +const normalizeFieldQuery = (query: string): string => ( + query + .replace(/title(_*)public:/i, 'titlePublic:') + .replace(/title(_*)original:/i, 'titleOriginal:') + .replace(/contact(_*)ame:/i, 'contactNames:') + .replace(/sgs(_*)id:/i, 'sgsId:') +);