Skip to content

feat: query-suggestions client APIC-202 #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/actions/cache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ runs:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/recommend/dist
key: ${{ runner.os }}-js-client-recommend-${{ hashFiles('clients/algoliasearch-client-javascript/recommend/**') }}

- name: Restore built JavaScript query-suggestions client
if: ${{ inputs.job == 'cts' }}
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/client-query-suggestions/dist
key: ${{ runner.os }}-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/client-query-suggestions/**') }}

- name: Restore built JavaScript personalization client
if: ${{ inputs.job == 'cts' }}
uses: actions/cache@v2
Expand Down
12 changes: 8 additions & 4 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ runs:
echo "::set-output name=COMMON_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/common | wc -l)"
echo "::set-output name=SEARCH_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/search | wc -l)"
echo "::set-output name=RECOMMEND_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/recommend | wc -l)"
echo "::set-output name=QS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/query_suggestions | wc -l)"
echo "::set-output name=QUERY_SUGGESTIONS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/query-suggestions | wc -l)"
echo "::set-output name=PERSO_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/personalization | wc -l)"
echo "::set-output name=INSIGHTS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/insights | wc -l)"
echo "::set-output name=ANALYTICS_SPECS_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- specs/analytics | wc -l)"
Expand All @@ -44,6 +44,7 @@ runs:
echo "::set-output name=JS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript | wc -l)"
echo "::set-output name=JS_SEARCH_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-search | wc -l)"
echo "::set-output name=JS_RECOMMEND_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/recommend | wc -l)"
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)"
echo "::set-output name=JS_PERSO_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-personalization | wc -l)"
echo "::set-output name=JS_ANALYTICS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-analytics | wc -l)"
echo "::set-output name=JS_INSIGHTS_CLIENT_CHANGED::$(git diff --shortstat origin/${{ github.base_ref }}..HEAD -- clients/algoliasearch-client-javascript/client-insights | wc -l)"
Expand All @@ -60,9 +61,9 @@ outputs:
RUN_SPECS_RECOMMEND:
description: Determine if the `specs_recommend` job should run
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 }}
RUN_SPECS_QS:
description: Determine if the `specs_qs` job should run
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 }}
RUN_SPECS_QUERY_SUGGESTIONS:
description: Determine if the `specs_query_suggestions` job should run
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 }}
RUN_SPECS_PERSO:
description: Determine if the `specs_perso` job should run
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 }}
Expand All @@ -83,6 +84,9 @@ outputs:
RUN_JS_CLIENT_RECOMMEND:
description: Determine if the `client_javascript_recommend` job should run
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 }}
RUN_JS_CLIENT_QUERY_SUGGESTIONS:
description: Determine if the `client_javascript_query_suggestions` job should run
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 }}
RUN_JS_CLIENT_PERSO:
description: Determine if the `client_javascript_perso` job should run
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 }}
Expand Down
45 changes: 44 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,15 @@ jobs:
outputs:
RUN_SPECS_SEARCH: ${{ steps.setup.outputs.RUN_SPECS_SEARCH }}
RUN_SPECS_RECOMMEND: ${{ steps.setup.outputs.RUN_SPECS_RECOMMEND }}
RUN_SPECS_QS: ${{ steps.setup.outputs.RUN_SPECS_QS }}
RUN_SPECS_QUERY_SUGGESTIONS: ${{ steps.setup.outputs.RUN_SPECS_QUERY_SUGGESTIONS }}
RUN_SPECS_PERSO: ${{ steps.setup.outputs.RUN_SPECS_PERSO }}
RUN_SPECS_INSIGHTS: ${{ steps.setup.outputs.RUN_SPECS_INSIGHTS }}
RUN_SPECS_ANALYTICS: ${{ steps.setup.outputs.RUN_SPECS_ANALYTICS }}
RUN_SPECS_AB: ${{ steps.setup.outputs.RUN_SPECS_AB }}

RUN_JS_CLIENT_SEARCH: ${{ steps.setup.outputs.RUN_JS_CLIENT_SEARCH }}
RUN_JS_CLIENT_RECOMMEND: ${{ steps.setup.outputs.RUN_JS_CLIENT_RECOMMEND }}
RUN_JS_CLIENT_QUERY_SUGGESTIONS: ${{ steps.setup.outputs.RUN_JS_CLIENT_QUERY_SUGGESTIONS }}
RUN_JS_CLIENT_PERSO: ${{ steps.setup.outputs.RUN_JS_CLIENT_PERSO }}
RUN_JS_CLIENT_ANALYTICS: ${{ steps.setup.outputs.RUN_JS_CLIENT_ANALYTICS }}
RUN_JS_CLIENT_INSIGHTS: ${{ steps.setup.outputs.RUN_JS_CLIENT_INSIGHTS }}
Expand Down Expand Up @@ -76,6 +77,22 @@ jobs:
- name: Lint recommend specs
run: yarn eslint --ext=yml specs/recommend

specs_query_suggestions:
runs-on: ubuntu-20.04
needs: setup
if: ${{ always() && needs.setup.outputs.RUN_SPECS_QUERY_SUGGESTIONS == 'true' }}
steps:
- uses: actions/checkout@v2

- name: Restore cache
uses: ./.github/actions/cache

- name: Checking query-suggestions specs
run: yarn build:specs query-suggestions

- name: Lint query-suggestions specs
run: yarn eslint --ext=yml specs/query-suggestions

specs_perso:
runs-on: ubuntu-20.04
needs: setup
Expand Down Expand Up @@ -174,6 +191,31 @@ jobs:
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients javascript recommend

client_javascript_query_suggestions:
runs-on: ubuntu-20.04
needs: [specs_query_suggestions]
if: ${{ always() && needs.setup.outputs.RUN_JS_CLIENT_QUERY_SUGGESTIONS == 'true' }}
steps:
- uses: actions/checkout@v2

- name: Restore cache
uses: ./.github/actions/cache

- name: Cache query-suggestions client
id: cache
uses: actions/cache@v2
with:
path: /home/runner/work/api-clients-automation/api-clients-automation/clients/algoliasearch-client-javascript/client-query-suggestions/dist
key: ${{ runner.os }}-js-client-query-suggestions-${{ hashFiles('clients/algoliasearch-client-javascript/client-query-suggestions/**') }}

- name: Generate query-suggestions client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn generate javascript query-suggestions

- name: Build query-suggestions client
if: steps.cache.outputs.cache-hit != 'true'
run: yarn build:clients javascript query-suggestions

client_javascript_perso:
runs-on: ubuntu-20.04
needs: [specs_perso]
Expand Down Expand Up @@ -281,6 +323,7 @@ jobs:
needs:
- client_javascript_search
- client_javascript_recommend
- client_javascript_query_suggestions
- client_javascript_perso
- client_javascript_analytics
- client_javascript_insights
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.openapi-generator
.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

git_push.sh
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,6 @@
/**
* Error.
*/
export type ErrorBase = {
message?: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type IndexName = {
/**
* Index name to target.
*/
indexName: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export type LogFile = {
/**
* Date and time of creation of the record.
*/
timestamp: Date;
/**
* Type of the record, can be one of three values (INFO, SKIP or ERROR).
*/
level: LogFileLevel;
/**
* Detailed description of what happened.
*/
message: string;
/**
* Indicates the hierarchy of the records. For example, a record with contextLevel=1 belongs to a preceding record with contextLevel=0.
*/
contextLevel: number;
};

export type LogFileLevel = 'ERROR' | 'INFO' | 'SKIP';
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* eslint-disable no-param-reassign */
import type { RequestOptions } from '../utils/types';

export * from './errorBase';
export * from './indexName';
export * from './logFile';
export * from './querySuggestionsIndex';
export * from './querySuggestionsIndexParam';
export * from './querySuggestionsIndexWithIndexParam';
export * from './sourceIndex';
export * from './sourceIndexExternal';
export * from './sourceIndexWithReplicas';
export * from './status';
export * from './sucessResponse';

export interface Authentication {
/**
* Apply authentication settings to header and query params.
*/
applyToRequest: (requestOptions: RequestOptions) => Promise<void> | void;
}

export class ApiKeyAuth implements Authentication {
apiKey: string = '';

constructor(private location: string, private paramName: string) {}

applyToRequest(requestOptions: RequestOptions): void {
if (this.location === 'query') {
requestOptions.queryParameters[this.paramName] = this.apiKey;
} else if (
this.location === 'header' &&
requestOptions &&
requestOptions.headers
) {
requestOptions.headers[this.paramName] = this.apiKey;
} else if (
this.location === 'cookie' &&
requestOptions &&
requestOptions.headers
) {
if (requestOptions.headers.Cookie) {
requestOptions.headers.Cookie += `; ${
this.paramName
}=${encodeURIComponent(this.apiKey)}`;
} else {
requestOptions.headers.Cookie = `${this.paramName}=${encodeURIComponent(
this.apiKey
)}`;
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { SourceIndexWithReplicas } from './sourceIndexWithReplicas';

export type QuerySuggestionsIndex = {
/**
* Index name to target.
*/
indexName: string;
/**
* List of source indices used to generate a Query Suggestions index.
*/
sourceIndices: SourceIndexWithReplicas[];
/**
* 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.
*/
languages: string[];
/**
* List of words and patterns to exclude from the Query Suggestions index.
*/
exclude: string[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { SourceIndex } from './sourceIndex';

export type QuerySuggestionsIndexParam = {
/**
* List of source indices used to generate a Query Suggestions index.
*/
sourceIndices: SourceIndex[];
/**
* 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.
*/
languages?: string[];
/**
* List of words and patterns to exclude from the Query Suggestions index.
*/
exclude?: string[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { IndexName } from './indexName';
import type { QuerySuggestionsIndexParam } from './querySuggestionsIndexParam';

export type QuerySuggestionsIndexWithIndexParam = IndexName &
QuerySuggestionsIndexParam;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { SourceIndexExternal } from './sourceIndexExternal';

export type SourceIndex = {
/**
* Source index name.
*/
indexName: string;
/**
* List of analytics tags to filter the popular searches per tag.
*/
analyticsTags?: string[];
/**
* List of facets to define as categories for the query suggestions.
*/
facets?: Array<Record<string, any>>;
/**
* Minimum number of hits (e.g., matching records in the source index) to generate a suggestions.
*/
minHits?: number;
/**
* Minimum number of required letters for a suggestion to remain.
*/
minLetters?: number;
/**
* 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).
*/
generate?: string[][];
/**
* List of external indices to use to generate custom Query Suggestions.
*/
external?: SourceIndexExternal[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type SourceIndexExternal = {
/**
* The suggestion you would like to add.
*/
query: string;
/**
* The measure of the suggestion relative popularity.
*/
count: number;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { SourceIndexExternal } from './sourceIndexExternal';

export type SourceIndexWithReplicas = {
/**
* Source index name.
*/
indexName: string;
/**
* True if the Query Suggestions index is a replicas.
*/
replicas: boolean;
/**
* List of analytics tags to filter the popular searches per tag.
*/
analyticsTags: string[];
/**
* List of facets to define as categories for the query suggestions.
*/
facets: Array<Record<string, any>>;
/**
* Minimum number of hits (e.g., matching records in the source index) to generate a suggestions.
*/
minHits: number;
/**
* Minimum number of required letters for a suggestion to remain.
*/
minLetters: number;
/**
* 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).
*/
generate: string[][];
/**
* List of external indices to use to generate custom Query Suggestions.
*/
external: SourceIndexExternal[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type Status = {
/**
* The targeted index name.
*/
indexName: string;
/**
* True if the Query Suggestions index is running.
*/
isRunning: boolean;
/**
* Date and time of the last build.
*/
lastBuiltAt: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type SucessResponse = {
/**
* The status code.
*/
status: number;
/**
* Message of the response.
*/
message: string;
};
Loading