@@ -234,6 +234,22 @@ impl FastFieldReaders {
234
234
Ok ( dynamic_column_handle_opt)
235
235
}
236
236
237
+ /// Returning all `dynamic_column_handle`.
238
+ pub fn dynamic_column_handles (
239
+ & self ,
240
+ field_name : & str ,
241
+ ) -> crate :: Result < Vec < DynamicColumnHandle > > {
242
+ let Some ( resolved_field_name) = self . resolve_field ( field_name) ? else {
243
+ return Ok ( Vec :: new ( ) ) ;
244
+ } ;
245
+ let dynamic_column_handles = self
246
+ . columnar
247
+ . read_columns ( & resolved_field_name) ?
248
+ . into_iter ( )
249
+ . collect ( ) ;
250
+ Ok ( dynamic_column_handles)
251
+ }
252
+
237
253
#[ doc( hidden) ]
238
254
pub async fn list_dynamic_column_handles (
239
255
& self ,
@@ -338,6 +354,8 @@ impl FastFieldReaders {
338
354
339
355
#[ cfg( test) ]
340
356
mod tests {
357
+ use columnar:: ColumnType ;
358
+
341
359
use crate :: schema:: { JsonObjectOptions , Schema , FAST } ;
342
360
use crate :: { Document , Index } ;
343
361
@@ -417,4 +435,45 @@ mod tests {
417
435
Some ( "_dyna\u{1} notinschema\u{1} attr\u{1} color" . to_string( ) )
418
436
) ;
419
437
}
438
+
439
+ #[ test]
440
+ fn test_fast_field_reader_dynamic_column_handles ( ) {
441
+ let mut schema_builder = Schema :: builder ( ) ;
442
+ let id = schema_builder. add_u64_field ( "id" , FAST ) ;
443
+ let json = schema_builder. add_json_field ( "json" , FAST ) ;
444
+ let schema = schema_builder. build ( ) ;
445
+ let index = Index :: create_in_ram ( schema) ;
446
+ let mut index_writer = index. writer_for_tests ( ) . unwrap ( ) ;
447
+ index_writer
448
+ . add_document ( doc ! ( id=> 1u64 , json => json!( { "foo" : 42 } ) ) )
449
+ . unwrap ( ) ;
450
+ index_writer
451
+ . add_document ( doc ! ( id=> 2u64 , json => json!( { "foo" : true } ) ) )
452
+ . unwrap ( ) ;
453
+ index_writer
454
+ . add_document ( doc ! ( id=> 3u64 , json => json!( { "foo" : "bar" } ) ) )
455
+ . unwrap ( ) ;
456
+ index_writer. commit ( ) . unwrap ( ) ;
457
+ let reader = index. reader ( ) . unwrap ( ) ;
458
+ let searcher = reader. searcher ( ) ;
459
+ let reader = searcher. segment_reader ( 0u32 ) ;
460
+ let fast_fields = reader. fast_fields ( ) ;
461
+ let id_columns = fast_fields. dynamic_column_handles ( "id" ) . unwrap ( ) ;
462
+ assert_eq ! ( id_columns. len( ) , 1 ) ;
463
+ assert_eq ! ( id_columns. first( ) . unwrap( ) . column_type( ) , ColumnType :: U64 ) ;
464
+
465
+ let foo_columns = fast_fields. dynamic_column_handles ( "json.foo" ) . unwrap ( ) ;
466
+ assert_eq ! ( foo_columns. len( ) , 3 ) ;
467
+ assert ! ( foo_columns
468
+ . iter( )
469
+ . any( |column| column. column_type( ) == ColumnType :: I64 ) ) ;
470
+ assert ! ( foo_columns
471
+ . iter( )
472
+ . any( |column| column. column_type( ) == ColumnType :: Bool ) ) ;
473
+ assert ! ( foo_columns
474
+ . iter( )
475
+ . any( |column| column. column_type( ) == ColumnType :: Str ) ) ;
476
+
477
+ println ! ( "*** {:?}" , fast_fields. columnar( ) . list_columns( ) ) ;
478
+ }
420
479
}
0 commit comments