@@ -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 {
@@ -192,6 +200,10 @@ impl From<TantivyBucketResult> for BucketResult {
192200 TantivyBucketResult :: Filter ( _filter_bucket_result) => {
193201 unimplemented ! ( "filter aggregation is not yet supported in quickwit" )
194202 }
203+ TantivyBucketResult :: Composite { buckets, after_key } => BucketResult :: Composite {
204+ buckets : buckets. into_iter ( ) . map ( Into :: into) . collect ( ) ,
205+ after_key : after_key. into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
206+ } ,
195207 }
196208 }
197209}
@@ -214,6 +226,10 @@ impl From<BucketResult> for TantivyBucketResult {
214226 sum_other_doc_count,
215227 doc_count_error_upper_bound,
216228 } ,
229+ BucketResult :: Composite { buckets, after_key } => TantivyBucketResult :: Composite {
230+ buckets : buckets. into_iter ( ) . map ( Into :: into) . collect ( ) ,
231+ after_key : after_key. into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
232+ } ,
217233 }
218234 }
219235}
@@ -413,3 +429,75 @@ impl From<PercentilesMetricResult> for TantivyPercentilesMetricResult {
413429 TantivyPercentilesMetricResult { values }
414430 }
415431}
432+
433+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
434+ pub enum CompositeKey {
435+ /// Boolean key
436+ Bool ( bool ) ,
437+ /// String key
438+ Str ( String ) ,
439+ /// `i64` key
440+ I64 ( i64 ) ,
441+ /// `u64` key
442+ U64 ( u64 ) ,
443+ /// `f64` key
444+ F64 ( f64 ) ,
445+ /// Null key
446+ Null ,
447+ }
448+
449+ #[ derive( Clone , Debug , Serialize , Deserialize ) ]
450+ pub struct CompositeBucketEntry {
451+ /// The identifier of the bucket.
452+ pub key : FxHashMap < String , CompositeKey > ,
453+ /// Number of documents in the bucket.
454+ pub doc_count : u64 ,
455+ /// Sub-aggregations in this bucket.
456+ pub sub_aggregation : AggregationResults ,
457+ }
458+
459+ impl From < TantivyCompositeKey > for CompositeKey {
460+ fn from ( value : TantivyCompositeKey ) -> CompositeKey {
461+ match value {
462+ TantivyCompositeKey :: Bool ( b) => CompositeKey :: Bool ( b) ,
463+ TantivyCompositeKey :: Str ( s) => CompositeKey :: Str ( s) ,
464+ TantivyCompositeKey :: I64 ( i) => CompositeKey :: I64 ( i) ,
465+ TantivyCompositeKey :: U64 ( u) => CompositeKey :: U64 ( u) ,
466+ TantivyCompositeKey :: F64 ( f) => CompositeKey :: F64 ( f) ,
467+ TantivyCompositeKey :: Null => CompositeKey :: Null ,
468+ }
469+ }
470+ }
471+
472+ impl From < CompositeKey > for TantivyCompositeKey {
473+ fn from ( value : CompositeKey ) -> TantivyCompositeKey {
474+ match value {
475+ CompositeKey :: Bool ( b) => TantivyCompositeKey :: Bool ( b) ,
476+ CompositeKey :: Str ( s) => TantivyCompositeKey :: Str ( s) ,
477+ CompositeKey :: I64 ( i) => TantivyCompositeKey :: I64 ( i) ,
478+ CompositeKey :: U64 ( u) => TantivyCompositeKey :: U64 ( u) ,
479+ CompositeKey :: F64 ( f) => TantivyCompositeKey :: F64 ( f) ,
480+ CompositeKey :: Null => TantivyCompositeKey :: Null ,
481+ }
482+ }
483+ }
484+
485+ impl From < TantivyCompositeBucketEntry > for CompositeBucketEntry {
486+ fn from ( value : TantivyCompositeBucketEntry ) -> CompositeBucketEntry {
487+ CompositeBucketEntry {
488+ key : value. key . into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
489+ doc_count : value. doc_count ,
490+ sub_aggregation : value. sub_aggregation . into ( ) ,
491+ }
492+ }
493+ }
494+
495+ impl From < CompositeBucketEntry > for TantivyCompositeBucketEntry {
496+ fn from ( value : CompositeBucketEntry ) -> TantivyCompositeBucketEntry {
497+ TantivyCompositeBucketEntry {
498+ key : value. key . into_iter ( ) . map ( |( k, v) | ( k, v. into ( ) ) ) . collect ( ) ,
499+ doc_count : value. doc_count ,
500+ sub_aggregation : value. sub_aggregation . into ( ) ,
501+ }
502+ }
503+ }
0 commit comments