forked from meilisearch/meilisearch-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingsHandler.java
More file actions
857 lines (794 loc) · 31.6 KB
/
SettingsHandler.java
File metadata and controls
857 lines (794 loc) · 31.6 KB
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
package com.meilisearch.sdk;
import com.meilisearch.sdk.exceptions.MeilisearchException;
import com.meilisearch.sdk.http.URLBuilder;
import com.meilisearch.sdk.model.Embedder;
import com.meilisearch.sdk.model.Faceting;
import com.meilisearch.sdk.model.FilterableAttributesConfig;
import com.meilisearch.sdk.model.FilterableAttributesLegacyAdapter;
import com.meilisearch.sdk.model.LocalizedAttribute;
import com.meilisearch.sdk.model.Pagination;
import com.meilisearch.sdk.model.Settings;
import com.meilisearch.sdk.model.TaskInfo;
import com.meilisearch.sdk.model.TypoTolerance;
import java.util.Map;
/**
* Class covering the Meilisearch Settings API
*
* @see <a href="https://www.meilisearch.com/docs/reference/api/settings">API specification</a>
* @see Settings
*/
public class SettingsHandler {
private final HttpClient httpClient;
/**
* Constructor for the Meilisearch Settings object
*
* @param config Meilisearch configuration
*/
protected SettingsHandler(Config config) {
httpClient = config.httpClient;
}
/**
* Gets the settings of the index
*
* @param uid Index identifier
* @return settings of a given uid as String
* @throws MeilisearchException if an error occurs
*/
Settings getSettings(String uid) throws MeilisearchException {
return httpClient.get(settingsPath(uid).getURL(), Settings.class);
}
/**
* Updates the settings of the index
*
* @param uid Index identifier
* @param settings the data that contains the new settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateSettings(String uid, Settings settings) throws MeilisearchException {
return httpClient.patch(settingsPath(uid).getURL(), settings, TaskInfo.class);
}
/**
* Resets the settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetSettings(String uid) throws MeilisearchException {
return httpClient.delete(settingsPath(uid).getURL(), TaskInfo.class);
}
/**
* Gets the ranking rules settings of the index
*
* @param uid Index identifier
* @return an array of strings that contains the ranking rules settings
* @throws MeilisearchException if an error occurs
*/
String[] getRankingRulesSettings(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("ranking-rules").getURL(), String[].class);
}
/**
* Updates the ranking rules settings of the index
*
* @param uid Index identifier
* @param rankingRules the data that contains the new settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateRankingRulesSettings(String uid, String[] rankingRules)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("ranking-rules").getURL(),
rankingRules == null ? httpClient.jsonHandler.encode(rankingRules) : rankingRules,
TaskInfo.class);
}
/**
* Resets the ranking rules settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetRankingRulesSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("ranking-rules").getURL(), TaskInfo.class);
}
/**
* Gets the synonyms settings of the index
*
* @param uid Index identifier
* @return a Map that contains all synonyms and their associated words
* @throws MeilisearchException if an error occurs
*/
Map<String, String[]> getSynonymsSettings(String uid) throws MeilisearchException {
return httpClient.jsonHandler.decode(
httpClient.get(settingsPath(uid).addSubroute("synonyms").getURL(), String.class),
Map.class);
}
/**
* Updates the synonyms settings of the index
*
* @param uid Index identifier
* @param synonyms a Map that contains the new synonyms settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateSynonymsSettings(String uid, Map<String, String[]> synonyms)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("synonyms").getURL(),
synonyms == null ? httpClient.jsonHandler.encode(synonyms) : synonyms,
TaskInfo.class);
}
/**
* Resets the synonyms settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetSynonymsSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("synonyms").getURL(), TaskInfo.class);
}
/**
* Gets the stop-words settings of the index
*
* @param uid Index identifier
* @return an array of strings that contains the stop-words
* @throws MeilisearchException if an error occurs
*/
String[] getStopWordsSettings(String uid) throws MeilisearchException {
return httpClient.get(settingsPath(uid).addSubroute("stop-words").getURL(), String[].class);
}
/**
* Updates the stop-words settings of the index
*
* @param uid Index identifier
* @param stopWords an array of strings that contains the new stop-words settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateStopWordsSettings(String uid, String[] stopWords) throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("stop-words").getURL(),
stopWords == null ? httpClient.jsonHandler.encode(stopWords) : stopWords,
TaskInfo.class);
}
/**
* Resets the stop-words settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetStopWordsSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("stop-words").getURL(), TaskInfo.class);
}
/**
* Gets the searchable attributes of the index
*
* @param uid Index identifier
* @return an array of strings that contains the searchable attributes
* @throws MeilisearchException if an error occurs
*/
String[] getSearchableAttributesSettings(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("searchable-attributes").getURL(), String[].class);
}
/**
* Updates the searchable attributes of the index
*
* @param uid Index identifier
* @param searchableAttributes an array of strings that contains the new searchable attributes
* settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateSearchableAttributesSettings(String uid, String[] searchableAttributes)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("searchable-attributes").getURL(),
searchableAttributes == null
? httpClient.jsonHandler.encode(searchableAttributes)
: searchableAttributes,
TaskInfo.class);
}
/**
* Resets the searchable attributes of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetSearchableAttributesSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("searchable-attributes").getURL(), TaskInfo.class);
}
/**
* Gets the display attributes of the index
*
* @param uid Index identifier
* @return an array of strings that contains attributes of the index to display
* @throws MeilisearchException if an error occurs
*/
String[] getDisplayedAttributesSettings(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("displayed-attributes").getURL(), String[].class);
}
/**
* Updates the display attributes of the index
*
* @param uid Index identifier
* @param displayAttributes an array of strings that contains the new displayed attributes
* settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateDisplayedAttributesSettings(String uid, String[] displayAttributes)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("displayed-attributes").getURL(),
displayAttributes == null
? httpClient.jsonHandler.encode(displayAttributes)
: displayAttributes,
TaskInfo.class);
}
/**
* Resets the displayed attributes of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetDisplayedAttributesSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("displayed-attributes").getURL(), TaskInfo.class);
}
/**
* Gets the localized attributes of the index
*
* @param uid Index identifier
* @return an array of localizedattributes that contains attributes of the index to display
* @throws MeilisearchException if an error occurs
*/
LocalizedAttribute[] getLocalizedAttributes(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("localized-attributes").getURL(),
LocalizedAttribute[].class);
}
/**
* Updates the localized attributes of the index.
*
* @param uid Index identifier
* @param localizedAttributes an array of LocalizedAttributes that contain patterns and locales
* settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateLocalizedAttributesSettings(String uid, LocalizedAttribute[] localizedAttributes)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("localized-attributes").getURL(),
localizedAttributes == null
? httpClient.jsonHandler.encode(localizedAttributes)
: localizedAttributes,
TaskInfo.class);
}
/**
* Resets the localized attributes of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetLocalizedAttributesSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("localized-attributes").getURL(), TaskInfo.class);
}
/**
* Gets the filterableAttributes of the index (legacy String[] view).
*
* @param uid Index identifier
* @return an array of strings that contains the filterable attributes settings
* @throws MeilisearchException if an error occurs or granular configs cannot be reduced
*/
String[] getFilterableAttributesSettings(String uid) throws MeilisearchException {
return FilterableAttributesLegacyAdapter.toLegacyNamesOrThrow(
getGranularFilterableAttributesSettings(uid));
}
/**
* Gets the filterableAttributes of the index (granular view).
*
* @param uid Index identifier
* @return an array of filterable attribute configs (strings or granular objects)
* @throws MeilisearchException if an error occurs
* @since 1.14.0
*/
FilterableAttributesConfig[] getGranularFilterableAttributesSettings(String uid)
throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("filterable-attributes").getURL(),
FilterableAttributesConfig[].class);
}
/**
* Updates the filterable attributes of the index using the legacy String[] view. This will
* re-index all documents in the index.
*
* @param uid Index identifier
* @param filterableAttributes an array of strings that contains the new filterable attributes
* settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateFilterableAttributesSettings(String uid, String[] filterableAttributes)
throws MeilisearchException {
return updateGranularFilterableAttributesSettings(
uid, FilterableAttributesLegacyAdapter.fromLegacyNames(filterableAttributes));
}
/**
* Updates the filterable attributes of the index using the granular representation. This will
* re-index all documents in the index.
*
* @param uid Index identifier
* @param filterableAttributes Array of filterable attribute configs (strings or granular
* objects) that contains the new filterable attributes settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
* @since 1.14.0
*/
TaskInfo updateGranularFilterableAttributesSettings(
String uid, FilterableAttributesConfig[] filterableAttributes)
throws MeilisearchException {
Object body =
filterableAttributes == null
? httpClient.jsonHandler.encode(filterableAttributes)
: filterableAttributes;
return httpClient.put(
settingsPath(uid).addSubroute("filterable-attributes").getURL(),
body,
TaskInfo.class);
}
/**
* Resets the filterable attributes of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetFilterableAttributesSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("filterable-attributes").getURL(), TaskInfo.class);
}
/**
* Gets the sortableAttributes of the index
*
* @param uid Index identifier
* @return an array of strings that contains the sortable attributes settings
* @throws MeilisearchException if an error occurs
*/
String[] getSortableAttributesSettings(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("sortable-attributes").getURL(), String[].class);
}
/**
* Updates the sortable attributes of the index. This will re-index all documents in the index
*
* @param uid Index identifier
* @param sortableAttributes an array of strings that contains the new sortable attributes
* settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateSortableAttributesSettings(String uid, String[] sortableAttributes)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("sortable-attributes").getURL(),
sortableAttributes == null
? httpClient.jsonHandler.encode(sortableAttributes)
: sortableAttributes,
TaskInfo.class);
}
/**
* Resets the sortable attributes of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetSortableAttributesSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("sortable-attributes").getURL(), TaskInfo.class);
}
/**
* Gets the distinct attribute field of the index
*
* @param uid Index identifier
* @return a string of the distinct attribute field
* @throws MeilisearchException if an error occurs
*/
String getDistinctAttributeSettings(String uid) throws MeilisearchException {
String response =
httpClient.get(
settingsPath(uid).addSubroute("distinct-attribute").getURL(), String.class);
return response.equals("null") ? null : response.substring(1, response.length() - 1);
}
/**
* Updates the distinct attribute field of the index
*
* @param uid Index identifier
* @param distinctAttribute a String that contains the new distinct attributes settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateDistinctAttributeSettings(String uid, String distinctAttribute)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("distinct-attribute").getURL(),
distinctAttribute == null
? httpClient.jsonHandler.encode(distinctAttribute)
: "\"" + distinctAttribute + "\"",
TaskInfo.class);
}
/**
* Resets the distinct attribute field of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetDistinctAttributeSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("distinct-attribute").getURL(), TaskInfo.class);
}
/**
* Gets the typo tolerance settings of the index
*
* @param uid Index identifier
* @return a TypoTolerance instance that contains all typo tolerance settings
* @throws MeilisearchException if an error occurs
*/
TypoTolerance getTypoToleranceSettings(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("typo-tolerance").getURL(), TypoTolerance.class);
}
/**
* Updates the typo tolerance settings of the index
*
* @param uid Index identifier
* @param typoTolerance a TypoTolerance instance that contains the new typo tolerance settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateTypoToleranceSettings(String uid, TypoTolerance typoTolerance)
throws MeilisearchException {
return httpClient.patch(
settingsPath(uid).addSubroute("typo-tolerance").getURL(),
typoTolerance == null
? httpClient.jsonHandler.encode(typoTolerance)
: typoTolerance,
TaskInfo.class);
}
/**
* Resets the typo tolerance settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetTypoToleranceSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("typo-tolerance").getURL(), TaskInfo.class);
}
/**
* Gets the pagination settings of the index
*
* @param uid Index identifier
* @return a Pagination instance that contains all pagination settings
* @throws MeilisearchException if an error occurs
*/
Pagination getPaginationSettings(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("pagination").getURL(), Pagination.class);
}
/**
* Updates the pagination settings of the index
*
* @param uid Index identifier
* @param pagination a Pagination instance that contains the new pagination settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updatePaginationSettings(String uid, Pagination pagination)
throws MeilisearchException {
return httpClient.patch(
settingsPath(uid).addSubroute("pagination").getURL(),
pagination == null ? httpClient.jsonHandler.encode(pagination) : pagination,
TaskInfo.class);
}
/**
* Resets the pagination settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetPaginationSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("pagination").getURL(), TaskInfo.class);
}
/**
* Gets the faceting settings of the index
*
* @param uid Index identifier
* @return a Faceting instance that contains all faceting settings
* @throws MeilisearchException if an error occurs
*/
Faceting getFacetingSettings(String uid) throws MeilisearchException {
return httpClient.get(settingsPath(uid).addSubroute("faceting").getURL(), Faceting.class);
}
/**
* Updates the pagination settings of the index
*
* @param uid Index identifier
* @param faceting a Faceting instance that contains the new faceting settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateFacetingSettings(String uid, Faceting faceting) throws MeilisearchException {
return httpClient.patch(
settingsPath(uid).addSubroute("faceting").getURL(),
faceting == null ? httpClient.jsonHandler.encode(faceting) : faceting,
TaskInfo.class);
}
/**
* Reset the faceting settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetFacetingSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("faceting").getURL(), TaskInfo.class);
}
/**
* Gets the dictionary settings of the index
*
* @param uid Index identifier
* @return an array of strings that contains the dictionary
* @throws MeilisearchException if an error occurs
*/
String[] getDictionarySettings(String uid) throws MeilisearchException {
return httpClient.get(settingsPath(uid).addSubroute("dictionary").getURL(), String[].class);
}
/**
* Updates the dictionary settings of the index
*
* @param uid Index identifier
* @param dictionary an array of strings that contains the new dictionary settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateDictionarySettings(String uid, String[] dictionary) throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("dictionary").getURL(),
dictionary == null ? httpClient.jsonHandler.encode(dictionary) : dictionary,
TaskInfo.class);
}
/**
* Resets the dictionary settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetDictionarySettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("dictionary").getURL(), TaskInfo.class);
}
/**
* Gets the proximity precision level of the index
*
* @param uid Index identifier
* @return a string of the proximity precision level
* @throws MeilisearchException if an error occurs
*/
String getProximityPrecisionSettings(String uid) throws MeilisearchException {
String response =
httpClient.get(
settingsPath(uid).addSubroute("proximity-precision").getURL(),
String.class);
return response.substring(1, response.length() - 1);
}
/**
* Updates the proximity precision level of the index
*
* @param uid Index identifier
* @param proximityPrecision a String that contains the new proximity precision level settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateProximityPrecisionSettings(String uid, String proximityPrecision)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("proximity-precision").getURL(),
proximityPrecision == null
? httpClient.jsonHandler.encode(proximityPrecision)
: "\"" + proximityPrecision + "\"",
TaskInfo.class);
}
/**
* Resets the proximity precision level of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetProximityPrecisionSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("proximity-precision").getURL(), TaskInfo.class);
}
/** Creates an URLBuilder for the constant route settings */
private URLBuilder settingsPath(String uid) {
return new URLBuilder("/indexes").addSubroute(uid).addSubroute("/settings");
}
/**
* Gets the search cutoff value of the index
*
* @param uid Index identifier
* @return an integer of the search cutoff value
* @throws MeilisearchException if an error occurs
*/
Integer getSearchCutoffMsSettings(String uid) throws MeilisearchException {
String response =
httpClient.get(
settingsPath(uid).addSubroute("search-cutoff-ms").getURL(), String.class);
return response.equals("null") ? null : Integer.valueOf(response);
}
/**
* Updates the search cutoff value of the index
*
* @param uid Index identifier
* @param milliseconds an Integer that contains the new search cutoff value
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateSearchCutoffMsSettings(String uid, Integer milliseconds)
throws MeilisearchException {
return httpClient.put(
settingsPath(uid).addSubroute("search-cutoff-ms").getURL(),
milliseconds == null ? httpClient.jsonHandler.encode(milliseconds) : milliseconds,
TaskInfo.class);
}
/**
* Resets the search cutoff value of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetSearchCutoffMsSettings(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("search-cutoff-ms").getURL(), TaskInfo.class);
}
/**
* Gets the separator tokens of the index
*
* @param uid Index identifier
* @return separator tokens of a given uid as String
* @throws MeilisearchException if an error occurs
*/
public String[] getSeparatorTokensSettings(String uid) {
return httpClient.get(
settingsPath(uid).addSubroute("separator-tokens").getURL(), String[].class);
}
/**
* Updates the separator tokens settings of the index
*
* @param uid Index identifier
* @param separatorTokens an array of strings that contains the new separator tokens settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo updateSeparatorTokensSettings(String uid, String[] separatorTokens) {
return httpClient.put(
settingsPath(uid).addSubroute("separator-tokens").getURL(),
separatorTokens == null
? httpClient.jsonHandler.encode(separatorTokens)
: separatorTokens,
TaskInfo.class);
}
/**
* Resets the separator tokens settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo resetSeparatorTokensSettings(String uid) {
return httpClient.delete(
settingsPath(uid).addSubroute("separator-tokens").getURL(), TaskInfo.class);
}
/**
* Gets the non-separator tokens of the index
*
* @param uid Index identifier
* @return non-separator tokens of a given uid as String
* @throws MeilisearchException if an error occurs
*/
public String[] getNonSeparatorTokensSettings(String uid) {
return httpClient.get(
settingsPath(uid).addSubroute("non-separator-tokens").getURL(), String[].class);
}
/**
* Updates the non-separator tokens settings of the index
*
* @param uid Index identifier
* @param separatorTokens an array of strings that contains the new separator tokens settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo updateNonSeparatorTokensSettings(String uid, String[] separatorTokens) {
return httpClient.put(
settingsPath(uid).addSubroute("non-separator-tokens").getURL(),
separatorTokens == null
? httpClient.jsonHandler.encode(separatorTokens)
: separatorTokens,
TaskInfo.class);
}
/**
* Resets the non-separator tokens settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
public TaskInfo resetNonSeparatorTokensSettings(String uid) {
return httpClient.delete(
settingsPath(uid).addSubroute("non-separator-tokens").getURL(), TaskInfo.class);
}
/**
* Gets the embedders settings of the index
*
* @param uid Index identifier
* @return a Map that contains all embedders settings
* @throws MeilisearchException if an error occurs
*/
Map<String, Embedder> getEmbedders(String uid) throws MeilisearchException {
return httpClient.get(
settingsPath(uid).addSubroute("embedders").getURL(),
Map.class,
String.class,
Embedder.class);
}
/**
* Updates the embedders settings of the index
*
* @param uid Index identifier
* @param embedders a Map that contains the new embedders settings
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo updateEmbedders(String uid, Map<String, Embedder> embedders)
throws MeilisearchException {
return httpClient.patch(
settingsPath(uid).addSubroute("embedders").getURL(),
embedders == null ? null : httpClient.jsonHandler.encode(embedders),
TaskInfo.class);
}
/**
* Resets the embedders settings of the index
*
* @param uid Index identifier
* @return TaskInfo instance
* @throws MeilisearchException if an error occurs
*/
TaskInfo resetEmbedders(String uid) throws MeilisearchException {
return httpClient.delete(
settingsPath(uid).addSubroute("embedders").getURL(), TaskInfo.class);
}
}