Skip to content

Commit 36574f6

Browse files
authored
feat: query-suggestions client APIC-202 (#74)
1 parent e610fbf commit 36574f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2304
-42
lines changed

.github/actions/cache/action.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ runs:
2525
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/recommend/dist
2626
key: ${{ runner.os }}-js-client-recommend-${{ hashFiles('clients/algoliasearch-client-javascript/recommend/**') }}
2727

28+
- name: Restore built JavaScript query-suggestions client
29+
if: ${{ inputs.job == 'cts' }}
30+
uses: actions/cache@v2
31+
with:
32+
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/client-query-suggestions/dist
33+
key: ${{ runner.os }}-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/client-query-suggestions/**') }}
34+
2835
- name: Restore built JavaScript personalization client
2936
if: ${{ inputs.job == 'cts' }}
3037
uses: actions/cache@v2

.github/actions/setup/action.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ runs:
3131
echo "::set-output name=COMMON_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/common | wc -l)"
3232
echo "::set-output name=SEARCH_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/search | wc -l)"
3333
echo "::set-output name=RECOMMEND_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/recommend | wc -l)"
34-
echo "::set-output name=QS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/query_suggestions | wc -l)"
34+
echo "::set-output name=QUERY_SUGGESTIONS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/query-suggestions | wc -l)"
3535
echo "::set-output name=PERSO_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/personalization | wc -l)"
3636
echo "::set-output name=INSIGHTS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/insights | wc -l)"
3737
echo "::set-output name=ANALYTICS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/analytics | wc -l)"
@@ -44,6 +44,7 @@ runs:
4444
echo "::set-output name=JS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript | wc -l)"
4545
echo "::set-output name=JS_SEARCH_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-search | wc -l)"
4646
echo "::set-output name=JS_RECOMMEND_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/recommend | wc -l)"
47+
echo "::set-output name=JS_QUERY_SUGGESTIONS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-query-suggestions | wc -l)"
4748
echo "::set-output name=JS_PERSO_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-personalization | wc -l)"
4849
echo "::set-output name=JS_ANALYTICS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-analytics | wc -l)"
4950
echo "::set-output name=JS_INSIGHTS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-insights | wc -l)"
@@ -60,9 +61,9 @@ outputs:
6061
RUN_SPECS_RECOMMEND:
6162
description: Determine if the `specs_recommend` job should run
6263
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.RECOMMEND_SPECS_CHANGED > 0 }}
63-
RUN_SPECS_QS:
64-
description: Determine if the `specs_qs` job should run
65-
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.QS_SPECS_CHANGED > 0 }}
64+
RUN_SPECS_QUERY_SUGGESTIONS:
65+
description: Determine if the `specs_query_suggestions` job should run
66+
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.QUERY_SUGGESTIONS_SPECS_CHANGED > 0 }}
6667
RUN_SPECS_PERSO:
6768
description: Determine if the `specs_perso` job should run
6869
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.PERSO_SPECS_CHANGED > 0 }}
@@ -83,6 +84,9 @@ outputs:
8384
RUN_JS_CLIENT_RECOMMEND:
8485
description: Determine if the `client_javascript_recommend` job should run
8586
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.RECOMMEND_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JS_RECOMMEND_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 }}
87+
RUN_JS_CLIENT_QUERY_SUGGESTIONS:
88+
description: Determine if the `client_javascript_query_suggestions` job should run
89+
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.QUERY_SUGGESTIONS_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JS_QUERY_SUGGESTIONS_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 }}
8690
RUN_JS_CLIENT_PERSO:
8791
description: Determine if the `client_javascript_perso` job should run
8892
value: ${{ github.ref == 'refs/heads/main' || steps.diff.outputs.GITHUB_ACTIONS_CHANGED > 0 || steps.diff.outputs.COMMON_SPECS_CHANGED > 0 || steps.diff.outputs.PERSO_SPECS_CHANGED > 0 || steps.diff.outputs.SCRIPTS_CHANGED > 0 || steps.diff.outputs.JS_PERSO_CLIENT_CHANGED > 0 || steps.diff.outputs.JS_TEMPLATE_CHANGED > 0 }}

.github/workflows/check.yml

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ jobs:
2828
outputs:
2929
RUN_SPECS_SEARCH: ${{ steps.setup.outputs.RUN_SPECS_SEARCH }}
3030
RUN_SPECS_RECOMMEND: ${{ steps.setup.outputs.RUN_SPECS_RECOMMEND }}
31-
RUN_SPECS_QS: ${{ steps.setup.outputs.RUN_SPECS_QS }}
31+
RUN_SPECS_QUERY_SUGGESTIONS: ${{ steps.setup.outputs.RUN_SPECS_QUERY_SUGGESTIONS }}
3232
RUN_SPECS_PERSO: ${{ steps.setup.outputs.RUN_SPECS_PERSO }}
3333
RUN_SPECS_INSIGHTS: ${{ steps.setup.outputs.RUN_SPECS_INSIGHTS }}
3434
RUN_SPECS_ANALYTICS: ${{ steps.setup.outputs.RUN_SPECS_ANALYTICS }}
3535
RUN_SPECS_AB: ${{ steps.setup.outputs.RUN_SPECS_AB }}
3636

3737
RUN_JS_CLIENT_SEARCH: ${{ steps.setup.outputs.RUN_JS_CLIENT_SEARCH }}
3838
RUN_JS_CLIENT_RECOMMEND: ${{ steps.setup.outputs.RUN_JS_CLIENT_RECOMMEND }}
39+
RUN_JS_CLIENT_QUERY_SUGGESTIONS: ${{ steps.setup.outputs.RUN_JS_CLIENT_QUERY_SUGGESTIONS }}
3940
RUN_JS_CLIENT_PERSO: ${{ steps.setup.outputs.RUN_JS_CLIENT_PERSO }}
4041
RUN_JS_CLIENT_ANALYTICS: ${{ steps.setup.outputs.RUN_JS_CLIENT_ANALYTICS }}
4142
RUN_JS_CLIENT_INSIGHTS: ${{ steps.setup.outputs.RUN_JS_CLIENT_INSIGHTS }}
@@ -76,6 +77,22 @@ jobs:
7677
- name: Lint recommend specs
7778
run: yarn eslint --ext=yml specs/recommend
7879

80+
specs_query_suggestions:
81+
runs-on: ubuntu-20.04
82+
needs: setup
83+
if: ${{ always() && needs.setup.outputs.RUN_SPECS_QUERY_SUGGESTIONS == 'true' }}
84+
steps:
85+
- uses: actions/checkout@v2
86+
87+
- name: Restore cache
88+
uses: ./.github/actions/cache
89+
90+
- name: Checking query-suggestions specs
91+
run: yarn build:specs query-suggestions
92+
93+
- name: Lint query-suggestions specs
94+
run: yarn eslint --ext=yml specs/query-suggestions
95+
7996
specs_perso:
8097
runs-on: ubuntu-20.04
8198
needs: setup
@@ -174,6 +191,31 @@ jobs:
174191
if: steps.cache.outputs.cache-hit != 'true'
175192
run: yarn build:clients javascript recommend
176193

194+
client_javascript_query_suggestions:
195+
runs-on: ubuntu-20.04
196+
needs: [specs_query_suggestions]
197+
if: ${{ always() && needs.setup.outputs.RUN_JS_CLIENT_QUERY_SUGGESTIONS == 'true' }}
198+
steps:
199+
- uses: actions/checkout@v2
200+
201+
- name: Restore cache
202+
uses: ./.github/actions/cache
203+
204+
- name: Cache query-suggestions client
205+
id: cache
206+
uses: actions/cache@v2
207+
with:
208+
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/client-query-suggestions/dist
209+
key: ${{ runner.os }}-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/client-query-suggestions/**') }}
210+
211+
- name: Generate query-suggestions client
212+
if: steps.cache.outputs.cache-hit != 'true'
213+
run: yarn generate javascript query-suggestions
214+
215+
- name: Build query-suggestions client
216+
if: steps.cache.outputs.cache-hit != 'true'
217+
run: yarn build:clients javascript query-suggestions
218+
177219
client_javascript_perso:
178220
runs-on: ubuntu-20.04
179221
needs: [specs_perso]
@@ -281,6 +323,7 @@ jobs:
281323
needs:
282324
- client_javascript_search
283325
- client_javascript_recommend
326+
- client_javascript_query_suggestions
284327
- client_javascript_perso
285328
- client_javascript_analytics
286329
- client_javascript_insights
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
dist
3+
.openapi-generator
4+
.env
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# OpenAPI Generator Ignore
2+
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
3+
4+
git_push.sh
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This is the entrypoint for the package
2+
export * from './src/apis';
3+
export * from './model/models';
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* Error.
3+
*/
4+
export type ErrorBase = {
5+
message?: string;
6+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type IndexName = {
2+
/**
3+
* Index name to target.
4+
*/
5+
indexName: string;
6+
};
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type LogFile = {
2+
/**
3+
* Date and time of creation of the record.
4+
*/
5+
timestamp: Date;
6+
/**
7+
* Type of the record, can be one of three values (INFO, SKIP or ERROR).
8+
*/
9+
level: LogFileLevel;
10+
/**
11+
* Detailed description of what happened.
12+
*/
13+
message: string;
14+
/**
15+
* Indicates the hierarchy of the records. For example, a record with contextLevel=1 belongs to a preceding record with contextLevel=0.
16+
*/
17+
contextLevel: number;
18+
};
19+
20+
export type LogFileLevel = 'ERROR' | 'INFO' | 'SKIP';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* eslint-disable no-param-reassign */
2+
import type { RequestOptions } from '../utils/types';
3+
4+
export * from './errorBase';
5+
export * from './indexName';
6+
export * from './logFile';
7+
export * from './querySuggestionsIndex';
8+
export * from './querySuggestionsIndexParam';
9+
export * from './querySuggestionsIndexWithIndexParam';
10+
export * from './sourceIndex';
11+
export * from './sourceIndexExternal';
12+
export * from './sourceIndexWithReplicas';
13+
export * from './status';
14+
export * from './sucessResponse';
15+
16+
export interface Authentication {
17+
/**
18+
* Apply authentication settings to header and query params.
19+
*/
20+
applyToRequest: (requestOptions: RequestOptions) => Promise<void> | void;
21+
}
22+
23+
export class ApiKeyAuth implements Authentication {
24+
apiKey: string = '';
25+
26+
constructor(private location: string, private paramName: string) {}
27+
28+
applyToRequest(requestOptions: RequestOptions): void {
29+
if (this.location === 'query') {
30+
requestOptions.queryParameters[this.paramName] = this.apiKey;
31+
} else if (
32+
this.location === 'header' &&
33+
requestOptions &&
34+
requestOptions.headers
35+
) {
36+
requestOptions.headers[this.paramName] = this.apiKey;
37+
} else if (
38+
this.location === 'cookie' &&
39+
requestOptions &&
40+
requestOptions.headers
41+
) {
42+
if (requestOptions.headers.Cookie) {
43+
requestOptions.headers.Cookie += `; ${
44+
this.paramName
45+
}=${encodeURIComponent(this.apiKey)}`;
46+
} else {
47+
requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent(
48+
this.apiKey
49+
)}`;
50+
}
51+
}
52+
}
53+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { SourceIndexWithReplicas } from './sourceIndexWithReplicas';
2+
3+
export type QuerySuggestionsIndex = {
4+
/**
5+
* Index name to target.
6+
*/
7+
indexName: string;
8+
/**
9+
* List of source indices used to generate a Query Suggestions index.
10+
*/
11+
sourceIndices: SourceIndexWithReplicas[];
12+
/**
13+
* De-duplicate singular and plural suggestions. For example, let\'s say your index contains English content, and that two suggestions “shoe” and “shoes” end up in your Query Suggestions index. If the English language is configured, only the most popular of those two suggestions would remain.
14+
*/
15+
languages: string[];
16+
/**
17+
* List of words and patterns to exclude from the Query Suggestions index.
18+
*/
19+
exclude: string[];
20+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import type { SourceIndex } from './sourceIndex';
2+
3+
export type QuerySuggestionsIndexParam = {
4+
/**
5+
* List of source indices used to generate a Query Suggestions index.
6+
*/
7+
sourceIndices: SourceIndex[];
8+
/**
9+
* De-duplicate singular and plural suggestions. For example, let\'s say your index contains English content, and that two suggestions “shoe” and “shoes” end up in your Query Suggestions index. If the English language is configured, only the most popular of those two suggestions would remain.
10+
*/
11+
languages?: string[];
12+
/**
13+
* List of words and patterns to exclude from the Query Suggestions index.
14+
*/
15+
exclude?: string[];
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { IndexName } from './indexName';
2+
import type { QuerySuggestionsIndexParam } from './querySuggestionsIndexParam';
3+
4+
export type QuerySuggestionsIndexWithIndexParam = IndexName &
5+
QuerySuggestionsIndexParam;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { SourceIndexExternal } from './sourceIndexExternal';
2+
3+
export type SourceIndex = {
4+
/**
5+
* Source index name.
6+
*/
7+
indexName: string;
8+
/**
9+
* List of analytics tags to filter the popular searches per tag.
10+
*/
11+
analyticsTags?: string[];
12+
/**
13+
* List of facets to define as categories for the query suggestions.
14+
*/
15+
facets?: Array<Record<string, any>>;
16+
/**
17+
* Minimum number of hits (e.g., matching records in the source index) to generate a suggestions.
18+
*/
19+
minHits?: number;
20+
/**
21+
* Minimum number of required letters for a suggestion to remain.
22+
*/
23+
minLetters?: number;
24+
/**
25+
* List of facet attributes used to generate Query Suggestions. The resulting suggestions are every combination of the facets in the nested list (e.g., (facetA and facetB) and facetC).
26+
*/
27+
generate?: string[][];
28+
/**
29+
* List of external indices to use to generate custom Query Suggestions.
30+
*/
31+
external?: SourceIndexExternal[];
32+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type SourceIndexExternal = {
2+
/**
3+
* The suggestion you would like to add.
4+
*/
5+
query: string;
6+
/**
7+
* The measure of the suggestion relative popularity.
8+
*/
9+
count: number;
10+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { SourceIndexExternal } from './sourceIndexExternal';
2+
3+
export type SourceIndexWithReplicas = {
4+
/**
5+
* Source index name.
6+
*/
7+
indexName: string;
8+
/**
9+
* True if the Query Suggestions index is a replicas.
10+
*/
11+
replicas: boolean;
12+
/**
13+
* List of analytics tags to filter the popular searches per tag.
14+
*/
15+
analyticsTags: string[];
16+
/**
17+
* List of facets to define as categories for the query suggestions.
18+
*/
19+
facets: Array<Record<string, any>>;
20+
/**
21+
* Minimum number of hits (e.g., matching records in the source index) to generate a suggestions.
22+
*/
23+
minHits: number;
24+
/**
25+
* Minimum number of required letters for a suggestion to remain.
26+
*/
27+
minLetters: number;
28+
/**
29+
* List of facet attributes used to generate Query Suggestions. The resulting suggestions are every combination of the facets in the nested list (e.g., (facetA and facetB) and facetC).
30+
*/
31+
generate: string[][];
32+
/**
33+
* List of external indices to use to generate custom Query Suggestions.
34+
*/
35+
external: SourceIndexExternal[];
36+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export type Status = {
2+
/**
3+
* The targeted index name.
4+
*/
5+
indexName: string;
6+
/**
7+
* True if the Query Suggestions index is running.
8+
*/
9+
isRunning: boolean;
10+
/**
11+
* Date and time of the last build.
12+
*/
13+
lastBuiltAt: string;
14+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type SucessResponse = {
2+
/**
3+
* The status code.
4+
*/
5+
status: number;
6+
/**
7+
* Message of the response.
8+
*/
9+
message: string;
10+
};

0 commit comments

Comments
 (0)