From 419397e3bf4a096c6a3fcfc9e70d26e15ab9563f Mon Sep 17 00:00:00 2001 From: andrepat0 Date: Tue, 24 Sep 2024 11:00:41 +0200 Subject: [PATCH 1/2] feat: added pagination search and filter apis --- src/engine/search.ts | 60 ++++++++++++++++++++++++++++++++++++++++++++ src/types.ts | 9 +++++++ 2 files changed, 69 insertions(+) diff --git a/src/engine/search.ts b/src/engine/search.ts index 3c6c0d5..964f9ca 100644 --- a/src/engine/search.ts +++ b/src/engine/search.ts @@ -23,6 +23,66 @@ export default (apiUrl: string) => ({ matches: SearchMatches[]; } >, + + + /** + * + * @param sessionId + * @param pageIndex + * @param pageSize + * @param query + * @returns + */ + searchMemoryPaginated: async ( + sessionId: string, + pageIndex: number, + pageSize: number, + query?: SearchQuery + ) => + apiFetcher(`/Search/${sessionId}/${pageIndex}/${pageSize}`, { + method: 'POST', + body: query, + apiUrl, + }) as Promise< + ResponseSpec & { + count: number; + matches: SearchMatches[]; + } + >, + + /** + * Searches for matching Memory objects using the same algorithm employed in the Text Entered event of the R1 state of the Dialog State Machine. + * @param {string} sessionId The session ID + * @param {SearchQuery} query Search query params + */ +filterMemories: async (sessionId: string, query?: SearchQuery) => + apiFetcher(`/FilterMemories/${sessionId}`, { + method: 'POST', + body: query, + apiUrl, + }) as Promise< + ResponseSpec & { + count: number; + matches: SearchMatches[]; + } + >, + +filterMemoriesPaginated: async ( + sessionId: string, + pageIndex: number, + pageSize: number, + query?: SearchQuery, +) => + apiFetcher(`/FilterMemories/${sessionId}/${pageIndex}/${pageSize}`, { + method: 'POST', + body: query, + apiUrl:, + }) as Promise< + ResponseSpec & { + count: number; + matches: SearchMatches[]; + } + >, /** * Picks up to 5 random Memory objects using the same algorithm employed in the diff --git a/src/types.ts b/src/types.ts index 2e5ac6e..0cfca3b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -533,6 +533,9 @@ export declare type Asset = { }; export type SearchQuery = { + + + /** * @type {string} * Search query. If omitted, either a Date or a Place must be set. Used only for Search, ignored for Random picking and Memory Hints. @@ -602,6 +605,12 @@ export type SearchQuery = { */ excludedMemoryIDs?: string[]; + /** + * @type {number=0} + * Index of the first Memory to return. Used for pagination. + */ + startFrom?: number; + /** * @type {?number=5} * Optional number of results. If omitted defaults to 5. From 95bcf011079c0f9cb97dda5595c5086f43f2e27a Mon Sep 17 00:00:00 2001 From: nzambello Date: Wed, 25 Sep 2024 08:43:56 +0300 Subject: [PATCH 2/2] chore: fix typo + format code --- src/engine/search.ts | 119 ++++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 57 deletions(-) diff --git a/src/engine/search.ts b/src/engine/search.ts index 964f9ca..7f02e5a 100644 --- a/src/engine/search.ts +++ b/src/engine/search.ts @@ -23,66 +23,71 @@ export default (apiUrl: string) => ({ matches: SearchMatches[]; } >, - - /** - * - * @param sessionId - * @param pageIndex - * @param pageSize - * @param query - * @returns - */ - searchMemoryPaginated: async ( - sessionId: string, - pageIndex: number, - pageSize: number, - query?: SearchQuery - ) => - apiFetcher(`/Search/${sessionId}/${pageIndex}/${pageSize}`, { - method: 'POST', - body: query, - apiUrl, - }) as Promise< - ResponseSpec & { - count: number; - matches: SearchMatches[]; - } - >, + /** + * Searches for matching Memory objects using the same algorithm employed in the Text Entered event of the R1 state of the Dialog State Machine. + * @param {string} sessionId The session ID + * @param {number} pageIndex The page index + * @param {number} pageSize The page size + * @param {SearchQuery} query Search query params + */ + searchMemoryPaginated: async ( + sessionId: string, + pageIndex: number, + pageSize: number, + query?: SearchQuery + ) => + apiFetcher(`/Search/${sessionId}/${pageIndex}/${pageSize}`, { + method: 'POST', + body: query, + apiUrl, + }) as Promise< + ResponseSpec & { + count: number; + matches: SearchMatches[]; + } + >, - /** - * Searches for matching Memory objects using the same algorithm employed in the Text Entered event of the R1 state of the Dialog State Machine. - * @param {string} sessionId The session ID - * @param {SearchQuery} query Search query params - */ -filterMemories: async (sessionId: string, query?: SearchQuery) => - apiFetcher(`/FilterMemories/${sessionId}`, { - method: 'POST', - body: query, - apiUrl, - }) as Promise< - ResponseSpec & { - count: number; - matches: SearchMatches[]; - } - >, + /** + * Filters Memory objects + * @param {string} sessionId The session ID + * @param {SearchQuery} query Search query params + */ + filterMemories: async (sessionId: string, query?: SearchQuery) => + apiFetcher(`/FilterMemories/${sessionId}`, { + method: 'POST', + body: query, + apiUrl, + }) as Promise< + ResponseSpec & { + count: number; + matches: SearchMatches[]; + } + >, -filterMemoriesPaginated: async ( - sessionId: string, - pageIndex: number, - pageSize: number, - query?: SearchQuery, -) => - apiFetcher(`/FilterMemories/${sessionId}/${pageIndex}/${pageSize}`, { - method: 'POST', - body: query, - apiUrl:, - }) as Promise< - ResponseSpec & { - count: number; - matches: SearchMatches[]; - } - >, + /** + * Filters Memory objects, with pagination + * @param {string} sessionId The session ID + * @param {number} pageIndex The page index + * @param {number} pageSize The page size + * @param {SearchQuery} query Search query params + */ + filterMemoriesPaginated: async ( + sessionId: string, + pageIndex: number, + pageSize: number, + query?: SearchQuery + ) => + apiFetcher(`/FilterMemories/${sessionId}/${pageIndex}/${pageSize}`, { + method: 'POST', + body: query, + apiUrl, + }) as Promise< + ResponseSpec & { + count: number; + matches: SearchMatches[]; + } + >, /** * Picks up to 5 random Memory objects using the same algorithm employed in the