Skip to content

Commit

Permalink
feat: Consistent search response (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
adilansari authored Oct 14, 2022
1 parent 5669e73 commit 068c6c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,7 @@ export abstract class ReadOnlyCollection<T extends TigrisCollectionType> impleme
* @param request - Search query to execute
* @param options - Optional settings for search
*/
search(
request: SearchRequest<T>,
options?: SearchRequestOptions
): Promise<SearchResult<T> | undefined> {
search(request: SearchRequest<T>, options?: SearchRequestOptions): Promise<SearchResult<T>> {
return new Promise<SearchResult<T>>((resolve, reject) => {
const searchRequest = Utility.createProtoSearchRequest(
this.db,
Expand All @@ -184,7 +181,7 @@ export abstract class ReadOnlyCollection<T extends TigrisCollectionType> impleme
resolve(searchResult);
});
stream.on("error", (error) => reject(error));
stream.on("end", () => resolve(undefined));
stream.on("end", () => resolve(SearchResult.empty));
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ export class SearchResult<T> {
this._meta = meta;
}

static get empty(): SearchResult<never> {
return new SearchResult([], new Map(), undefined);
}

/**
* @returns matched documents as immutable list
* @readonly
Expand Down

0 comments on commit 068c6c0

Please sign in to comment.