forked from algolia/instantsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
1604 lines (1522 loc) · 56.5 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import EventEmitter from '@algolia/events';
// eslint-disable-next-line @typescript-eslint/consistent-type-imports
import type {
FindAnswersResponse,
FrequentlyBoughtTogetherQuery,
HighlightResult,
LookingSimilarQuery,
RankingInfo,
RecommendResponse,
RelatedProductsQuery,
SearchClient,
SearchOptions,
SearchResponse,
SnippetResult,
SupportedLanguage,
TrendingFacetsQuery,
TrendingItemsQuery,
PlainRecommendParameters as ClientPlainRecommendParameters,
} from './types/algoliasearch';
/**
* The algoliasearchHelper module is the function that will let its
* contains everything needed to use the Algoliasearch
* Helper. It is a also a function that instantiate the helper.
* To use the helper, you also need the Algolia JS client v3.
* @param client an AlgoliaSearch client
* @param index the name of the index to query
* @param opts
* @param searchResultsOptions
*/
declare function algoliasearchHelper(
client: SearchClient,
index: string,
opts?: algoliasearchHelper.PlainSearchParameters,
searchResultsOptions?: algoliasearchHelper.SearchResultsOptions
): algoliasearchHelper.AlgoliaSearchHelper;
declare namespace algoliasearchHelper {
export const version: string;
export class AlgoliaSearchHelper extends EventEmitter {
state: SearchParameters;
recommendState: RecommendParameters;
lastResults: SearchResults | null;
lastRecommendResults: RecommendResults | null;
_recommendCache: RecommendResults['_rawResults'];
derivedHelpers: DerivedHelper[];
on(
event: 'search',
cb: (res: { state: SearchParameters; results: SearchResults }) => void
): this;
on(
event: 'change',
cb: (res: {
state: SearchParameters;
results: SearchResults;
isPageReset: boolean;
}) => void
): this;
on(
event: 'searchForFacetValues',
cb: (res: {
state: SearchParameters;
facet: string;
query: string;
}) => void
): this;
on(
event: 'searchOnce',
cb: (res: { state: SearchParameters }) => void
): this;
on(
event: 'result',
cb: (res: { results: SearchResults; state: SearchParameters }) => void
): this;
on(event: 'error', cb: (res: { error: Error }) => void): this;
on(event: 'searchQueueEmpty', cb: () => void): this;
/**
* Start the search with the parameters set in the state. When the
* method is called, it triggers a `search` event. The results will
* be available through the `result` event. If an error occurs, an
* `error` will be fired instead.
* @return
* @fires search
* @fires result
* @fires error
* @chainable
*/
search(): this;
recommend(): this;
/**
* Private method to only search on derived helpers
*/
searchOnlyWithDerivedHelpers(): this;
/**
* Private method for search, without triggering events
*/
searchWithoutTriggeringOnStateChange(): this;
/**
* Gets the search query parameters that would be sent to the Algolia Client
* for the hits
*/
getQuery(): SearchOptions;
/**
* Start a search using a modified version of the current state. This method does
* not trigger the helper lifecycle and does not modify the state kept internally
* by the helper. This second aspect means that the next search call will be the
* same as a search call before calling searchOnce.
* @param options can contain all the parameters that can be set to SearchParameters
* plus the index
* @param [callback] optional callback executed when the response from the
* server is back.
* @return if a callback is passed the method returns undefined
* otherwise it returns a promise containing an object with two keys :
* - content with a SearchResults
* - state with the state used for the query as a SearchParameters
* @example
* // Changing the number of records returned per page to 1
* // This example uses the callback API
* var state = helper.searchOnce({hitsPerPage: 1},
* function(error, content, state) {
* // if an error occurred it will be passed in error, otherwise its value is null
* // content contains the results formatted as a SearchResults
* // state is the instance of SearchParameters used for this search
* });
* @example
* // Changing the number of records returned per page to 1
* // This example uses the promise API
* var state1 = helper.searchOnce({hitsPerPage: 1})
* .then(promiseHandler);
*
* function promiseHandler(res) {
* // res contains
* // {
* // content : SearchResults
* // state : SearchParameters (the one used for this specific search)
* // }
* }
*/
searchOnce(
options: PlainSearchParameters
): Promise<{ content: SearchResults; state: SearchParameters }>;
searchOnce(
options: PlainSearchParameters,
cb: (
error: Error,
content: SearchResults,
state: SearchParameters
) => void
): void;
/**
* Start the search for answers with the parameters set in the state.
* This method returns a promise.
* @param {Object} options - the options for answers API call
* @param {string[]} options.attributesForPrediction - Attributes to use for predictions. If empty, `searchableAttributes` is used instead.
* @param {string[]} options.queryLanguages - The languages in the query. Currently only supports ['en'].
* @param {number} options.nbHits - Maximum number of answers to retrieve from the Answers Engine. Cannot be greater than 1000.
* @deprecated answers is deprecated and will be replaced with new initiatives
*/
findAnswers<TObject>(options: {
attributesForPrediction: string[];
queryLanguages: string[];
nbHits: number;
}): Promise<FindAnswersResponse<TObject>>;
/**
* Search for facet values based on an query and the name of a faceted attribute. This
* triggers a search and will return a promise. On top of using the query, it also sends
* the parameters from the state so that the search is narrowed down to only the possible values.
*
* See the description of [FacetSearchResult](reference.html#FacetSearchResult)
* @param facet the name of the faceted attribute
* @param query the string query for the search
* @param [maxFacetHits] the maximum number values returned. Should be > 0 and <= 100
* @param [userState] the set of custom parameters to use on top of the current state. Setting a property to `undefined` removes
* it in the generated query.
* @return the results of the search
*/
searchForFacetValues(
facet: string,
query: string,
maxFacetHits: number,
userState?: PlainSearchParameters
): Promise<SearchForFacetValues.Result>;
/**
* Sets the text query used for the search.
*
* This method resets the current page to 0.
* @param q the user query
* @return
* @fires change
* @chainable
*/
setQuery(q: string): this;
/**
* Remove all the types of refinements except tags. A string can be provided to remove
* only the refinements of a specific attribute. For more advanced use case, you can
* provide a function instead. This function should follow the
* [clearCallback definition](#SearchParameters.clearCallback).
*
* This method resets the current page to 0.
* @param [name] optional name of the facet / attribute on which we want to remove all refinements
* @return
* @fires change
* @chainable
* @example
* // Removing all the refinements
* helper.clearRefinements().search();
* @example
* // Removing all the filters on a the category attribute.
* helper.clearRefinements('category').search();
* @example
* // Removing only the exclude filters on the category facet.
* helper.clearRefinements(function(value, attribute, type) {
* return type === 'exclude' && attribute === 'category';
* }).search();
*/
clearRefinements(name?: string): this;
clearRefinements(
func: (value: any, attribute: string, type: string) => boolean
): this;
/**
* Remove all the tag filters.
*
* This method resets the current page to 0.
* @return
* @fires change
* @chainable
*/
clearTags(): this;
/**
* Updates the name of the index that will be targeted by the query.
*
* This method resets the current page to 0.
* @param name the index name
* @return
* @fires change
* @chainable
*/
setIndex(name: string): this;
addDisjunctiveFacetRefinement(facet: string, value: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addDisjunctiveFacetRefinement}
*/
addDisjunctiveRefine(facet: string, value: string): this;
addHierarchicalFacetRefinement(facet: string, path: string): this;
addNumericRefinement(
facet: string,
operator?: SearchParameters.Operator,
value?: number | number[]
): this;
addFacetRefinement(facet: string, value: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetRefinement}
*/
addRefine: AlgoliaSearchHelper['addFacetRefinement'];
addFacetExclusion(facet: string, value: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#addFacetExclusion}
*/
addExclude: AlgoliaSearchHelper['addFacetExclusion'];
addTag(tag: string): this;
addFrequentlyBoughtTogether(
params: RecommendParametersWithId<FrequentlyBoughtTogetherQuery>
): this;
addRelatedProducts(
params: RecommendParametersWithId<RelatedProductsQuery>
): this;
addTrendingItems(
params: RecommendParametersWithId<TrendingItemsQuery>
): this;
addTrendingFacets(
params: RecommendParametersWithId<TrendingFacetsQuery>
): this;
addLookingSimilar(
params: RecommendParametersWithId<LookingSimilarQuery>
): this;
removeNumericRefinement(
facet: string,
operator?: SearchParameters.Operator,
value?: number | number[]
): this;
removeDisjunctiveFacetRefinement(facet: string, value?: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeDisjunctiveFacetRefinement}
*/
removeDisjunctiveRefine(facet: string, value?: string): this;
removeHierarchicalFacetRefinement(facet: string): this;
removeFacetRefinement(facet: string, value?: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetRefinement}
*/
removeRefine(facet: string, value: string): this;
removeFacetExclusion(facet: string, value: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#removeFacetExclusion}
*/
removeExclude(facet: string, value: string): this;
removeTag(value: string): this;
removeFrequentlyBoughtTogether(id: number): this;
removeRelatedProducts(id: number): this;
removeTrendingItems(id: number): this;
removeTrendingFacets(id: number): this;
removeLookingSimilar(id: number): this;
toggleFacetExclusion(facet: string, value: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetExclusion}
*/
toggleExclude(facet: string, value: string): this;
toggleFacetRefinement(facet: string, value: string): this;
/**
* @deprecated since version 2.19.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
*/
toggleRefinement(facet: string, value: string): this;
/**
* @deprecated since version 2.4.0, see {@link AlgoliaSearchHelper#toggleFacetRefinement}
*/
toggleRefine(facet: string, value: string): this;
toggleTag(tag: string): this;
nextPage(): this;
previousPage(): this;
setPage(page: number): this;
/**
* @deprecated
*/
setCurrentPage(page: number): this;
setQueryParameter<SearchParameter extends keyof PlainSearchParameters>(
parameter: SearchParameter,
value: PlainSearchParameters[SearchParameter]
): this;
/**
* Set the whole state (warning: will erase previous state)
* @param newState the whole new state
* @return
* @fires change
* @chainable
*/
setState(newState: PlainSearchParameters): this;
overrideStateWithoutTriggeringChangeEvent: AlgoliaSearchHelper['setState'];
hasRefinements(facet: string): boolean;
isExcluded: SearchParameters['isExcludeRefined'];
/**
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasRefinements}
*/
isDisjunctiveRefined: SearchParameters['isDisjunctiveFacetRefined'];
hasTag: SearchParameters['isTagRefined'];
/**
* @deprecated since 2.4.0, see {@link AlgoliaSearchHelper#hasTag}
*/
isTagRefined: SearchParameters['isTagRefined'];
getIndex(): string;
/**
* @deprecated
*/
getCurrentPage(): number;
getPage(): number;
getTags(): string[];
getRefinements(facetName: string): any[];
getNumericRefinement: SearchParameters['getNumericRefinement'];
getHierarchicalFacetBreadcrumb: SearchParameters['getHierarchicalFacetBreadcrumb'];
/**
* @deprecated
*/
containsRefinement(...any: any[]): any;
clearCache(): this;
setClient(client: SearchClient): this;
getClient(): SearchClient;
derive(
deriveFn: (oldParams: SearchParameters) => SearchParameters,
deriveRecommendFn?: (
oldParams: RecommendParameters
) => RecommendParameters
): DerivedHelper;
detachDerivedHelper(derivedHelper: DerivedHelper): void;
hasPendingRequests(): boolean;
}
interface DerivedHelper extends EventEmitter {
on(
event: 'search',
cb: (res: { state: SearchParameters; results: SearchResults }) => void
): this;
on(
event: 'result',
cb: (res: { results: SearchResults; state: SearchParameters }) => void
): this;
on(
event: 'recommend:result',
cb: (res: {
recommend: {
results: RecommendResults | null;
state: RecommendParameters;
};
}) => void
): this;
on(event: 'error', cb: (res: { error: Error }) => void): this;
lastResults: SearchResults | null;
lastRecommendResults: RecommendResults | null;
detach(): void;
getModifiedState(): SearchParameters;
getModifiedRecommendState(): RecommendParameters;
}
namespace SearchForFacetValues {
/**
* Structure of each result when using
* [`searchForFacetValues()`](reference.html#AlgoliaSearchHelper#searchForFacetValues)
*/
export interface Hit {
value: string;
escapedValue: string;
highlighted: string;
count: number;
isRefined: boolean;
}
/**
* Structure of the data resolved by the
* [`searchForFacetValues()`](reference.html#AlgoliaSearchHelper#searchForFacetValues)
* promise.
*/
export interface Result {
facetHits: Hit[];
processingTimeMS: number;
}
}
export interface PlainSearchParameters extends SearchOptions {
/**
* Targeted index. This parameter is mandatory.
*/
index?: string;
/**
* This attribute contains the list of all the disjunctive facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
*/
disjunctiveFacets?: string[];
/**
* This attribute contains the list of all the hierarchical facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
* Hierarchical facets are a sub type of disjunctive facets that
* let you filter faceted attributes hierarchically.
*/
hierarchicalFacets?: SearchParameters.HierarchicalFacet[];
// Refinements
/**
* This attribute contains all the filters that need to be
* applied on the conjunctive facets. Each facet must be properly
* defined in the `facets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
facetsRefinements?: { [facet: string]: SearchParameters.FacetList };
/**
* This attribute contains all the filters that need to be
* excluded from the conjunctive facets. Each facet must be properly
* defined in the `facets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters excluded for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
facetsExcludes?: { [facet: string]: SearchParameters.FacetList };
/**
* This attribute contains all the filters that need to be
* applied on the disjunctive facets. Each facet must be properly
* defined in the `disjunctiveFacets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
disjunctiveFacetsRefinements?: {
[facet: string]: SearchParameters.FacetList;
};
/**
* This attribute contains all the filters that need to be
* applied on the numeric attributes.
*
* The key is the name of the attribute, and the value is the
* filters to apply to this attribute.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `numericFilters` attribute.
*/
numericRefinements?: { [facet: string]: SearchParameters.OperatorList };
/**
* This attribute contains all the tags used to refine the query.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `tagFilters` attribute.
*/
tagRefinements?: string[];
/**
* This attribute contains all the filters that need to be
* applied on the hierarchical facets. Each facet must be properly
* defined in the `hierarchicalFacets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name. The FacetList values
* are structured as a string that contain the values for each level
* separated by the configured separator.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
hierarchicalFacetsRefinements?: {
[facet: string]: SearchParameters.FacetList;
};
// types missing in @types/algoliasearch, so duplicated from v4
ruleContexts?: string[];
optionalFilters?: Array<string | string[]>;
queryLanguages?: SupportedLanguage[];
/**
* The relevancy threshold to apply to search in a virtual index [0-100]. A bigger
* value means fewer but more relevant results, a smaller value means more but
* less relevant results.
*/
relevancyStrictness?: number;
}
export class SearchParameters implements PlainSearchParameters {
managedParameters: [
'index',
'facets',
'disjunctiveFacets',
'facetsRefinements',
'hierarchicalFacets',
'facetsExcludes',
'disjunctiveFacetsRefinements',
'numericRefinements',
'tagRefinements',
'hierarchicalFacetsRefinements'
];
constructor(newParameters?: PlainSearchParameters);
/* Add a disjunctive facet to the disjunctiveFacets attribute of the helper configuration, if it isn't already present. */
addDisjunctiveFacet(facet: string): SearchParameters;
/* Adds a refinement on a disjunctive facet. */
addDisjunctiveFacetRefinement(
facet: string,
value: string
): SearchParameters;
/* Exclude a value from a "normal" facet */
addExcludeRefinement(facet: string, value: string): SearchParameters;
/* Add a facet to the facets attribute of the helper configuration, if it isn't already present. */
addFacet(facet: string): SearchParameters;
/* Add a refinement on a "normal" facet */
addFacetRefinement(facet: string, value: string): SearchParameters;
addHierarchicalFacet(
facet: SearchParameters.HierarchicalFacet
): SearchParameters;
addHierarchicalFacetRefinement(
facet: string,
path: string
): SearchParameters;
addNumericRefinement(
attribute: string,
operator: SearchParameters.Operator,
value: number | number[]
): SearchParameters;
addTagRefinement(tag: string): SearchParameters;
clearRefinements(
attribute?:
| string
| ((value: any, attribute: string, type: string) => void)
): SearchParameters;
clearTags(): SearchParameters;
getConjunctiveRefinements(facetName: string): string[];
getDisjunctiveRefinements(facetName: string): string[];
getExcludeRefinements(facetName: string): string[];
getHierarchicalFacetBreadcrumb(facetName: string): string[];
getHierarchicalFacetByName(hierarchicalFacetName: string): any;
getHierarchicalRefinement(facetName: string): string[];
getNumericRefinements(facetName: string): SearchParameters.OperatorList;
getNumericRefinement(
attribute: string,
operator: SearchParameters.Operator
): Array<number | number[]>;
getQueryParams(): SearchOptions;
getRefinedDisjunctiveFacets(facet: string, value: any): string[];
getRefinedHierarchicalFacets(facet: string, value: any): string[];
getUnrefinedDisjunctiveFacets(): string[];
isConjunctiveFacet(facet: string): boolean;
isDisjunctiveFacetRefined(facet: string, value?: string): boolean;
isDisjunctiveFacet(facet: string): boolean;
isExcludeRefined(facet: string, value?: string): boolean;
isFacetRefined(facet: string, value?: string): boolean;
isHierarchicalFacetRefined(facet: string, value?: string): boolean;
isHierarchicalFacet(facet: string): boolean;
isNumericRefined(
attribute: string,
operator?: SearchParameters.Operator,
value?: string
): boolean;
isTagRefined(tag: string): boolean;
static make(newParameters: PlainSearchParameters): SearchParameters;
removeExcludeRefinement(facet: string, value: string): SearchParameters;
removeFacet(facet: string): SearchParameters;
removeFacetRefinement(facet: string, value?: string): SearchParameters;
removeDisjunctiveFacet(facet: string): SearchParameters;
removeDisjunctiveFacetRefinement(
facet: string,
value?: string
): SearchParameters;
removeHierarchicalFacet(facet: string): SearchParameters;
removeHierarchicalFacetRefinement(facet: string): SearchParameters;
removeNumericRefinement(
attribute: string,
operator?: string,
value?: string
): SearchParameters;
removeTagRefinement(tag: string): SearchParameters;
resetPage(): SearchParameters;
setDisjunctiveFacets(facets: string[]): SearchParameters;
setFacets(facets: string[]): SearchParameters;
setHitsPerPage(n: number): SearchParameters;
setIndex(index: string): SearchParameters;
setPage(newPage: number): SearchParameters;
setQueryParameters(params: PlainSearchParameters): SearchParameters;
setQueryParameter<SearchParameter extends keyof PlainSearchParameters>(
parameter: SearchParameter,
value: PlainSearchParameters[SearchParameter]
): SearchParameters;
setQuery(newQuery: string): SearchParameters;
setTypoTolerance(typoTolerance: string): SearchParameters;
toggleDisjunctiveFacetRefinement(
facet: string,
value: any
): SearchParameters;
toggleExcludeFacetRefinement(facet: string, value: any): SearchParameters;
toggleConjunctiveFacetRefinement(
facet: string,
value: any
): SearchParameters;
toggleHierarchicalFacetRefinement(
facet: string,
value: any
): SearchParameters;
toggleFacetRefinement(facet: string, value: any): SearchParameters;
toggleTagRefinement(tag: string): SearchParameters;
static validate(
currentState: SearchParameters,
parameters: PlainSearchParameters
): null | Error;
/**
* implementation of PlainSearchParameters, copied because it's an interface.
* Notable difference is that the managed search parameters are not optional,
* ideally this would be Required<ManagedParameters> where ManagedParameters
* are the following ones.
*/
/**
* Targeted index. This parameter is mandatory.
*/
index: string;
/**
* This attribute contains the list of all the disjunctive facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
*/
disjunctiveFacets: string[];
/**
* This attribute contains the list of all the hierarchical facets
* used. This list will be added to requested facets in the
* [facets attribute](https://www.algolia.com/doc/rest-api/search#param-facets) sent to algolia.
* Hierarchical facets are a sub type of disjunctive facets that
* let you filter faceted attributes hierarchically.
*/
hierarchicalFacets: SearchParameters.HierarchicalFacet[];
// Refinements
/**
* This attribute contains all the filters that need to be
* applied on the conjunctive facets. Each facet must be properly
* defined in the `facets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
facetsRefinements: { [facet: string]: SearchParameters.FacetList };
/**
* This attribute contains all the filters that need to be
* excluded from the conjunctive facets. Each facet must be properly
* defined in the `facets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters excluded for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
facetsExcludes: { [facet: string]: SearchParameters.FacetList };
/**
* This attribute contains all the filters that need to be
* applied on the disjunctive facets. Each facet must be properly
* defined in the `disjunctiveFacets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
disjunctiveFacetsRefinements: {
[facet: string]: SearchParameters.FacetList;
};
/**
* This attribute contains all the filters that need to be
* applied on the numeric attributes.
*
* The key is the name of the attribute, and the value is the
* filters to apply to this attribute.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `numericFilters` attribute.
*/
numericRefinements: { [facet: string]: SearchParameters.OperatorList };
/**
* This attribute contains all the tags used to refine the query.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `tagFilters` attribute.
*/
tagRefinements: string[];
/**
* This attribute contains all the filters that need to be
* applied on the hierarchical facets. Each facet must be properly
* defined in the `hierarchicalFacets` attribute.
*
* The key is the name of the facet, and the `FacetList` contains all
* filters selected for the associated facet name. The FacetList values
* are structured as a string that contain the values for each level
* separated by the configured separator.
*
* When querying algolia, the values stored in this attribute will
* be translated into the `facetFilters` attribute.
*/
hierarchicalFacetsRefinements: {
[facet: string]: SearchParameters.FacetList;
};
/* end implementation of PlainSearchParameters */
/**
* Implementation of regular search parameters, copied from algoliasearch.QueryParameters
* Ideally there'd be a way to automatically implement this interface, but that
* isn't possible.
*/
/**
* Query string used to perform the search
* default: ''
* https://www.algolia.com/doc/api-reference/api-parameters/query/
*/
query?: string;
/**
* Filter the query with numeric, facet or/and tag filters
* default: ""
* https://www.algolia.com/doc/api-reference/api-parameters/filters/
*/
filters?: string;
/**
* A string that contains the list of attributes you want to retrieve in order to minimize the size of the JSON answer.
* default: *
* https://www.algolia.com/doc/api-reference/api-parameters/attributesToRetrieve/
*/
attributesToRetrieve?: string[];
/**
* List of attributes you want to use for textual search
* default: attributeToIndex
* https://www.algolia.com/doc/api-reference/api-parameters/restrictSearchableAttributes/
*/
restrictSearchableAttributes?: string[];
/**
* You can use facets to retrieve only a part of your attributes declared in attributesForFaceting attributes
* default: []
* https://www.algolia.com/doc/api-reference/api-parameters/facets/
*/
facets?: string[];
/**
* Force faceting to be applied after de-duplication (via the Distinct setting).
* When using the distinct setting in combination with faceting, facet counts may be higher than expected.
* This is because the engine, by default, computes faceting before applying de-duplication (distinct).
* When facetingAfterDistinct is set to true, the engine calculates faceting after the de-duplication has been applied.
* default ""
* https://www.algolia.com/doc/api-reference/api-parameters/facetingAfterDistinct/
*/
facetingAfterDistinct?: boolean;
/**
* Limit the number of facet values returned for each facet.
* default: 100
* https://www.algolia.com/doc/api-reference/api-parameters/maxValuesPerFacet/
*/
maxValuesPerFacet?: number;
/**
* Default list of attributes to highlight. If set to null, all indexed attributes are highlighted.
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/attributesToHighlight/
*/
attributesToHighlight?: string[];
/**
* Default list of attributes to snippet alongside the number of words to return
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/attributesToSnippet/
*/
attributesToSnippet?: string[];
/**
* Specify the string that is inserted before the highlighted parts in the query result
* default: <em>
* https://www.algolia.com/doc/api-reference/api-parameters/highlightPreTag/
*/
highlightPreTag?: string;
/**
* Specify the string that is inserted after the highlighted parts in the query result
* default: </em>
* https://www.algolia.com/doc/api-reference/api-parameters/highlightPostTag/
*/
highlightPostTag?: string;
/**
* String used as an ellipsis indicator when a snippet is truncated.
* default: …
* https://www.algolia.com/doc/api-reference/api-parameters/snippetEllipsisText/
*/
snippetEllipsisText?: string;
/**
* If set to true, restrict arrays in highlights and snippets to items that matched the query at least partially else return all array items in highlights and snippets
* default: false
* https://www.algolia.com/doc/api-reference/api-parameters/restrictHighlightAndSnippetArrays/
*/
restrictHighlightAndSnippetArrays?: boolean;
/**
* Pagination parameter used to select the number of hits per page
* default: 20
* https://www.algolia.com/doc/api-reference/api-parameters/hitsPerPage/
*/
hitsPerPage?: number;
/**
* Pagination parameter used to select the page to retrieve.
* default: 0
* https://www.algolia.com/doc/api-reference/api-parameters/page/
*/
page?: number;
/**
* Offset of the first hit to return
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/offset/
*/
offset?: number;
/**
* Number of hits to return.
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/length/
*/
length?: number;
/**
* The minimum number of characters needed to accept one typo.
* default: 4
* https://www.algolia.com/doc/api-reference/api-parameters/minWordSizefor1Typo/
*/
minWordSizefor1Typo?: number;
/**
* The minimum number of characters needed to accept two typo.
* fault: 8
* https://www.algolia.com/doc/api-reference/api-parameters/minWordSizefor2Typos/
*/
minWordSizefor2Typos?: number;
/**
* This option allows you to control the number of typos allowed in the result set:
* default: true
* 'true' The typo tolerance is enabled and all matching hits are retrieved
* 'false' The typo tolerance is disabled. All results with typos will be hidden.
* 'min' Only keep results with the minimum number of typos
* 'strict' Hits matching with 2 typos are not retrieved if there are some matching without typos.
* https://www.algolia.com/doc/api-reference/api-parameters/typoTolerance/
*/
typoTolerance?: boolean;
/**
* If set to false, disables typo tolerance on numeric tokens (numbers).
* default:
* https://www.algolia.com/doc/api-reference/api-parameters/allowTyposOnNumericTokens/
*/
allowTyposOnNumericTokens?: boolean;
/**
* If set to true, plural won't be considered as a typo
* default: false
* https://www.algolia.com/doc/api-reference/api-parameters/ignorePlurals/
*/
ignorePlurals?: boolean;
/**
* List of attributes on which you want to disable typo tolerance
* default: []
* https://www.algolia.com/doc/api-reference/api-parameters/disableTypoToleranceOnAttributes/
*/
disableTypoToleranceOnAttributes?: string[];
/**
* Search for entries around a given location
* default: ""
* https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLng/
*/
aroundLatLng?: string;
/**
* Search for entries around a given latitude/longitude automatically computed from user IP address.
* default: ""
* https://www.algolia.com/doc/api-reference/api-parameters/aroundLatLngViaIP/
*/
aroundLatLngViaIP?: boolean;
/**
* Control the radius associated with a geo search. Defined in meters.
* default: null
* You can specify aroundRadius=all if you want to compute the geo distance without filtering in a geo area
* https://www.algolia.com/doc/api-reference/api-parameters/aroundRadius/
*/
aroundRadius?: number | 'all';
/**
* Control the precision of a geo search
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/aroundPrecision/
*/
aroundPrecision?: number;
/**
* Define the minimum radius used for a geo search when aroundRadius is not set.
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/minimumAroundRadius/
*/
minimumAroundRadius?: number;
/**
* Search entries inside a given area defined by the two extreme points of a rectangle
* default: null
* https://www.algolia.com/doc/api-reference/api-parameters/insideBoundingBox/
*/
insideBoundingBox?: Array<[number, number, number, number]>;
/**
* Selects how the query words are interpreted
* default: 'prefixLast'
* 'prefixAll' All query words are interpreted as prefixes. This option is not recommended.
* 'prefixLast' Only the last word is interpreted as a prefix (default behavior).
* 'prefixNone' No query word is interpreted as a prefix. This option is not recommended.
* https://www.algolia.com/doc/api-reference/api-parameters/queryType/
*/
queryType?: 'prefixAll' | 'prefixLast' | 'prefixNone';
/**
* Search entries inside a given area defined by a set of points
* default: ''
* https://www.algolia.com/doc/api-reference/api-parameters/insidePolygon/
*/
insidePolygon?: number[][];
/**
* This option is used to select a strategy in order to avoid having an empty result page
* default: 'none'
* 'lastWords' When a query does not return any results, the last word will be added as optional
* 'firstWords' When a query does not return any results, the first word will be added as optional
* 'allOptional' When a query does not return any results, a second trial will be made with all words as optional
* 'none' No specific processing is done when a query does not return any results
* https://www.algolia.com/doc/api-reference/api-parameters/removeWordsIfNoResults/
*/
removeWordsIfNoResults?:
| 'none'
| 'lastWords'
| 'firstWords'
| 'allOptional';
/**
* Enables the advanced query syntax