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..df001f3 100644 --- a/src/search/search.ts +++ b/src/search/search.ts @@ -55,10 +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 } } },