@@ -12,44 +12,75 @@ pub struct CollectionSchemaBuilder {
1212 name : String ,
1313 fields : Vec < Field > ,
1414 default_sorting_field : Option < String > ,
15+ token_separators : Option < Vec < String > > ,
16+ enable_nested_fields : Option < bool > ,
17+ symbols_to_index : Option < Vec < String > > ,
1518}
1619
1720impl CollectionSchemaBuilder {
1821 /// Create a builder for [CollectionSchema]
19- pub fn new ( name : impl Into < String > ) -> Self {
22+ #[ inline]
23+ pub fn new ( name : impl Into < String > , fields : Vec < Field > ) -> Self {
2024 Self {
2125 name : name. into ( ) ,
26+ fields,
2227 ..Default :: default ( )
2328 }
2429 }
30+
2531 /// Insert field
32+ #[ inline]
2633 pub fn field ( mut self , field : Field ) -> Self {
2734 self . fields . push ( field) ;
2835 self
2936 }
3037
3138 /// Set fields
39+ #[ inline]
3240 pub fn fields ( mut self , fields : & [ Field ] ) -> Self {
3341 self . fields . extend_from_slice ( fields) ;
3442 self
3543 }
3644
37- /// Set default_sorting_field
38- pub fn default_sorting_field ( mut self , default_sorting_field : String ) -> Self {
39- self . default_sorting_field = Some ( default_sorting_field) ;
45+ /// Set default sorting field
46+ #[ inline]
47+ pub fn default_sorting_field ( mut self , default_sorting_field : impl Into < String > ) -> Self {
48+ self . default_sorting_field = Some ( default_sorting_field. into ( ) ) ;
49+ self
50+ }
51+
52+ /// Set token separators
53+ #[ inline]
54+ pub fn token_separators ( mut self , token_separators : Vec < String > ) -> Self {
55+ self . token_separators = Some ( token_separators) ;
56+ self
57+ }
58+
59+ /// Enable nested fields
60+ #[ inline]
61+ pub fn enable_nested_fields ( mut self , enable_nested_fields : Option < bool > ) -> Self {
62+ self . enable_nested_fields = enable_nested_fields;
63+ self
64+ }
65+
66+ /// Set symbols to index
67+ #[ inline]
68+ pub fn symbols_to_index ( mut self , symbols_to_index : Vec < String > ) -> Self {
69+ self . symbols_to_index = Some ( symbols_to_index) ;
4070 self
4171 }
4272
4373 /// Create a `CollectionSchema` with the current values of the builder,
4474 /// It can fail if any of the required fields is not not defined.
75+ #[ inline]
4576 pub fn build ( self ) -> CollectionSchema {
4677 CollectionSchema {
4778 name : self . name ,
4879 fields : self . fields ,
4980 default_sorting_field : self . default_sorting_field ,
50- token_separators : None ,
51- enable_nested_fields : None ,
52- symbols_to_index : None ,
81+ token_separators : self . token_separators ,
82+ enable_nested_fields : self . enable_nested_fields ,
83+ symbols_to_index : self . symbols_to_index ,
5384 }
5485 }
5586}
@@ -63,17 +94,17 @@ mod test {
6394 #[ test]
6495 fn collection_schema_serializes_as_expected ( ) {
6596 let fields = [
66- ( "company_name" . to_owned ( ) , "string" . to_owned ( ) , None ) ,
67- ( "num_employees" . to_owned ( ) , "int32" . to_owned ( ) , None ) ,
68- ( "country" . to_owned ( ) , "string" . to_owned ( ) , Some ( true ) ) ,
97+ ( "company_name" , "string" . to_owned ( ) , None ) ,
98+ ( "num_employees" , "int32" . to_owned ( ) , None ) ,
99+ ( "country" , "string" . to_owned ( ) , Some ( true ) ) ,
69100 ]
70101 . map ( |( name, typesense_type, facet) | {
71102 FieldBuilder :: new ( name, typesense_type) . facet ( facet) . build ( )
72- } ) ;
103+ } )
104+ . to_vec ( ) ;
73105
74- let collection = CollectionSchemaBuilder :: new ( "companies" . to_owned ( ) )
106+ let collection = CollectionSchemaBuilder :: new ( "companies" , fields )
75107 . default_sorting_field ( "num_employees" . to_owned ( ) )
76- . fields ( & fields)
77108 . build ( ) ;
78109
79110 let expected = json ! (
0 commit comments