Skip to content

Commit c319c27

Browse files
committed
feat(javascript): add search wrappers to lite client
1 parent 9d62976 commit c319c27

File tree

3 files changed

+35
-31
lines changed

3 files changed

+35
-31
lines changed

generators/src/main/java/com/algolia/codegen/AlgoliaJavascriptGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private void setDefaultGeneratorOptions() {
145145

146146
additionalProperties.put("apiName", apiName);
147147
additionalProperties.put("algoliaAgent", Helpers.capitalize(CLIENT));
148-
additionalProperties.put("isSearchClient", CLIENT.equals("search"));
148+
additionalProperties.put("isSearchClient", CLIENT.equals("search") || isAlgoliasearchClient);
149149
additionalProperties.put("isIngestionClient", CLIENT.equals("ingestion"));
150150
additionalProperties.put("isAlgoliasearchClient", isAlgoliasearchClient);
151151
additionalProperties.put("packageVersion", Helpers.getPackageJsonVersion(packageName));

templates/javascript/clients/client/api/helpers.mustache

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{{^isAlgoliasearchClient}}
12
/**
23
* Helper: Wait for a task to be published (completed) for a given `indexName` and `taskID`.
34
*
@@ -275,36 +276,6 @@ browseSynonyms(
275276
});
276277
},
277278

278-
/**
279-
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
280-
* Disclaimer: We don't assert that the parameters you pass to this method only contains `hits` requests to prevent impacting search performances, this helper is purely for typing purposes.
281-
*
282-
* @summary Search multiple indices for `hits`.
283-
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
284-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
285-
*/
286-
searchForHits<T>(
287-
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
288-
requestOptions?: RequestOptions
289-
): Promise<{results: Array<SearchResponse<T>>}> {
290-
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchResponse<T>>}>;
291-
},
292-
293-
/**
294-
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
295-
* Disclaimer: We don't assert that the parameters you pass to this method only contains `facets` requests to prevent impacting search performances, this helper is purely for typing purposes.
296-
*
297-
* @summary Search multiple indices for `facets`.
298-
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
299-
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
300-
*/
301-
searchForFacets(
302-
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
303-
requestOptions?: RequestOptions
304-
): Promise<{results: Array<SearchForFacetValuesResponse>}> {
305-
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchForFacetValuesResponse>}>;
306-
},
307-
308279
/**
309280
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
310281
*
@@ -476,4 +447,35 @@ async replaceAllObjects(
476447
});
477448

478449
return { copyOperationResponse, batchResponses, moveOperationResponse };
450+
},
451+
{{/isAlgoliasearchClient}}
452+
453+
/**
454+
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
455+
* Disclaimer: We don't assert that the parameters you pass to this method only contains `hits` requests to prevent impacting search performances, this helper is purely for typing purposes.
456+
*
457+
* @summary Search multiple indices for `hits`.
458+
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
459+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
460+
*/
461+
searchForHits<T>(
462+
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
463+
requestOptions?: RequestOptions
464+
): Promise<{results: Array<SearchResponse<T>>}> {
465+
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchResponse<T>>}>;
466+
},
467+
468+
/**
469+
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
470+
* Disclaimer: We don't assert that the parameters you pass to this method only contains `facets` requests to prevent impacting search performances, this helper is purely for typing purposes.
471+
*
472+
* @summary Search multiple indices for `facets`.
473+
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
474+
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
475+
*/
476+
searchForFacets(
477+
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
478+
requestOptions?: RequestOptions
479+
): Promise<{results: Array<SearchForFacetValuesResponse>}> {
480+
return this.search(searchMethodParams, requestOptions) as Promise<{results: Array<SearchForFacetValuesResponse>}>;
479481
},

templates/javascript/clients/client/model/clientMethodProps.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export type {{#lambda.titlecase}}{{nickname}}{{/lambda.titlecase}}Props = {
4747
{{/operations}}
4848

4949
{{#isSearchClient}}
50+
{{^isAlgoliasearchClient}}
5051
/**
5152
* The `browseObjects`, `browseRules`, `browseSynonyms` options.
5253
*/
@@ -175,6 +176,7 @@ export type ReplaceAllObjectsOptions = {
175176
*/
176177
batchSize?: number;
177178
}
179+
{{/isAlgoliasearchClient}}
178180
{{/isSearchClient}}
179181

180182
{{/apiInfo.apis.0}}

0 commit comments

Comments
 (0)