From cf50d0507edaf50b8d97dfe0328bda26368b4d89 Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 3 Nov 2017 13:30:40 +0100 Subject: [PATCH] query rules --- types/algoliasearch/index.d.ts | 246 ++++++++++++++++++++++++++++++++- 1 file changed, 239 insertions(+), 7 deletions(-) diff --git a/types/algoliasearch/index.d.ts b/types/algoliasearch/index.d.ts index 71ab8cce86..5d87946c3c 100644 --- a/types/algoliasearch/index.d.ts +++ b/types/algoliasearch/index.d.ts @@ -545,6 +545,65 @@ declare namespace algoliasearch { options: SearchSynonymOptions, cb: (err: Error, res: any) => void ): void; + /** + * Save a rule object + * @param rule + * @param options + * @param cb(err, res) + * https://github.com/algolia/algoliasearch-client-js#save-rule---saverule + */ + saveRule( + rule: AlgoliaRule, + options: RuleOption, + cb: (err: Error, res: any) => void + ): void; + /** + * Save a rule object + * @param rules + * @param options + * @param cb(err, res) + */ + batchRules( + rules: AlgoliaRule[], + options: RuleOption, + cb: (err: Error, res: any) => void + ): void; + /** + * Delete a specific rule + * @param identifier + * @param options + * @param cb(err, res) + * https://github.com/algolia/algoliasearch-client-js#batch-rules---batchrules + */ + deleteRule( + identifier: string, + options: RuleOption, + cb: (err: Error, res: any) => void + ): void; + /** + * Clear all rules of an index + * @param options + * @param cb(err, res) + * https://github.com/algolia/algoliasearch-client-js#clear-all-rules---clearrules + */ + clearRules(options: RuleOption, cb: (err: Error, res: any) => void): void; + /** + * Get a specific rule + * @param identifier + * @param cb(err, res) + * https://github.com/algolia/algoliasearch-client-js#get-rule---getrule + */ + getRule(identifier: string, cb: (err: Error, res: any) => void): void; + /** + * Search a rules + * @param options + * @param cb(err, res) + * https://github.com/algolia/algoliasearch-client-js#search-rules---searchrules + */ + searchRules( + options: SearchRuleOptions, + cb: (err: Error, res: any) => void + ): void; /** * List index user keys * @param cb(err, res) @@ -858,6 +917,50 @@ declare namespace algoliasearch { * https://github.com/algolia/algoliasearch-client-js#search-synonyms---searchsynonyms */ searchSynonyms(options: SearchSynonymOptions): Promise; + /** + * Save a rule object + * @param rule + * @param options + * return {Promise} + * https://github.com/algolia/algoliasearch-client-js#save-rule---saverule + */ + saveRule(rule: AlgoliaRule, options: RuleOption): Promise; + /** + * Save a rule object + * @param rules + * @param options + * return {Promise} + */ + batchRules(rules: AlgoliaRule[], options: RuleOption): Promise; + /** + * Delete a specific rule + * @param identifier + * @param options + * return {Promise} + * https://github.com/algolia/algoliasearch-client-js#batch-rules---batchrules + */ + deleteRule(identifier: string, options: RuleOption): Promise; + /** + * Clear all query rules of an index + * @param options + * return {Promise} + * https://github.com/algolia/algoliasearch-client-js#clear-all-rules---clearrules + */ + clearRules(options: RuleOption): Promise; + /** + * Get a specific query rule + * @param identifier + * return {Promise} + * https://github.com/algolia/algoliasearch-client-js#get-rule---getrule + */ + getRule(identifier: string): Promise; + /** + * Search for query rules + * @param options + * return {Promise} + * https://github.com/algolia/algoliasearch-client-js#search-rules---searchrules + */ + searchRules(options: SearchRuleOptions): Promise; /** * List index user keys * return {Promise} @@ -1036,8 +1139,8 @@ Interface describing options available for gettings the logs description?: string; } /** - * Describes option used when making operation on synonyms - */ + * Describes option used when making operation on synonyms + */ interface SynonymOption { /** * You can forward all settings updates to the replicas of an index @@ -1051,8 +1154,8 @@ Interface describing options available for gettings the logs replaceExistingSynonyms?: boolean; } /** - * Describes options used when searching for synonyms - */ + * Describes options used when searching for synonyms + */ interface SearchSynonymOptions { /** * The actual search query to find synonyms @@ -1061,7 +1164,7 @@ Interface describing options available for gettings the logs query?: string; /** * The page to fetch when browsing through several pages of results - * default: 100 + * default: 0 * https://github.com/algolia/algoliasearch-client-js#search-synonyms---searchsynonyms */ page?: number; @@ -1078,6 +1181,49 @@ Interface describing options available for gettings the logs */ hitsPerPage?: number; } + /** + * Describes option used when making operation on query rules + */ + interface RuleOption { + /** + * You can forward all settings updates to the replicas of an index + * https://github.com/algolia/algoliasearch-client-js#replica-settings + */ + forwardToReplicas?: boolean; + /** + * Replace all existing query rules on the index with the content of the batch + */ + clearExistingRules?: boolean; + } + /** + * Describes options used when searching for query rules + */ + interface SearchRuleOptions { + /** + * The actual search query to find synonyms + */ + query?: string; + /** + * When specified, restricts matches to rules with a specific anchoring type. + * When omitted, all anchoring types may match. + */ + anchoring?: string; + /** + * When specified, restricts matches to contextual rules with a specific context (exact match). + * When omitted, any generic or contextual rule (with any context) may match. + */ + context?: string; + /** + * Requested page (zero-based) + * default: 0 + */ + page?: number; + /** + * Number of hits per page + * default: 20 + */ + hitsPerPage?: number; + } interface AlgoliaBrowseResponse { cursor?: string; hits: any[]; @@ -1106,8 +1252,94 @@ Interface describing options available for gettings the logs synonyms: string[]; } /** - * Describes the options used when generating new api keys - */ + * Describes a query rule object + */ + interface AlgoliaRule { + /** + * ObjectID of the synonym + * https://github.com/algolia/algoliasearch-client-js#save-synonym---savesynonym + */ + objectID: string; + /** + * Condition of the rule + */ + condition: { + /** + * Query pattern + * syntax: https://www.algolia.com/doc/rest-api/query-rules/?language=php#query-pattern-syntax + */ + pattern: string; + /** + * Whether the pattern must match the beginning or the end of the query string, or both, or none. + */ + anchoring: 'is' | 'startsWith' | 'endsWith' | 'contains'; + /** + * Rule context (format: [A-Za-z0-9_-]+). + * When specified, the rule is contextual and applies only when the same context is specified + * at query time (using the ruleContexts parameter). + * When absent, the rule is generic and always applies + * (provided that its other conditions are met, of course). + */ + context?: string; + }; + /** + * Consequence of the rule. At least one of the following must be used: + */ + consequence: { + params?: { + /** + * When a string, it replaces the entire query string. + * When an object, describes incremental edits to be made to the query string. + */ + query?: + | string + | { + /** + * Tokens (literals or placeholders) from the query pattern + * that should be removed from the query string. + */ + remove: string[]; + }; + /** + * Names of facets to which automatic filtering must be applied; + * they must match the facet name of a facet value placeholder in the query pattern. + */ + automaticFacetFilters?: string[]; + /** + * Same as automaticFacetFilters, but for optionalFacetFilters. + * The same syntax as query parameters can be used to specify a score: facetName. + */ + automaticOptionalFacetFilters?: string[]; + }; + /** + * Objects to promote as hits. Each object must contain the following fields + */ + promote?: { + /** + * Unique identifier of the object to promote + */ + objectID: string; + /** + * Promoted rank for the object (zero-based) + */ + position: number; + }[]; + /** + * Custom JSON object that will be appended to the userData array in the response. + * This object is not interpreted by the API. It is limited to 1kB of minified JSON. + */ + userData?: {}; + }; + /** + * This field is intended for rule management purposes, + * in particular to ease searching for rules and presenting them to human readers. + * It is not interpreted by the API. + */ + description?: string; + } + /** + * Describes the options used when generating new api keys + */ interface AlgoliaSecuredApiOptions { /** * Filter the query with numeric, facet or/and tag filters