@@ -284,9 +284,10 @@ fn array_index() {
284
284
// Index with one level of unnest
285
285
let index_configuration = ArrayIndexConfiguration :: new ( QueryLanguage :: N1QL , "likes" , "" ) ;
286
286
287
- assert ! ( default_collection
288
- . create_array_index( "one_level" , & index_configuration, )
289
- . unwrap( ) ) ;
287
+ let result = default_collection
288
+ . create_array_index ( "one_level" , & index_configuration)
289
+ . unwrap ( ) ;
290
+ assert ! ( result) ;
290
291
291
292
let query = Query :: new (
292
293
db,
@@ -305,18 +306,12 @@ fn array_index() {
305
306
assert ! ( result. next( ) . is_none( ) ) ;
306
307
307
308
// Index with two levels of unnest
308
- /*let index_configuration = ArrayIndexConfiguration::new(
309
- QueryLanguage::N1QL,
310
- "contacts[].phones",
311
- "",//"type",
312
- );
309
+ let index_configuration =
310
+ ArrayIndexConfiguration :: new ( QueryLanguage :: N1QL , "contacts[].phones" , "type" ) ;
313
311
314
312
assert ! ( default_collection
315
- .create_array_index(
316
- "myindex",
317
- &index_configuration,
318
- ).unwrap()
319
- );
313
+ . create_array_index( "two_levels" , & index_configuration, )
314
+ . unwrap( ) ) ;
320
315
321
316
let query = Query :: new (
322
317
db,
@@ -325,18 +320,29 @@ fn array_index() {
325
320
FROM _
326
321
UNNEST _.contacts as contact
327
322
UNNEST contact.phones as phone
328
- WHERE phone.type = 'mobile'"#
329
- ).unwrap();
323
+ WHERE phone.type = 'mobile'"# ,
324
+ )
325
+ . unwrap ( ) ;
330
326
331
327
println ! ( "Explain: {}" , query. explain( ) . unwrap( ) ) ;
332
328
333
329
let index = get_index_name_from_explain ( & query. explain ( ) . unwrap ( ) ) . unwrap ( ) ;
334
330
assert_eq ! ( index, "two_levels" ) ;
335
331
336
332
let mut result = query. execute ( ) . unwrap ( ) ;
333
+
337
334
let row = result. next ( ) . unwrap ( ) ;
338
- assert_eq!(row.as_array().to_json(), r#"["Sam","travel"]"#);
335
+ assert_eq ! (
336
+ row. as_array( ) . to_json( ) ,
337
+ r#"["Sam","primary","310-123-6789"]"#
338
+ ) ;
339
339
340
- assert!(result.next().is_none());*/
340
+ let row = result. next ( ) . unwrap ( ) ;
341
+ assert_eq ! (
342
+ row. as_array( ) . to_json( ) ,
343
+ r#"["Sam","secondary","206-123-6789"]"#
344
+ ) ;
345
+
346
+ assert ! ( result. next( ) . is_none( ) ) ;
341
347
} )
342
348
}
0 commit comments