@@ -114,7 +114,7 @@ fn get_index() {
114
114
default_collection
115
115
. create_index(
116
116
"new_index1" ,
117
- & ValueIndexConfiguration :: new( QueryLanguage :: JSON , r#"[[".someField"]]"# , "" ) ,
117
+ & ValueIndexConfiguration :: new( QueryLanguage :: JSON , r#"[[".someField"]]"# , None ) ,
118
118
)
119
119
. unwrap( )
120
120
) ;
@@ -135,7 +135,11 @@ fn get_index() {
135
135
new_coll
136
136
. create_index(
137
137
"new_index2" ,
138
- & ValueIndexConfiguration :: new( QueryLanguage :: JSON , r#"[[".someField2"]]"# , "" ) ,
138
+ & ValueIndexConfiguration :: new(
139
+ QueryLanguage :: JSON ,
140
+ r#"[[".someField2"]]"# ,
141
+ None
142
+ ) ,
139
143
)
140
144
. unwrap( )
141
145
) ;
@@ -159,7 +163,7 @@ fn full_index() {
159
163
assert ! (
160
164
db. create_index(
161
165
"new_index" ,
162
- & ValueIndexConfiguration :: new( QueryLanguage :: JSON , r#"[[".someField"]]"# , "" ) ,
166
+ & ValueIndexConfiguration :: new( QueryLanguage :: JSON , r#"[[".someField"]]"# , None ) ,
163
167
)
164
168
. unwrap( )
165
169
) ;
@@ -215,7 +219,55 @@ fn partial_index() {
215
219
& ValueIndexConfiguration :: new(
216
220
QueryLanguage :: JSON ,
217
221
r#"{"WHAT": [[".id"]], "WHERE": ["=", [".someField"], "someValue"]}"# ,
218
- ""
222
+ None
223
+ ) ,
224
+ )
225
+ . unwrap( )
226
+ ) ;
227
+
228
+ // Check index creation
229
+ let value = db. get_index_names ( ) . iter ( ) . next ( ) . unwrap ( ) ;
230
+ let name = value. as_string ( ) . unwrap ( ) ;
231
+ assert_eq ! ( name, "new_index" ) ;
232
+
233
+ // Check index used
234
+ let query = Query :: new (
235
+ db,
236
+ QueryLanguage :: N1QL ,
237
+ "select _.* from _ where _.id = 'id' and _.someField='someValue'" ,
238
+ )
239
+ . expect ( "create query" ) ;
240
+
241
+ let index = get_index_name_from_explain ( & query. explain ( ) . unwrap ( ) ) . unwrap ( ) ;
242
+ assert_eq ! ( index, "new_index" ) ;
243
+
244
+ // Check index not used
245
+ let query = Query :: new (
246
+ db,
247
+ QueryLanguage :: N1QL ,
248
+ "select _.* from _ where _.id = 'id' and _.someField='notSomeValue'" ,
249
+ )
250
+ . expect ( "create query" ) ;
251
+
252
+ let index = Regex :: new ( r"USING INDEX (\w+) " )
253
+ . unwrap ( )
254
+ . captures ( & query. explain ( ) . unwrap ( ) )
255
+ . map ( |c| c. get ( 1 ) . unwrap ( ) . as_str ( ) . to_string ( ) ) ;
256
+
257
+ assert ! ( index. is_none( ) ) ;
258
+ } ) ;
259
+ }
260
+
261
+ #[ test]
262
+ fn partial_index_with_condition_field ( ) {
263
+ utils:: with_db ( |db| {
264
+ assert ! (
265
+ db. create_index(
266
+ "new_index" ,
267
+ & ValueIndexConfiguration :: new(
268
+ QueryLanguage :: JSON ,
269
+ r#"[[".id"]]"# ,
270
+ Some ( r#"["=", [".someField"], "someValue"]"# )
219
271
) ,
220
272
)
221
273
. unwrap( )
0 commit comments