Skip to content

Commit

Permalink
feat(specs): add recommend spec and client (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Nov 30, 2021
1 parent 47f71b9 commit ef603fb
Show file tree
Hide file tree
Showing 103 changed files with 1,849 additions and 320 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,26 @@
nvm use && yarn
```

## Generate clients based on the [`spec.yml` file](./search/specs.yml)
## Generate clients based on the [`specs`](./specs/)

### All clients

```bash
yarn generate
```

### Search client

```bash
yarn generate:search
```

### Recommend client

```bash
yarn generate:recommend
```

## Build generated clients

```bash
Expand Down
7 changes: 5 additions & 2 deletions clients/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ This folder hosts the generated clients and their utils.

## Generated clients

- [algoliasearch-client-javascript](./algoliasearch-client-javascript/): The Algolia JavaScript client.
### JavaScript

- [algoliasearch](./algoliasearch-client-javascript/algoliasearch/): The Algolia search client.
- [@algolia/recommend](./algoliasearch-client-javascript/recommend/): The Algolia recommend client.

## Utils

- [JavaScript](./utils/javascript/): The Algolia JavaScript utils.
- [JavaScript](./algoliasearch-client-javascript/utils/): The JavaScript clients utils.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// This is the entrypoint for the package
export * from './client-search/apis';
export * from './src/apis';
export * from './model/models';
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Record } from './record';
import { SearchResponseFacetsStats } from './searchResponseFacetsStats';
import { BaseSearchResponseFacetsStats } from './baseSearchResponseFacetsStats';

export type SearchResponse = {
export type BaseSearchResponse = {
/**
* If a search encounters an index that is being A/B tested, abTestID reports the ongoing A/B test ID.
*/
Expand Down Expand Up @@ -37,8 +36,7 @@ export type SearchResponse = {
/**
* Statistics for numerical facets.
*/
facets_stats?: { [key: string]: SearchResponseFacetsStats };
hits: Array<Record>;
facets_stats?: { [key: string]: BaseSearchResponseFacetsStats };
/**
* Set the number of hits per page.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SearchResponseFacetsStats = {
export type BaseSearchResponseFacetsStats = {
/**
* The minimum value in the result set.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type { RequestOptions } from '../utils/types';

export * from './baseIndexSettings';
export * from './baseSearchParams';
export * from './baseSearchResponse';
export * from './baseSearchResponseFacetsStats';
export * from './batchObject';
export * from './batchResponse';
export * from './errorBase';
Expand All @@ -16,10 +18,10 @@ export * from './rankingInfo';
export * from './rankingInfoMatchedGeoLocation';
export * from './record';
export * from './saveObjectResponse';
export * from './searchHits';
export * from './searchParams';
export * from './searchParamsAsString';
export * from './searchResponse';
export * from './searchResponseFacetsStats';
export * from './setSettingsResponse';
export * from './snippetResult';

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { Record } from './record';

export type SearchHits = {
hits?: Array<Record>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { BaseSearchResponse } from './baseSearchResponse';
import { BaseSearchResponseFacetsStats } from './baseSearchResponseFacetsStats';
import { Record } from './record';
import { SearchHits } from './searchHits';

export type SearchResponse = BaseSearchResponse & SearchHits;
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "algoliasearch-client-javascript",
"name": "@algolia/client-search",
"version": "5.0.0",
"description": "JavaScript client for algoliasearch-client-javascript",
"description": "JavaScript client for @algolia/client-search",
"repository": "algolia/algoliasearch-client-javascript",
"author": "Algolia",
"private": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
export * from './searchApi';
import { SearchApi } from './searchApi';

export class searchClient extends SearchApi {}

export * from '../utils/errors';
export { EchoRequester } from '../utils/requester/EchoRequester';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { SearchResponse } from '../model/searchResponse';
import { SetSettingsResponse } from '../model/setSettingsResponse';
import { ApiKeyAuth } from '../model/models';

export enum SearchApiApiKeys {
export enum SearchApiKeys {
apiKey,
appId,
}
Expand All @@ -30,8 +30,8 @@ export class SearchApi {
};

constructor(appId: string, apiKey: string, options?: { requester?: Requester; hosts?: Host[] }) {
this.setApiKey(SearchApiApiKeys.appId, appId);
this.setApiKey(SearchApiApiKeys.apiKey, apiKey);
this.setApiKey(SearchApiKeys.appId, appId);
this.setApiKey(SearchApiKeys.apiKey, apiKey);
this.transporter = new Transporter({
hosts: options?.hosts ?? this.getDefaultHosts(appId, apiKey),
baseHeaders: {
Expand Down Expand Up @@ -70,8 +70,8 @@ export class SearchApi {
this.transporter.setHosts(hosts);
}

public setApiKey(key: SearchApiApiKeys, value: string) {
this.authentications[SearchApiApiKeys[key]].apiKey = value;
public setApiKey(key: SearchApiKeys, value: string) {
this.authentications[SearchApiKeys[key]].apiKey = value;
}

private async sendRequest<TResponse>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
"typeRoots": ["node_modules/@types"],
"types": ["node"]
},
"include": ["client-search", "model", "api.ts"],
"include": ["src", "model", "api.ts"],
"exclude": ["dist", "node_modules"]
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export class Transporter {
timeoutsCount++;
}
/**
* Failures are individually send the logger, allowing
* Failures are individually sent to the logger, allowing
* the end user to debug / store stack frames even
* when a retry error does not happen.
*/
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions clients/algoliasearch-client-javascript/recommend/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules
typings
dist
build
.env
.vscode
3 changes: 3 additions & 0 deletions clients/algoliasearch-client-javascript/recommend/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is the entrypoint for the package
export * from './src/apis';
export * from './model/models';
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
export type BaseSearchParams = {
/**
* The text to search in the index.
*/
query: string;
/**
* Overrides the query parameter and performs a more generic search that can be used to find \"similar\" results.
*/
similarQuery?: string;
/**
* Filter the query with numeric, facet and/or tag filters.
*/
filters?: string;
/**
* Filter hits by facet value.
*/
facetFilters?: Array<string>;
/**
* Create filters for ranking purposes, where records that match the filter are ranked higher, or lower in the case of a negative optional filter.
*/
optionalFilters?: Array<string>;
/**
* Filter on numeric attributes.
*/
numericFilters?: Array<string>;
/**
* Filter hits by tags.
*/
tagFilters?: Array<string>;
/**
* Determines how to calculate the total score for filtering.
*/
sumOrFiltersScores?: boolean;
/**
* Retrieve facets and their facet values.
*/
facets?: Array<string>;
/**
* Maximum number of facet values to return for each facet during a regular search.
*/
maxValuesPerFacet?: number;
/**
* Force faceting to be applied after de-duplication (via the Distinct setting).
*/
facetingAfterDistinct?: boolean;
/**
* Controls how facet values are fetched.
*/
sortFacetValuesBy?: string;
/**
* Specify the page to retrieve.
*/
page?: number;
/**
* Specify the offset of the first hit to return.
*/
offset?: number;
/**
* Set the number of hits to retrieve (used only with offset).
*/
length?: number;
/**
* Search for entries around a central geolocation, enabling a geo search within a circular area.
*/
aroundLatLng?: string;
/**
* Search for entries around a given location automatically computed from the requester’s IP address.
*/
aroundLatLngViaIP?: boolean;
/**
* Define the maximum radius for a geo search (in meters).
*/
aroundRadius?: number | string | null;
/**
* Precision of geo search (in meters), to add grouping by geo location to the ranking formula.
*/
aroundPrecision?: number;
/**
* Minimum radius (in meters) used for a geo search when aroundRadius is not set.
*/
minimumAroundRadius?: number;
/**
* Search inside a rectangular area (in geo coordinates).
*/
insideBoundingBox?: Array<number>;
/**
* Search inside a polygon (in geo coordinates).
*/
insidePolygon?: Array<number>;
/**
* This parameter changes the default values of certain parameters and settings that work best for a natural language query, such as ignorePlurals, removeStopWords, removeWordsIfNoResults, analyticsTags and ruleContexts. These parameters and settings work well together when the query is formatted in natural language instead of keywords, for example when your user performs a voice search.
*/
naturalLanguages?: Array<string>;
/**
* Enables contextual rules.
*/
ruleContexts?: Array<string>;
/**
* Define the impact of the Personalization feature.
*/
personalizationImpact?: number;
/**
* Associates a certain user token with the current search.
*/
userToken?: string;
/**
* Retrieve detailed ranking information.
*/
getRankingInfo?: boolean;
/**
* Enable the Click Analytics feature.
*/
clickAnalytics?: boolean;
/**
* Whether the current query will be taken into account in the Analytics.
*/
analytics?: boolean;
/**
* List of tags to apply to the query for analytics purposes.
*/
analyticsTags?: Array<string>;
/**
* Whether to include or exclude a query from the processing-time percentile computation.
*/
percentileComputation?: boolean;
/**
* Whether this search should participate in running AB tests.
*/
enableABTest?: boolean;
/**
* Whether this search should use AI Re-Ranking.
*/
enableReRanking?: boolean;
};
Loading

0 comments on commit ef603fb

Please sign in to comment.