Skip to content

Commit

Permalink
feat(javascript): add search wrappers to lite client (generated)
Browse files Browse the repository at this point in the history
algolia/api-clients-automation#3556

Co-authored-by: algolia-bot <[email protected]>
Co-authored-by: Clément Vannicatte <[email protected]>
  • Loading branch information
algolia-bot and shortcuts committed Aug 20, 2024
1 parent a1b2456 commit a9964a2
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 39 deletions.
10 changes: 5 additions & 5 deletions bundlesize.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"files": [
{
"path": "packages/algoliasearch/dist/algoliasearch.umd.js",
"maxSize": "8.65KB"
"maxSize": "9.20KB"
},
{
"path": "packages/algoliasearch/dist/lite/lite.umd.js",
"maxSize": "3.90KB"
"maxSize": "3.95KB"
},
{
"path": "packages/client-abtesting/dist/client-abtesting.umd.js",
"maxSize": "4.05KB"
"maxSize": "4.10KB"
},
{
"path": "packages/client-analytics/dist/client-analytics.umd.js",
Expand All @@ -30,11 +30,11 @@
},
{
"path": "packages/client-search/dist/client-search.umd.js",
"maxSize": "7.05KB"
"maxSize": "7.15KB"
},
{
"path": "packages/ingestion/dist/ingestion.umd.js",
"maxSize": "5.20KB"
"maxSize": "5.90KB"
},
{
"path": "packages/monitoring/dist/monitoring.umd.js",
Expand Down
35 changes: 35 additions & 0 deletions packages/algoliasearch/lite/src/liteClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import type {
} from '../model/clientMethodProps';
import type { GetRecommendationsParams } from '../model/getRecommendationsParams';
import type { GetRecommendationsResponse } from '../model/getRecommendationsResponse';
import type { SearchForFacetValuesResponse } from '../model/searchForFacetValuesResponse';
import type { SearchMethodParams } from '../model/searchMethodParams';
import type { SearchResponse } from '../model/searchResponse';
import type { SearchResponses } from '../model/searchResponses';

export const apiClientVersion = '5.0.2';
Expand Down Expand Up @@ -125,6 +127,39 @@ export function createLiteClient({
transporter.algoliaAgent.add({ segment, version });
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
* 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.
*
* @summary Search multiple indices for `hits`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForHits<T>(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{ results: Array<SearchResponse<T>> }> {
return this.search(searchMethodParams, requestOptions) as Promise<{
results: Array<SearchResponse<T>>;
}>;
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
* 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.
*
* @summary Search multiple indices for `facets`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacets(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{ results: SearchForFacetValuesResponse[] }> {
return this.search(searchMethodParams, requestOptions) as Promise<{
results: SearchForFacetValuesResponse[];
}>;
},
/**
* This method allow you to send requests to the Algolia REST API.
*
Expand Down
68 changes: 34 additions & 34 deletions packages/client-search/src/searchClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,40 +505,6 @@ export function createSearchClient({
});
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
* 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.
*
* @summary Search multiple indices for `hits`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForHits<T>(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{ results: Array<SearchResponse<T>> }> {
return this.search(searchMethodParams, requestOptions) as Promise<{
results: Array<SearchResponse<T>>;
}>;
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
* 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.
*
* @summary Search multiple indices for `facets`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacets(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{ results: SearchForFacetValuesResponse[] }> {
return this.search(searchMethodParams, requestOptions) as Promise<{
results: SearchForFacetValuesResponse[];
}>;
},

/**
* Helper: Chunks the given `objects` list in subset of 1000 elements max in order to make it fit in `batch` requests.
*
Expand Down Expand Up @@ -725,6 +691,40 @@ export function createSearchClient({

return { copyOperationResponse, batchResponses, moveOperationResponse };
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia records (hits) and not facets.
* 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.
*
* @summary Search multiple indices for `hits`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForHits<T>(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{ results: Array<SearchResponse<T>> }> {
return this.search(searchMethodParams, requestOptions) as Promise<{
results: Array<SearchResponse<T>>;
}>;
},

/**
* Helper: calls the `search` method but with certainty that we will only request Algolia facets and not records (hits).
* 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.
*
* @summary Search multiple indices for `facets`.
* @param searchMethodParams - Query requests and strategies. Results will be received in the same order as the queries.
* @param requestOptions - The requestOptions to send along with the query, they will be merged with the transporter requestOptions.
*/
searchForFacets(
searchMethodParams: LegacySearchMethodProps | SearchMethodParams,
requestOptions?: RequestOptions
): Promise<{ results: SearchForFacetValuesResponse[] }> {
return this.search(searchMethodParams, requestOptions) as Promise<{
results: SearchForFacetValuesResponse[];
}>;
},
/**
* Creates a new API key with specific permissions and restrictions.
*
Expand Down

0 comments on commit a9964a2

Please sign in to comment.