diff --git a/src/engine/search.ts b/src/engine/search.ts index 3c6c0d5..7f02e5a 100644 --- a/src/engine/search.ts +++ b/src/engine/search.ts @@ -24,6 +24,71 @@ export default (apiUrl: string) => ({ } >, + /** + * 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[]; + } + >, + + /** + * 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[]; + } + >, + + /** + * 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 * Timeout event of the R1 state of the Dialog State Machine. diff --git a/src/types.ts b/src/types.ts index a3f4a90..25c0fe3 100644 --- a/src/types.ts +++ b/src/types.ts @@ -595,6 +595,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. @@ -664,6 +667,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.