Skip to content

Commit 4bacf25

Browse files
authored
feat: add Rules endpoints for search client (#48)
1 parent 1555786 commit 4bacf25

34 files changed

+1207
-11
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Whether the pattern parameter must match the beginning or the end of the query string, or both, or none.
3+
*/
4+
export enum Anchoring {
5+
Is = 'is',
6+
StartsWith = 'startsWith',
7+
EndsWith = 'endsWith',
8+
Contains = 'contains',
9+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Automatic facet Filter.
3+
*/
4+
export type AutomaticFacetFilter = {
5+
/**
6+
* Attribute to filter on. This must match a facet placeholder in the Rule’s pattern.
7+
*/
8+
facet: string;
9+
/**
10+
* Score for the filter. Typically used for optional or disjunctive filters.
11+
*/
12+
score?: number;
13+
/**
14+
* Whether the filter is disjunctive (true) or conjunctive (false).
15+
*/
16+
disjunctive?: boolean;
17+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Anchoring } from './anchoring';
2+
3+
export type Condition = {
4+
/**
5+
* Query pattern syntax.
6+
*/
7+
pattern?: string;
8+
anchoring?: Anchoring;
9+
/**
10+
* Whether the pattern matches on plurals, synonyms, and typos.
11+
*/
12+
alternatives?: boolean;
13+
/**
14+
* Rule context format: [A-Za-z0-9_-]+).
15+
*/
16+
context?: string;
17+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import type { ConsequenceHide } from './consequenceHide';
2+
import type { Params } from './params';
3+
import type { Promote } from './promote';
4+
5+
/**
6+
* Consequence of the Rule.
7+
*/
8+
export type Consequence = {
9+
params?: Params;
10+
/**
11+
* Objects to promote as hits.
12+
*/
13+
promote?: Promote[];
14+
/**
15+
* 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.
16+
*/
17+
filterPromotes?: boolean;
18+
/**
19+
* Objects to hide from hits. Each object must contain an objectID field. By default, you can hide up to 50 items per rule.
20+
*/
21+
hide?: ConsequenceHide[];
22+
/**
23+
* 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.
24+
*/
25+
userData?: { [key: string]: Record<string, any> };
26+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Unique identifier of the object to hide.
3+
*/
4+
export type ConsequenceHide = {
5+
/**
6+
* Unique identifier of the object.
7+
*/
8+
objectID: string;
9+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export type DeletedRule = {
2+
/**
3+
* Date of last update (ISO-8601 format).
4+
*/
5+
updatedAt: Date;
6+
/**
7+
* TaskID of the indexing task to wait for.
8+
*/
9+
taskID: number;
10+
};

clients/algoliasearch-client-javascript/client-search/model/models.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import type { RequestOptions } from '../utils/types';
33

44
export * from './addApiKeyResponse';
5+
export * from './anchoring';
56
export * from './apiKey';
67
export * from './appendSourceResponse';
78
export * from './assignUserIdObject';
89
export * from './assignUserIdResponse';
10+
export * from './automaticFacetFilter';
911
export * from './baseIndexSettings';
1012
export * from './baseSearchParams';
1113
export * from './baseSearchResponse';
@@ -15,6 +17,9 @@ export * from './batchAssignUserIdsResponse';
1517
export * from './batchObject';
1618
export * from './batchResponse';
1719
export * from './clearAllSynonymsResponse';
20+
export * from './condition';
21+
export * from './consequence';
22+
export * from './consequenceHide';
1823
export * from './createdAtObject';
1924
export * from './deleteApiKeyResponse';
2025
export * from './deleteIndexResponse';
@@ -42,18 +47,23 @@ export * from './multipleQueriesResponse';
4247
export * from './operation';
4348
export * from './operationIndexObject';
4449
export * from './operationIndexResponse';
50+
export * from './params';
51+
export * from './promote';
4552
export * from './rankingInfo';
4653
export * from './rankingInfoMatchedGeoLocation';
4754
export * from './record';
4855
export * from './removeUserIdResponse';
4956
export * from './replaceSourceResponse';
57+
export * from './rule';
5058
export * from './saveObjectResponse';
5159
export * from './saveSynonymResponse';
5260
export * from './saveSynonymsResponse';
5361
export * from './searchHits';
5462
export * from './searchParams';
5563
export * from './searchParamsAsString';
5664
export * from './searchResponse';
65+
export * from './searchRulesParams';
66+
export * from './searchRulesResponse';
5767
export * from './searchSynonymsResponse';
5868
export * from './searchUserIdsObject';
5969
export * from './searchUserIdsResponse';
@@ -64,7 +74,10 @@ export * from './snippetResult';
6474
export * from './source';
6575
export * from './synonymHit';
6676
export * from './synonymHitHighlightResult';
77+
export * from './timeRange';
6778
export * from './updateApiKeyResponse';
79+
export * from './updatedRuleResponse';
80+
export * from './updatedRuleResponseWithoutObjectID';
6881
export * from './userId';
6982

7083
export interface Authentication {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import type { AutomaticFacetFilter } from './automaticFacetFilter';
2+
3+
/**
4+
* Additional search parameters. Any valid search parameter is allowed.
5+
*/
6+
export type Params = {
7+
/**
8+
* Query string.
9+
*/
10+
query?: string;
11+
/**
12+
* 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.
13+
*/
14+
automaticFacetFilters?: AutomaticFacetFilter[];
15+
/**
16+
* Same syntax as automaticFacetFilters, but the engine treats the filters as optional.
17+
*/
18+
automaticOptionalFacetFilters?: AutomaticFacetFilter[];
19+
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Object to promote as hits.
3+
*/
4+
export type Promote = {
5+
/**
6+
* Unique identifier of the object to promote.
7+
*/
8+
objectID?: string;
9+
/**
10+
* Array of unique identifiers of the objects to promote.
11+
*/
12+
objectIDs?: string[];
13+
/**
14+
* 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.
15+
*/
16+
position: number;
17+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { Condition } from './condition';
2+
import type { Consequence } from './consequence';
3+
import type { TimeRange } from './timeRange';
4+
5+
/**
6+
* Rule object.
7+
*/
8+
export type Rule = {
9+
/**
10+
* Unique identifier of the object.
11+
*/
12+
objectID: string;
13+
/**
14+
* A list of conditions that should apply to activate a Rule. You can use up to 25 conditions per Rule.
15+
*/
16+
conditions?: Condition[];
17+
consequence: Consequence;
18+
/**
19+
* 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.
20+
*/
21+
description?: string;
22+
/**
23+
* Whether the Rule is enabled. Disabled Rules remain in the index, but aren’t applied at query time.
24+
*/
25+
enabled?: boolean;
26+
/**
27+
* 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.
28+
*/
29+
validity?: TimeRange[];
30+
};

0 commit comments

Comments
 (0)