@@ -18,7 +18,8 @@ use tantivy::aggregation::Key as TantivyKey;
1818use tantivy:: aggregation:: agg_result:: {
1919 AggregationResult as TantivyAggregationResult , AggregationResults as TantivyAggregationResults ,
2020 BucketEntries as TantivyBucketEntries , BucketEntry as TantivyBucketEntry ,
21- BucketResult as TantivyBucketResult , MetricResult as TantivyMetricResult ,
21+ BucketResult as TantivyBucketResult , CompositeBucketEntry as TantivyCompositeBucketEntry ,
22+ CompositeKey as TantivyCompositeKey , MetricResult as TantivyMetricResult ,
2223 RangeBucketEntry as TantivyRangeBucketEntry ,
2324} ;
2425use tantivy:: aggregation:: metric:: {
@@ -169,6 +170,13 @@ pub enum BucketResult {
169170 /// The upper bound error for the doc count of each term.
170171 doc_count_error_upper_bound : Option < u64 > ,
171172 } ,
173+ /// This is the composite aggregation result
174+ Composite {
175+ /// The buckets
176+ buckets : Vec < CompositeBucketEntry > ,
177+ /// The key to start after when paginating
178+ after_key : FxHashMap < String , CompositeKey > ,
179+ } ,
172180}
173181
174182impl From < TantivyBucketResult > for BucketResult {
@@ -189,6 +197,10 @@ impl From<TantivyBucketResult> for BucketResult {
189197 sum_other_doc_count,
190198 doc_count_error_upper_bound,
191199 } ,
200+ TantivyBucketResult :: Composite { buckets, after_key } => BucketResult :: Composite {
201+ buckets : buckets. into_iter ( ) . map ( Into :: into) . collect ( ) ,
202+ after_key : after_key. into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
203+ } ,
192204 }
193205 }
194206}
@@ -211,6 +223,10 @@ impl From<BucketResult> for TantivyBucketResult {
211223 sum_other_doc_count,
212224 doc_count_error_upper_bound,
213225 } ,
226+ BucketResult :: Composite { buckets, after_key } => TantivyBucketResult :: Composite {
227+ buckets : buckets. into_iter ( ) . map ( Into :: into) . collect ( ) ,
228+ after_key : after_key. into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
229+ } ,
214230 }
215231 }
216232}
@@ -410,3 +426,75 @@ impl From<PercentilesMetricResult> for TantivyPercentilesMetricResult {
410426 TantivyPercentilesMetricResult { values }
411427 }
412428}
429+
430+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
431+ pub enum CompositeKey {
432+ /// Boolean key
433+ Bool ( bool ) ,
434+ /// String key
435+ Str ( String ) ,
436+ /// `i64` key
437+ I64 ( i64 ) ,
438+ /// `u64` key
439+ U64 ( u64 ) ,
440+ /// `f64` key
441+ F64 ( f64 ) ,
442+ /// Null key
443+ Null ,
444+ }
445+
446+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
447+ pub struct CompositeBucketEntry {
448+ /// The identifier of the bucket.
449+ pub key : FxHashMap < String , CompositeKey > ,
450+ /// Number of documents in the bucket.
451+ pub doc_count : u64 ,
452+ /// Sub-aggregations in this bucket.
453+ pub sub_aggregation : AggregationResults ,
454+ }
455+
456+ impl From < TantivyCompositeKey > for CompositeKey {
457+ fn from ( value : TantivyCompositeKey ) -> CompositeKey {
458+ match value {
459+ TantivyCompositeKey :: Bool ( b) => CompositeKey :: Bool ( b) ,
460+ TantivyCompositeKey :: Str ( s) => CompositeKey :: Str ( s) ,
461+ TantivyCompositeKey :: I64 ( i) => CompositeKey :: I64 ( i) ,
462+ TantivyCompositeKey :: U64 ( u) => CompositeKey :: U64 ( u) ,
463+ TantivyCompositeKey :: F64 ( f) => CompositeKey :: F64 ( f) ,
464+ TantivyCompositeKey :: Null => CompositeKey :: Null ,
465+ }
466+ }
467+ }
468+
469+ impl From < CompositeKey > for TantivyCompositeKey {
470+ fn from ( value : CompositeKey ) -> TantivyCompositeKey {
471+ match value {
472+ CompositeKey :: Bool ( b) => TantivyCompositeKey :: Bool ( b) ,
473+ CompositeKey :: Str ( s) => TantivyCompositeKey :: Str ( s) ,
474+ CompositeKey :: I64 ( i) => TantivyCompositeKey :: I64 ( i) ,
475+ CompositeKey :: U64 ( u) => TantivyCompositeKey :: U64 ( u) ,
476+ CompositeKey :: F64 ( f) => TantivyCompositeKey :: F64 ( f) ,
477+ CompositeKey :: Null => TantivyCompositeKey :: Null ,
478+ }
479+ }
480+ }
481+
482+ impl From < TantivyCompositeBucketEntry > for CompositeBucketEntry {
483+ fn from ( value : TantivyCompositeBucketEntry ) -> CompositeBucketEntry {
484+ CompositeBucketEntry {
485+ key : value. key . into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
486+ doc_count : value. doc_count ,
487+ sub_aggregation : value. sub_aggregation . into ( ) ,
488+ }
489+ }
490+ }
491+
492+ impl From < CompositeBucketEntry > for TantivyCompositeBucketEntry {
493+ fn from ( value : CompositeBucketEntry ) -> TantivyCompositeBucketEntry {
494+ TantivyCompositeBucketEntry {
495+ key : value. key . into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
496+ doc_count : value. doc_count ,
497+ sub_aggregation : value. sub_aggregation . into ( ) ,
498+ }
499+ }
500+ }
0 commit comments