Skip to content

feat: add Rules endpoints for search client #48

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 11 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
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
@@ -1,6 +1,6 @@
export type BaseSearchParams = {
/**
* The text to search in the index.
* Full text query.
*/
query: string;
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type BaseSearchResponse = {
*/
facets_stats?: { [key: string]: BaseSearchResponseFacetsStats };
/**
* Set the number of hits per page.
* Maximum number of hits in a page. Minimum is 1, maximum is 1000.
*/
hitsPerPage: number;
/**
Expand Down Expand Up @@ -82,7 +82,7 @@ export type BaseSearchResponse = {
*/
processingTimeMS: number;
/**
* The text to search in the index.
* Full text query.
*/
query: string;
/**
Expand Down
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 @@ -56,7 +56,7 @@ export type IndexSettingsAsSearchParams = {
*/
restrictHighlightAndSnippetArrays?: boolean;
/**
* 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
Expand Up @@ -2,9 +2,11 @@
import type { RequestOptions } from '../utils/types';

export * from './addApiKeyResponse';
export * from './anchoring';
export * from './apiKey';
export * from './assignUserIdObject';
export * from './assignUserIdResponse';
export * from './automaticFacetFilter';
export * from './baseIndexSettings';
export * from './baseSearchParams';
export * from './baseSearchResponse';
Expand All @@ -14,6 +16,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 All @@ -40,17 +45,22 @@ 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 './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 @@ -60,7 +70,10 @@ export * from './setSettingsResponse';
export * from './snippetResult';
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
Expand Up @@ -4,7 +4,7 @@ export type MultipleQueries = {
*/
indexName: string;
/**
* The text to search in the index.
* Full text query.
*/
query?: string;
/**
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 @@ -15,7 +15,7 @@ export type SearchUserIdsObject = {
*/
page?: number;
/**
* Set the number of hits per page.
* Maximum number of hits in a page. Minimum is 1, maximum is 1000.
*/
hitsPerPage?: 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