Skip to content

Commit

Permalink
feat: add Rules endpoints for search client (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
damcou authored Dec 17, 2021
1 parent 1555786 commit 4bacf25
Show file tree
Hide file tree
Showing 34 changed files with 1,207 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Whether the pattern parameter must match the beginning or the end of the query string, or both, or none.
*/
export enum Anchoring {
Is = 'is',
StartsWith = 'startsWith',
EndsWith = 'endsWith',
Contains = 'contains',
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Automatic facet Filter.
*/
export type AutomaticFacetFilter = {
/**
* Attribute to filter on. This must match a facet placeholder in the Rule’s pattern.
*/
facet: string;
/**
* Score for the filter. Typically used for optional or disjunctive filters.
*/
score?: number;
/**
* Whether the filter is disjunctive (true) or conjunctive (false).
*/
disjunctive?: boolean;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Anchoring } from './anchoring';

export type Condition = {
/**
* Query pattern syntax.
*/
pattern?: string;
anchoring?: Anchoring;
/**
* Whether the pattern matches on plurals, synonyms, and typos.
*/
alternatives?: boolean;
/**
* Rule context format: [A-Za-z0-9_-]+).
*/
context?: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { ConsequenceHide } from './consequenceHide';
import type { Params } from './params';
import type { Promote } from './promote';

/**
* Consequence of the Rule.
*/
export type Consequence = {
params?: Params;
/**
* Objects to promote as hits.
*/
promote?: Promote[];
/**
* Only use in combination with the promote consequence. When true, promoted results will be restricted to match the filters of the current search. When false, the promoted results will show up regardless of the filters.
*/
filterPromotes?: boolean;
/**
* Objects to hide from hits. Each object must contain an objectID field. By default, you can hide up to 50 items per rule.
*/
hide?: ConsequenceHide[];
/**
* Custom JSON object that will be appended to the userData array in the response. This object isn’t interpreted by the API. It’s limited to 1kB of minified JSON.
*/
userData?: { [key: string]: Record<string, any> };
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Unique identifier of the object to hide.
*/
export type ConsequenceHide = {
/**
* Unique identifier of the object.
*/
objectID: string;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type DeletedRule = {
/**
* Date of last update (ISO-8601 format).
*/
updatedAt: Date;
/**
* TaskID of the indexing task to wait for.
*/
taskID: number;
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@
import type { RequestOptions } from '../utils/types';

export * from './addApiKeyResponse';
export * from './anchoring';
export * from './apiKey';
export * from './appendSourceResponse';
export * from './assignUserIdObject';
export * from './assignUserIdResponse';
export * from './automaticFacetFilter';
export * from './baseIndexSettings';
export * from './baseSearchParams';
export * from './baseSearchResponse';
Expand All @@ -15,6 +17,9 @@ export * from './batchAssignUserIdsResponse';
export * from './batchObject';
export * from './batchResponse';
export * from './clearAllSynonymsResponse';
export * from './condition';
export * from './consequence';
export * from './consequenceHide';
export * from './createdAtObject';
export * from './deleteApiKeyResponse';
export * from './deleteIndexResponse';
Expand Down Expand Up @@ -42,18 +47,23 @@ export * from './multipleQueriesResponse';
export * from './operation';
export * from './operationIndexObject';
export * from './operationIndexResponse';
export * from './params';
export * from './promote';
export * from './rankingInfo';
export * from './rankingInfoMatchedGeoLocation';
export * from './record';
export * from './removeUserIdResponse';
export * from './replaceSourceResponse';
export * from './rule';
export * from './saveObjectResponse';
export * from './saveSynonymResponse';
export * from './saveSynonymsResponse';
export * from './searchHits';
export * from './searchParams';
export * from './searchParamsAsString';
export * from './searchResponse';
export * from './searchRulesParams';
export * from './searchRulesResponse';
export * from './searchSynonymsResponse';
export * from './searchUserIdsObject';
export * from './searchUserIdsResponse';
Expand All @@ -64,7 +74,10 @@ export * from './snippetResult';
export * from './source';
export * from './synonymHit';
export * from './synonymHitHighlightResult';
export * from './timeRange';
export * from './updateApiKeyResponse';
export * from './updatedRuleResponse';
export * from './updatedRuleResponseWithoutObjectID';
export * from './userId';

export interface Authentication {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import type { AutomaticFacetFilter } from './automaticFacetFilter';

/**
* Additional search parameters. Any valid search parameter is allowed.
*/
export type Params = {
/**
* Query string.
*/
query?: 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?: AutomaticFacetFilter[];
/**
* Same syntax as automaticFacetFilters, but the engine treats the filters as optional.
*/
automaticOptionalFacetFilters?: AutomaticFacetFilter[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Object to promote as hits.
*/
export type Promote = {
/**
* Unique identifier of the object to promote.
*/
objectID?: string;
/**
* Array of unique identifiers of the objects to promote.
*/
objectIDs?: string[];
/**
* The position to promote the objects to (zero-based). If you pass objectIDs, the objects are placed at this position as a group. For example, if you pass four objectIDs to position 0, the objects take the first four positions.
*/
position: number;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { Condition } from './condition';
import type { Consequence } from './consequence';
import type { TimeRange } from './timeRange';

/**
* Rule object.
*/
export type Rule = {
/**
* Unique identifier of the object.
*/
objectID: string;
/**
* A list of conditions that should apply to activate a Rule. You can use up to 25 conditions per Rule.
*/
conditions?: Condition[];
consequence: Consequence;
/**
* This field is intended for Rule management purposes, in particular to ease searching for Rules and presenting them to human readers. It’s not interpreted by the API.
*/
description?: string;
/**
* Whether the Rule is enabled. Disabled Rules remain in the index, but aren’t applied at query time.
*/
enabled?: boolean;
/**
* By default, Rules are permanently valid. When validity periods are specified, the Rule applies only during those periods; it’s ignored the rest of the time. The list must not be empty.
*/
validity?: TimeRange[];
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { Anchoring } from './anchoring';

/**
* Parameters for the search.
*/
export type SearchRulesParams = {
/**
* Full text query.
*/
query?: string;
anchoring?: Anchoring;
/**
* Restricts matches to contextual rules with a specific context (exact match).
*/
context?: string;
/**
* Requested page (zero-based).
*/
page?: number;
/**
* Maximum number of hits in a page. Minimum is 1, maximum is 1000.
*/
hitsPerPage?: number;
/**
* When specified, restricts matches to rules with a specific enabled status. When absent (default), all rules are retrieved, regardless of their enabled status.
*/
enabled?: boolean;
/**
* A mapping of requestOptions to send along with the request.
*/
requestOptions?: Array<{ [key: string]: Record<string, any> }>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { Rule } from './rule';

export type SearchRulesResponse = {
/**
* Fetched rules.
*/
hits: Rule[];
/**
* Number of fetched rules.
*/
nbHits: number;
/**
* Current page.
*/
page: number;
/**
* Number of pages.
*/
nbPages: number;
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type SearchUserIdsResponse = {
*/
page: number;
/**
* Set the number of hits per page.
* Maximum number of hits in a page. Minimum is 1, maximum is 1000.
*/
hitsPerPage: number;
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type TimeRange = {
/**
* Lower bound of the time range (Unix timestamp).
*/
from: number;
/**
* Upper bound of the time range (Unix timestamp).
*/
until: number;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type UpdatedRuleResponse = {
/**
* Unique identifier of the object.
*/
objectID: string;
/**
* Date of last update (ISO-8601 format).
*/
updatedAt: Date;
/**
* TaskID of the indexing task to wait for.
*/
taskID: number;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type UpdatedRuleResponseWithoutObjectID = {
/**
* Date of last update (ISO-8601 format).
*/
updatedAt: Date;
/**
* TaskID of the indexing task to wait for.
*/
taskID: number;
};
Loading

0 comments on commit 4bacf25

Please sign in to comment.