From 63b04bd856b7b713f49e0ae99c8be0fd45b4ca0f Mon Sep 17 00:00:00 2001 From: Ben Silverman Date: Fri, 6 Dec 2024 13:00:53 -0500 Subject: [PATCH 1/2] Allow default sort typesense configuration (#304) --- packages/core-data/src/types/RuntimeConfig.js | 3 ++- packages/core-data/src/utils/Peripleo.js | 3 ++- packages/core-data/src/utils/Typesense.js | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/core-data/src/types/RuntimeConfig.js b/packages/core-data/src/types/RuntimeConfig.js index 68621d09..c89ca347 100644 --- a/packages/core-data/src/types/RuntimeConfig.js +++ b/packages/core-data/src/types/RuntimeConfig.js @@ -34,7 +34,8 @@ export type RuntimeConfig = { facets?: { include?: string[], exclude?: string[] - } + }, + default_sort?: string }, core_data: { project_ids: number[], diff --git a/packages/core-data/src/utils/Peripleo.js b/packages/core-data/src/utils/Peripleo.js index 02dea74e..27b85928 100644 --- a/packages/core-data/src/utils/Peripleo.js +++ b/packages/core-data/src/utils/Peripleo.js @@ -30,7 +30,8 @@ const normalize = (config: RuntimeConfig) => ({ typesense: { ...config.typesense, host: config.typesense.host || '443', - protocol: config.typesense.protocol || 'https' + protocol: config.typesense.protocol || 'https', + sort_by: `_text_match:desc${config.typesense.default_sort ? `,${config.typesense.default_sort}:asc` : ''}` }, core_data: { ...config.core_data, diff --git a/packages/core-data/src/utils/Typesense.js b/packages/core-data/src/utils/Typesense.js index f44be56c..a937a07f 100644 --- a/packages/core-data/src/utils/Typesense.js +++ b/packages/core-data/src/utils/Typesense.js @@ -14,7 +14,8 @@ type TypesenseConfig = { limit: number, port: number, protocol: string, - query_by: string + query_by: string, + default_sort?: string }; const ATTRIBUTE_DELIMITER = '.'; @@ -100,7 +101,8 @@ const createTypesenseAdapter = (config: TypesenseConfig, options = {}) => ( geoLocationField: 'coordinates', additionalSearchParameters: { query_by: config.query_by, - limit: config.limit || 250 + limit: config.limit || 250, + sort_by: `_text_match:desc${config.default_sort ? `,${config.default_sort}:asc` : ''}` }, ...options }) From ef586f2cdc3ca37d2a2f77bd5a0a4e0eb1f27cef Mon Sep 17 00:00:00 2001 From: Ben Silverman Date: Fri, 6 Dec 2024 13:28:38 -0500 Subject: [PATCH 2/2] Use pre-normalized sort_by in Typesense config (#304) --- packages/core-data/src/utils/Typesense.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/core-data/src/utils/Typesense.js b/packages/core-data/src/utils/Typesense.js index a937a07f..92c26786 100644 --- a/packages/core-data/src/utils/Typesense.js +++ b/packages/core-data/src/utils/Typesense.js @@ -15,7 +15,7 @@ type TypesenseConfig = { port: number, protocol: string, query_by: string, - default_sort?: string + sort_by: string }; const ATTRIBUTE_DELIMITER = '.'; @@ -102,7 +102,7 @@ const createTypesenseAdapter = (config: TypesenseConfig, options = {}) => ( additionalSearchParameters: { query_by: config.query_by, limit: config.limit || 250, - sort_by: `_text_match:desc${config.default_sort ? `,${config.default_sort}:asc` : ''}` + sort_by: config.sort_by }, ...options })