-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathsearch_commands.rs
3587 lines (3282 loc) · 119 KB
/
search_commands.rs
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
use crate::{
client::{prepare_command, PreparedCommand},
commands::{GeoUnit, SortOrder},
resp::{
cmd, deserialize_vec_of_pairs, CollectionResponse, Command, CommandArgs,
KeyValueCollectionResponse, MultipleArgsCollection, PrimitiveResponse, RespDeserializer,
SingleArg, SingleArgCollection, ToArgs, Value, VecOfPairsSeed,
},
};
use serde::{
de::{self, value::SeqAccessDeserializer, DeserializeOwned, DeserializeSeed, Visitor},
Deserialize, Deserializer,
};
use std::{collections::HashMap, fmt, future};
/// A group of Redis commands related to [`RedisSearch`](https://redis.io/docs/stack/search/)
///
/// # See Also
/// * [RedisSearch Commands](https://redis.io/commands/?group=search)
/// * [Auto-Suggest Commands](https://redis.io/commands/?group=suggestion)
pub trait SearchCommands<'a> {
/// Run a search query on an index,
/// and perform aggregate transformations on the results,
/// extracting statistics etc from them
///
/// # Arguments
/// * `index` - index against which the query is executed.
/// * `query`- is base filtering query that retrieves the documents.\
/// It follows the exact same syntax as the search query,\
/// including filters, unions, not, optional, and so on.
/// * `options` - See [`FtAggregateOptions`](FtAggregateOptions)
///
/// # Returns
/// An instance of [`FtAggregateResult`](FtAggregateResult)
///
/// # See Also
/// * [<https://redis.io/commands/ft.aggregate/>](https://redis.io/commands/ft.aggregate/)
/// * [`RedisSeach Aggregations`](https://redis.io/docs/stack/search/reference/aggregations/)
#[must_use]
fn ft_aggregate<I, Q>(
self,
index: I,
query: Q,
options: FtAggregateOptions,
) -> PreparedCommand<'a, Self, FtAggregateResult>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
{
prepare_command(self, cmd("FT.AGGREGATE").arg(index).arg(query).arg(options))
}
/// Add an alias to an index
///
/// # Arguments
/// * `index` - The index.
/// * `alias` - alias to be added to an index
///
/// # See Also
/// [<https://redis.io/commands/ft.aliasadd/>](https://redis.io/commands/ft.aliasadd/)
#[must_use]
fn ft_aliasadd<A, I>(self, alias: A, index: I) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
A: SingleArg,
I: SingleArg,
{
prepare_command(self, cmd("FT.ALIASADD").arg(alias).arg(index))
}
/// Remove an alias from an index
///
/// # Arguments
/// * `alias` - alias to be removed
///
/// # See Also
/// [<https://redis.io/commands/ft.aliasdel/>](https://redis.io/commands/ft.aliasdel/)
#[must_use]
fn ft_aliasdel<A>(self, alias: A) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
A: SingleArg,
{
prepare_command(self, cmd("FT.ALIASDEL").arg(alias))
}
/// Add an alias to an index.
///
/// If the alias is already associated with another index,
/// this command removes the alias association with the previous index.
///
/// # Arguments
/// * `index` - The index.
/// * `alias` - alias to be added to an index
///
/// # See Also
/// [<https://redis.io/commands/ft.aliasupdate/>](https://redis.io/commands/ft.aliasupdate/)
#[must_use]
fn ft_aliasupdate<A, I>(self, alias: A, index: I) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
A: SingleArg,
I: SingleArg,
{
prepare_command(self, cmd("FT.ALIASUPDATE").arg(alias).arg(index))
}
/// Add a new attribute to the index.
///
/// Adding an attribute to the index causes any future document updates
/// to use the new attribute when indexing and reindexing existing documents.
///
/// # Arguments
/// * `index` - index name to create.
/// * `skip_initial_scan` - if set, does not scan and index.
/// * `attribute` - attribute to add.
///
/// # See Also
/// [<https://redis.io/commands/ft.alter/>](https://redis.io/commands/ft.alter/)
#[must_use]
fn ft_alter<I>(
self,
index: I,
skip_initial_scan: bool,
attribute: FtFieldSchema,
) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
I: SingleArg,
{
prepare_command(
self,
cmd("FT.ALTER")
.arg(index)
.arg_if(skip_initial_scan, "SKIPINITIALSCAN")
.arg("SCHEMA")
.arg("ADD")
.arg(attribute),
)
}
/// Retrieve configuration options
///
/// # Arguments
/// * `option` - name of the configuration option, or '*' for all.
///
/// # Return
/// Key/value collection holding names & values of the requested configs
///
/// # See Also
/// [<https://redis.io/commands/ft.config-get/>](https://redis.io/commands/ft.config-get/)
#[must_use]
fn ft_config_get<O, N, V, R>(self, option: O) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
O: SingleArg,
N: PrimitiveResponse,
V: PrimitiveResponse,
R: KeyValueCollectionResponse<N, V>,
{
prepare_command(self, cmd("FT.CONFIG").arg("GET").arg(option))
}
/// Set configuration options
///
/// # Arguments
/// * `option` - name of the configuration option
/// * `value` - value of the configuration option.
///
/// # See Also
/// [<https://redis.io/commands/ft.config-set/>](https://redis.io/commands/ft.config-set/)
#[must_use]
fn ft_config_set<O, V>(self, option: O, value: V) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
O: SingleArg,
V: SingleArg,
{
prepare_command(self, cmd("FT.CONFIG").arg("SET").arg(option).arg(value))
}
/// Create an index with the given specification
///
/// # Arguments
/// * `index` - Name of the index to create. If it exists, the old specification is overwritten.
///
/// # See Also
/// * [<https://redis.io/commands/ft.create/>](https://redis.io/commands/ft.create/)
/// * [`Aggregations`](https://redis.io/docs/stack/search/reference/aggregations/)
#[must_use]
fn ft_create<I, S>(
self,
index: I,
options: FtCreateOptions,
schema: S,
) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
I: SingleArg,
S: MultipleArgsCollection<FtFieldSchema>,
{
prepare_command(
self,
cmd("FT.CREATE")
.arg(index)
.arg(options)
.arg("SCHEMA")
.arg(schema),
)
}
/// Delete a cursor
///
/// # Arguments
/// * `index` - index name.
/// * `cursor_id` - id of the cursor
///
/// # See Also
/// [<https://redis.io/commands/ft.cursor-del/>](https://redis.io/commands/ft.cursor-del/)
#[must_use]
fn ft_cursor_del<I>(self, index: I, cursor_id: u64) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
I: SingleArg,
{
prepare_command(self, cmd("FT.CURSOR").arg("DEL").arg(index).arg(cursor_id))
}
/// Read next results from an existing cursor
///
/// # Arguments
/// * `index` - index name.
/// * `cursor_id` - id of the cursor.
/// * `read_size` - number of results to read. This parameter overrides
/// [`count`](FtWithCursorOptions::count) specified in [`ft_aggregate`](SearchCommands::ft_aggregate).
///
/// # Returns
/// an instance of [`FtAggregateResult`](FtAggregateResult)
///
/// # See Also
/// [<https://redis.io/commands/ft.cursor-read/>](https://redis.io/commands/ft.cursor-read/)
#[must_use]
fn ft_cursor_read<I>(
self,
index: I,
cursor_id: u64,
) -> PreparedCommand<'a, Self, FtAggregateResult>
where
Self: Sized,
I: SingleArg,
{
prepare_command(self, cmd("FT.CURSOR").arg("READ").arg(index).arg(cursor_id))
}
/// Add terms to a dictionary
///
/// # Arguments
/// * `dict` - dictionary name.
/// * `terms` - terms to add to the dictionary.
///
/// # Return
/// the number of new terms that were added.
///
/// # See Also
/// [<https://redis.io/commands/ft.dictadd/>](https://redis.io/commands/ft.dictadd/)
#[must_use]
fn ft_dictadd<D, T, TT>(self, dict: D, terms: TT) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
D: SingleArg,
T: SingleArg,
TT: SingleArgCollection<T>,
{
prepare_command(self, cmd("FT.DICTADD").arg(dict).arg(terms))
}
/// Delete terms from a dictionary
///
/// # Arguments
/// * `dict` - dictionary name.
/// * `terms` - terms to delete from the dictionary.
///
/// # Return
/// the number of terms that were deleted.
///
/// # See Also
/// [<https://redis.io/commands/ft.dictdel/>](https://redis.io/commands/ft.dictdel/)
#[must_use]
fn ft_dictdel<D, T, TT>(self, dict: D, terms: TT) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
D: SingleArg,
T: SingleArg,
TT: SingleArgCollection<T>,
{
prepare_command(self, cmd("FT.DICTDEL").arg(dict).arg(terms))
}
/// Dump all terms in the given dictionary
///
/// # Arguments
/// * `dict` - dictionary name.
///
/// # Return
/// A collection, where each element is a term (bulkstring).
///
/// # See Also
/// [<https://redis.io/commands/ft.dictdump/>](https://redis.io/commands/ft.dictdump/)
#[must_use]
fn ft_dictdump<D, T, TT>(self, dict: D) -> PreparedCommand<'a, Self, TT>
where
Self: Sized,
D: SingleArg,
T: PrimitiveResponse + DeserializeOwned,
TT: CollectionResponse<T>,
{
prepare_command(self, cmd("FT.DICTDUMP").arg(dict))
}
/// Delete an index
///
/// # Arguments
/// * `index` - full-text index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `dd` - drop operation that, if set, deletes the actual document hashes
///
/// # Notes
/// * By default, `ft_dropindex` does not delete the document hashes associated with the index.
/// Adding the `dd` option deletes the hashes as well.
/// * When using `ft_dropindex` with the parameter `dd`, if an index creation is still running
/// ([`ft_create`](SearchCommands::ft_create) is running asynchronously),
/// only the document hashes that have already been indexed are deleted.
/// The document hashes left to be indexed remain in the database.
/// You can use [`ft_info`](SearchCommands::ft_info) to check the completion of the indexing.
///
/// # Return
/// the number of new terms that were added.
///
/// # See Also
/// [<https://redis.io/commands/ft.dropindex/>](https://redis.io/commands/ft.dropindex/)
#[must_use]
fn ft_dropindex<I>(self, index: I, dd: bool) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
I: SingleArg,
{
prepare_command(self, cmd("FT.DROPINDEX").arg(index).arg_if(dd, "DD"))
}
/// Return the execution plan for a complex query
///
/// # Arguments
/// * `index` - full-text index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `query` - query string, as if sent to [`ft_search`](SearchCommands::ft_search).
/// * `dialect_version` - dialect version under which to execute the query. \
/// If not specified, the query executes under the default dialect version set during module initial loading\
/// or via [`ft_config_set`](SearchCommands::ft_config_set) command.
///
/// # Notes
/// * In the returned response, a `+` on a term is an indication of stemming.
/// * `redis-cli --raw` to properly read line-breaks in the returned response.
///
/// # Return
/// a string representing the execution plan.
///
/// # See Also
/// [<https://redis.io/commands/ft.explain/>](https://redis.io/commands/ft.explain/)
#[must_use]
fn ft_explain<I, Q, R>(
self,
index: I,
query: Q,
dialect_version: Option<u64>,
) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
R: PrimitiveResponse,
{
prepare_command(
self,
cmd("FT.EXPLAIN").arg(index).arg(query).arg(dialect_version),
)
}
/// Return the execution plan for a complex query but formatted for easier reading without using `redis-cli --raw`
///
/// # Arguments
/// * `index` - full-text index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `query` - query string, as if sent to [`ft_search`](SearchCommands::ft_search).
/// * `dialect_version` - dialect version under which to execute the query. \
/// If not specified, the query executes under the default dialect version set during module initial loading\
/// or via [`ft_config_set`](SearchCommands::ft_config_set) command.
///
/// # Notes
/// * In the returned response, a `+` on a term is an indication of stemming.
///
/// # Return
/// a collection of strings representing the execution plan.
///
/// # See Also
/// [<https://redis.io/commands/ft.explaincli/>](https://redis.io/commands/ft.explaincli/)
#[must_use]
fn ft_explaincli<I, Q, R, RR>(
self,
index: I,
query: Q,
dialect_version: Option<u64>,
) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
R: PrimitiveResponse + DeserializeOwned,
RR: CollectionResponse<R>,
{
prepare_command(
self,
cmd("FT.EXPLAINCLI")
.arg(index)
.arg(query)
.arg(dialect_version),
)
}
/// Return information and statistics on the index
///
/// # Arguments
/// * `index` - full-text index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
///
/// # Return
/// an instance of [`FtInfoResult`](FtInfoResult)
///
/// # See Also
/// [<https://redis.io/commands/ft.info/>](https://redis.io/commands/ft.info/)
#[must_use]
fn ft_info(self, index: impl SingleArg) -> PreparedCommand<'a, Self, FtInfoResult>
where
Self: Sized,
{
prepare_command(self, cmd("FT.INFO").arg(index))
}
/// Returns a list of all existing indexes.
///
/// # Return
/// A collection of index names.
///
/// # See Also
/// [<https://redis.io/commands/ft._list/>](https://redis.io/commands/ft._list/)
#[must_use]
fn ft_list<R, RR>(self) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
R: PrimitiveResponse + DeserializeOwned,
RR: CollectionResponse<R>,
{
prepare_command(self, cmd("FT._LIST"))
}
/// Perform a [`ft_search`](SearchCommands::ft_search) command and collects performance information
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `limited` - if set, removes details of reader iterator.
/// * `query` - collection of query parameters (non including the index name)
///
/// # Note
/// To reduce the size of the output, use [`nocontent`](FtSearchOptions::nocontent) or [`limit(0,0)`](FtSearchOptions::limit) to reduce results reply
/// or `LIMITED` to not reply with details of `reader iterators` inside builtin-unions such as `fuzzy` or `prefix`.
///
/// # Return
/// An instance of [`FtProfileSearchResult`](FtProfileSearchResult)
///
/// # See Also
/// [<https://redis.io/commands/ft.profile/>](https://redis.io/commands/ft.profile/)
#[must_use]
fn ft_profile_search<I, Q, QQ>(
self,
index: I,
limited: bool,
query: QQ,
) -> PreparedCommand<'a, Self, FtProfileSearchResult>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
QQ: SingleArgCollection<Q>,
{
prepare_command(
self,
cmd("FT.PROFILE")
.arg(index)
.arg("SEARCH")
.arg_if(limited, "LIMITED")
.arg("QUERY")
.arg(query),
)
}
/// Perform a [`ft_aggregate`](SearchCommands::ft_aggregate) command and collects performance information
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `limited` - if set, removes details of reader iterator.
/// * `query` - collection of query parameters (non including the index name)
///
/// # Note
/// To reduce the size of the output, use [`nocontent`](FtSearchOptions::nocontent) or [`limit(0,0)`](FtSearchOptions::limit) to reduce results reply
/// or `LIMITED` to not reply with details of `reader iterators` inside builtin-unions such as `fuzzy` or `prefix`.
///
/// # Return
/// An instance of [`FtProfileAggregateResult`](FtProfileAggregateResult)
///
/// # See Also
/// [<https://redis.io/commands/ft.profile/>](https://redis.io/commands/ft.profile/)
#[must_use]
fn ft_profile_aggregate<I, Q, QQ>(
self,
index: I,
limited: bool,
query: QQ,
) -> PreparedCommand<'a, Self, FtProfileAggregateResult>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
QQ: SingleArgCollection<Q>,
{
prepare_command(
self,
cmd("FT.PROFILE")
.arg(index)
.arg("AGGREGATE")
.arg_if(limited, "LIMITED")
.arg("QUERY")
.arg(query),
)
}
/// Search the index with a textual query, returning either documents or just ids
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `query` - text query to search. Refer to [`Query syntax`](https://redis.io/docs/stack/search/reference/query_syntax) for more details.
/// * `options` - See [`FtSearchOptions`](FtSearchOptions)
///
/// # Return
/// An instance of [`FtSearchResult`](FtSearchResult)
///
/// # See Also
/// [<https://redis.io/commands/ft.search/>](https://redis.io/commands/ft.search/)
#[must_use]
fn ft_search<I, Q>(
self,
index: I,
query: Q,
options: FtSearchOptions,
) -> PreparedCommand<'a, Self, FtSearchResult>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
{
prepare_command(self, cmd("FT.SEARCH").arg(index).arg(query).arg(options))
}
/// Perform spelling correction on a query, returning suggestions for misspelled terms
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `query` - search query. See [`Spellchecking`](https://redis.io/docs/stack/search/reference/spellcheck) for more details.
/// * `options` - See [`FtSpellCheckOptions`](FtSpellCheckOptions)
///
/// # Return
/// An instance of [`FtSpellCheckResult`](FtSpellCheckResult)
///
/// # See Also
/// [<https://redis.io/commands/ft.spellcheck/>](https://redis.io/commands/ft.spellcheck/)
#[must_use]
fn ft_spellcheck<I, Q>(
self,
index: I,
query: Q,
options: FtSpellCheckOptions,
) -> PreparedCommand<'a, Self, FtSpellCheckResult>
where
Self: Sized,
I: SingleArg,
Q: SingleArg,
{
prepare_command(
self,
cmd("FT.SPELLCHECK").arg(index).arg(query).arg(options),
)
}
/// Dump the contents of a synonym group
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
///
/// # Return
/// This command returns a list of synonym terms and their synonym group ids.
///
/// # See Also
/// * [<https://redis.io/commands/ft.syndump/>](https://redis.io/commands/ft.syndump/)
/// * [`Synonym support`](https://redis.io/docs/stack/search/reference/synonyms/)
#[must_use]
fn ft_syndump<I, R>(self, index: I) -> PreparedCommand<'a, Self, R>
where
Self: Sized,
I: SingleArg,
R: KeyValueCollectionResponse<String, Vec<String>>,
{
prepare_command(self, cmd("FT.SYNDUMP").arg(index))
}
/// Update a synonym group
///
/// Use this command to create or update a synonym group with additional terms.
/// The command triggers a scan of all documents. ///
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `synonym_group_id` - synonym group to return.
/// * `skip_initial_scan` - does not scan and index, and only documents that are indexed after the update are affected.
/// * `terms` - terms to add to the synonym group
///
/// # Return
/// This command returns a list of synonym terms and their synonym group ids.
///
/// # See Also
/// * [<https://redis.io/commands/ft.synupdate/>](https://redis.io/commands/ft.synupdate/)
/// * [`Synonym support`](https://redis.io/docs/stack/search/reference/synonyms/)
#[must_use]
fn ft_synupdate<T: SingleArg>(
self,
index: impl SingleArg,
synonym_group_id: impl SingleArg,
skip_initial_scan: bool,
terms: impl SingleArgCollection<T>,
) -> PreparedCommand<'a, Self, ()>
where
Self: Sized,
{
prepare_command(
self,
cmd("FT.SYNUPDATE")
.arg(index)
.arg(synonym_group_id)
.arg_if(skip_initial_scan, "SKIPINITIALSCAN")
.arg(terms),
)
}
/// Return a distinct set of values indexed in a Tag field
///
/// Use this command if your tag indexes things like cities, categories, and so on.
///
/// # Arguments
/// * `index` - index name. You must first create the index using [`ft_create`](SearchCommands::ft_create).
/// * `field_name` - name of a Tag file defined in the schema.
///
/// # Return
/// A coolection reply of all distinct tags in the tag index.
///
/// # See Also
/// [<https://redis.io/commands/ft.tagvals/>](https://redis.io/commands/ft.tagvals/)
#[must_use]
fn ft_tagvals<R: PrimitiveResponse + DeserializeOwned, RR: CollectionResponse<R>>(
self,
index: impl SingleArg,
field_name: impl SingleArg,
) -> PreparedCommand<'a, Self, RR>
where
Self: Sized,
{
prepare_command(self, cmd("FT.TAGVALS").arg(index).arg(field_name))
}
/// Add a suggestion string to an auto-complete suggestion dictionary
///
/// The auto-complete suggestion dictionary is disconnected from the index definitions
/// and leaves creating and updating suggestions dictionaries to the user.
///
/// # Arguments
/// * `key` - suggestion dictionary key.
/// * `string` - suggestion string to index.
/// * `score` - floating point number of the suggestion string's weight.
/// * `options` - See [`FtSugAddOptions`](FtSugAddOptions)
///
/// # Return
/// the current size of the suggestion dictionary.
///
/// # See Also
/// [<https://redis.io/commands/ft.sugadd/>](https://redis.io/commands/ft.sugadd/)
#[must_use]
fn ft_sugadd(
self,
key: impl SingleArg,
string: impl SingleArg,
score: f64,
options: FtSugAddOptions,
) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
{
prepare_command(
self,
cmd("FT.SUGADD")
.arg(key)
.arg(string)
.arg(score)
.arg(options),
)
}
/// Delete a string from a suggestion index
///
/// # Arguments
/// * `key` - suggestion dictionary key.
/// * `string` - suggestion string to delete
///
/// # Return
/// * `true` - if the string was found and deleted
/// * `false` - otherwise
/// # See Also
/// [<https://redis.io/commands/ft.sugdel/>](https://redis.io/commands/ft.sugdel/)
#[must_use]
fn ft_sugdel(
self,
key: impl SingleArg,
string: impl SingleArg,
) -> PreparedCommand<'a, Self, bool>
where
Self: Sized,
{
prepare_command(self, cmd("FT.SUGDEL").arg(key).arg(string))
}
/// Get completion suggestions for a prefix
///
/// # Arguments
/// * `key` - suggestion dictionary key.
/// * `prefix` - prefix to complete on.
/// * `options` - See [`FtSugGetOptions`](FtSugGetOptions)
///
/// # Return
/// A collection of the top suggestions matching the prefix
///
/// # See Also
/// [<https://redis.io/commands/ft.sugget/>](https://redis.io/commands/ft.sugget/)
#[must_use]
fn ft_sugget(
self,
key: impl SingleArg,
prefix: impl SingleArg,
options: FtSugGetOptions,
) -> PreparedCommand<'a, Self, Vec<FtSuggestion>>
where
Self: Sized,
{
prepare_command(self, cmd("FT.SUGGET").arg(key).arg(prefix).arg(options)).custom_converter(
Box::new(|resp_buffer, command, _client| {
let mut deserializer = RespDeserializer::new(&resp_buffer);
Box::pin(future::ready(FtSuggestion::deserialize(
&mut deserializer,
command,
)))
}),
)
}
/// Get the size of an auto-complete suggestion dictionary
///
/// # Arguments
/// * `key` - suggestion dictionary key.
///
/// # Return
/// The the current size of the suggestion dictionary.
///
/// # See Also
/// [<https://redis.io/commands/ft.suglen/>](https://redis.io/commands/ft.suglen/)
#[must_use]
fn ft_suglen(self, key: impl SingleArg) -> PreparedCommand<'a, Self, usize>
where
Self: Sized,
{
prepare_command(self, cmd("FT.SUGLEN").arg(key))
}
}
#[derive(Debug, Copy, Clone)]
pub enum FtVectorType {
Float64,
Float32,
}
impl ToArgs for FtVectorType {
fn write_args(&self, args: &mut CommandArgs) {
args.arg(match self {
FtVectorType::Float32 => "FLOAT32",
FtVectorType::Float64 => "FLOAT64",
});
}
}
#[derive(Debug, Copy, Clone)]
pub enum FtVectorDistanceMetric {
L2,
IP,
Cosine,
}
impl ToArgs for FtVectorDistanceMetric {
fn write_args(&self, args: &mut CommandArgs) {
args.arg(match self {
FtVectorDistanceMetric::L2 => "L2",
FtVectorDistanceMetric::IP => "IP",
FtVectorDistanceMetric::Cosine => "COSINE",
});
}
}
#[derive(Debug, Copy, Clone)]
pub struct FtFlatVectorFieldAttributes {
pub ty: FtVectorType,
pub dim: usize,
pub distance_metric: FtVectorDistanceMetric,
pub initial_cap: Option<usize>,
pub block_size: Option<usize>,
}
impl FtFlatVectorFieldAttributes {
pub fn new(ty: FtVectorType, dim: usize, distance_metric: FtVectorDistanceMetric) -> Self {
Self {
ty,
dim,
distance_metric,
initial_cap: None,
block_size: None,
}
}
pub fn initial_cap(self, initial_cap: usize) -> Self {
Self {
initial_cap: Some(initial_cap),
..self
}
}
pub fn block_size(self, block_size: usize) -> Self {
Self {
block_size: Some(block_size),
..self
}
}
}
impl ToArgs for FtFlatVectorFieldAttributes {
fn write_args(&self, args: &mut CommandArgs) {
args.arg("TYPE")
.arg(self.ty)
.arg("DIM")
.arg(self.dim)
.arg("DISTANCE_METRIC")
.arg(self.distance_metric);
if let Some(initial_cap) = self.initial_cap {
args.arg("INITIAL_CAP").arg(initial_cap);
}
if let Some(block_size) = self.block_size {
args.arg("BLOCK_SIZE").arg(block_size);
}
}
fn num_args(&self) -> usize {
let mut num = 6;
if self.initial_cap.is_some() {
num += 2
}
if self.block_size.is_some() {
num += 2
}
num
}
}
#[derive(Debug, Copy, Clone)]
pub struct FtHnswVectorFieldAttributes {
pub ty: FtVectorType,
pub dim: usize,
pub distance_metric: FtVectorDistanceMetric,
pub initial_cap: Option<usize>,
pub m: Option<usize>,
pub ef_construction: Option<usize>,
pub ef_runtime: Option<usize>,
pub epsilon: Option<f64>,
}
impl FtHnswVectorFieldAttributes {
pub fn new(ty: FtVectorType, dim: usize, distance_metric: FtVectorDistanceMetric) -> Self {
Self {
ty,
dim,
distance_metric,
initial_cap: None,
m: None,
ef_construction: None,
ef_runtime: None,
epsilon: None,
}
}
pub fn initial_cap(self, initial_cap: usize) -> Self {
Self {
initial_cap: Some(initial_cap),
..self
}
}
pub fn m(self, m: usize) -> Self {
Self { m: Some(m), ..self }
}
pub fn ef_construction(self, ef_construction: usize) -> Self {
Self {
ef_construction: Some(ef_construction),
..self
}
}
pub fn ef_runtime(self, ef_runtime: usize) -> Self {
Self {
ef_runtime: Some(ef_runtime),
..self
}
}
pub fn epsilon(self, epsilon: f64) -> Self {
Self {
epsilon: Some(epsilon),
..self
}
}
}
impl ToArgs for FtHnswVectorFieldAttributes {
fn write_args(&self, args: &mut CommandArgs) {
args.arg("TYPE")
.arg(self.ty)
.arg("DIM")
.arg(self.dim)
.arg("DISTANCE_METRIC")
.arg(self.distance_metric);
if let Some(initial_cap) = self.initial_cap {
args.arg("INITIAL_CAP").arg(initial_cap);
}
if let Some(m) = self.m {
args.arg("M").arg(m);
}
if let Some(ef_construction) = self.ef_construction {
args.arg("EF_CONSTRUCTION").arg(ef_construction);
}
if let Some(ef_runtime) = self.ef_runtime {
args.arg("EF_RUNTIME").arg(ef_runtime);
}
if let Some(epsilon) = self.epsilon {
args.arg("EPSILON").arg(epsilon);
}
}
fn num_args(&self) -> usize {
let mut num = 6;
if self.initial_cap.is_some() {
num += 2
}
if self.m.is_some() {
num += 2
}
if self.ef_construction.is_some() {
num += 2
}
if self.ef_runtime.is_some() {
num += 2
}
if self.epsilon.is_some() {
num += 2