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
//! Provides a type-safe way to generate [FT.CREATE](https://redis.io/docs/latest/commands/ft.create/) commands programmatically.
//!
//! The pieces fit together as follows:
//!
//! ```text
//! SchemaTextField (and the other field builders)
//! │ into()
//! ▼
//! FieldDefinition
//! │ inserted by the schema! macro or by insert()
//! ▼
//! SearchSchema (always holds at least one field)
//! │
//! │ every type along the way implements ToRedisArgs
//! ▼
//! FtCreateCommand
//! │
//! └── into_cmd() yields a redis::Cmd
//! ```
//!
//! # Examples
//!
//! ```rust
//! use redis::{schema, search::*};
//!
//! // Build a schema using the schema! macro
//! let schema = schema! {
//! "title" => SchemaTextField::new().weight(2.0),
//! "price" => SchemaNumericField::new(),
//! "condition" => SchemaTagField::new().separator(',')
//! };
//!
//! // Create an FT.CREATE command
//! let ft_create = FtCreateCommand::new("index", schema)
//! .options(
//! CreateOptions::new()
//! .on(IndexDataType::Hash)
//! .prefix("doc:")
//! );
//! ```
//!
//! Index blog post hashes whose keys start with `blog:post:`, with sortable
//! fields:
//!
//! ```rust
//! use redis::{schema, search::*};
//!
//! let ft_create = FtCreateCommand::new(
//! "idx",
//! schema! {
//! "title" => SchemaTextField::new().sortable(Sortable::Yes),
//! "published_at" => SchemaNumericField::new().sortable(Sortable::Yes),
//! "category" => SchemaTagField::new().sortable(Sortable::Yes),
//! },
//! )
//! .options(
//! CreateOptions::new()
//! .on(IndexDataType::Hash)
//! .prefix("blog:post:")
//! );
//! ```
//!
//! Index a JSON document: select the attributes with JSONPath expressions and
//! give them plain names with aliases:
//!
//! ```rust
//! use redis::{schema, search::*};
//!
//! let ft_create = FtCreateCommand::new(
//! "idx",
//! schema! {
//! "$.title" => SchemaTextField::new().alias("title"),
//! "$.categories" => SchemaTagField::new().alias("categories"),
//! },
//! )
//! .options(CreateOptions::new().on(IndexDataType::Json));
//! ```
pub use *;
pub use *;
pub use *;
use crateCmd;
/// FT.CREATE command builder.
///
/// The schema is required by `FT.CREATE`, so [`FtCreateCommand::new`] takes it
/// as a mandatory argument rather than exposing it through a builder method.
/// Together with [`SearchSchema`] requiring at least one field, this makes the
/// server's requirements compile-time guarantees: the schema is always present
/// and never empty.
///
/// # Example
/// ```rust
/// use redis::{schema, search::*};
///
/// let cmd = FtCreateCommand::new("my_index", schema! { "title" => SchemaTextField::new() })
/// .options(CreateOptions::new().on(IndexDataType::Hash))
/// .into_cmd();
/// ```