From 8e2adeb309b4646077c83471ca3e64891cc6b621 Mon Sep 17 00:00:00 2001 From: Alfred Godoy Date: Mon, 16 Feb 2026 21:22:46 +0100 Subject: [PATCH 1/2] Adds env configuration for disabling fuzziness in search --- readme.md | 1 + src/lib/Config.ts | 7 +++++++ src/search/search.ts | 5 ++--- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 247c93b..0fe03d6 100644 --- a/readme.md +++ b/readme.md @@ -532,6 +532,7 @@ The environment variables used to configure the application: - `IIIF_SERVER_ATTRIBUTION`: Attribution to add to the IIIF manifests - `IIIF_SERVER_BASE_URL`: The public base URL of the application - `IIIF_SERVER_VIEWER_URL`: The URL of the main IIIF viewer to use (the manifest URI will be added to this URL) +- `IIIF_SERVER_SEARCH_MODE`: The search mode to use: `fuzzy` (default) for fuzzy matching or `phrase` for exact phrase matching - `IIIF_SERVER_HOT_FOLDER_PATH`: The path to the hot folder where new collections to be indexed are placed - `IIIF_SERVER_HOT_FOLDER_PATTERN`: The pattern of a file in the root of a new collection to trigger indexing - `IIIF_SERVER_DATA_ROOT_PATH`: The root path of the data storage diff --git a/src/lib/Config.ts b/src/lib/Config.ts index d3347b1..18cc9b3 100644 --- a/src/lib/Config.ts +++ b/src/lib/Config.ts @@ -34,6 +34,7 @@ export interface Config { imageTierSeparator: string; maxTasksPerWorker: number; maxSearchResults: number; + searchMode: 'fuzzy' | 'phrase'; services: string[]; secret: string; accessToken: string; @@ -161,6 +162,12 @@ const config: Config = { return (maxSearchResults > 0) ? maxSearchResults : 5000; })(), + searchMode: (_ => { + const mode = process.env.IIIF_SERVER_SEARCH_MODE?.toLowerCase(); + if (mode === 'phrase') return 'phrase' as const; + return 'fuzzy' as const; + })(), + services: (_ => { if (!process.env.IIIF_SERVER_SERVICES || (process.env.IIIF_SERVER_SERVICES === 'null')) throw new Error('Services to run are not defined'); diff --git a/src/search/search.ts b/src/search/search.ts index 846f7f0..f657fc3 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -55,11 +55,10 @@ async function search(query: string, filters: { [field: string]: string | undefi query: { bool: { must: { - [isPhraseMatch ? 'match_phrase' : 'match']: { + [isPhraseMatch || config.searchMode === 'phrase' ? 'match_phrase' : 'match']: { text: { query, - fuzziness: !isPhraseMatch ? 'AUTO' : undefined - } + fuzziness: !isPhraseMatch && config.searchMode === 'fuzzy' ? 'AUTO' : undefined } }, should: undefined, From 29648b2051bbfb2b98270e8014b89498f3e7d931 Mon Sep 17 00:00:00 2001 From: Alfred Godoy Date: Thu, 19 Feb 2026 09:58:03 +0100 Subject: [PATCH 2/2] intentation / closing bracket fix --- src/search/search.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/search/search.ts b/src/search/search.ts index f657fc3..df001f3 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -59,6 +59,7 @@ async function search(query: string, filters: { [field: string]: string | undefi text: { query, fuzziness: !isPhraseMatch && config.searchMode === 'fuzzy' ? 'AUTO' : undefined + } } }, should: undefined,