From ab6b532cc40a0cd708fd84b8734519e442ffc616 Mon Sep 17 00:00:00 2001 From: Pascal Seitz Date: Thu, 14 Apr 2022 12:06:36 +0800 Subject: [PATCH] add comments --- examples/aggregation.rs | 2 +- src/aggregation/agg_req_with_accessor.rs | 8 ++++---- src/aggregation/bucket/range.rs | 3 ++- src/aggregation/mod.rs | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/examples/aggregation.rs b/examples/aggregation.rs index f24ac6d46..82cc0fccd 100644 --- a/examples/aggregation.rs +++ b/examples/aggregation.rs @@ -122,7 +122,7 @@ fn main() -> tantivy::Result<()> { let searcher = reader.searcher(); let agg_res: AggregationResults = searcher.search(&term_query, &collector).unwrap(); - let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?; + let res: Value = serde_json::to_value(&agg_res)?; println!("{}", serde_json::to_string_pretty(&res)?); Ok(()) diff --git a/src/aggregation/agg_req_with_accessor.rs b/src/aggregation/agg_req_with_accessor.rs index 52a5ea5e5..8ed82ac5c 100644 --- a/src/aggregation/agg_req_with_accessor.rs +++ b/src/aggregation/agg_req_with_accessor.rs @@ -121,7 +121,7 @@ impl MetricAggregationWithAccessor { Ok(MetricAggregationWithAccessor { accessor: accessor .as_single() - .expect("unexpected fast field cardinatility") + .expect("unexpected fast field cardinality") .clone(), field_type, metric: metric.clone(), @@ -173,9 +173,9 @@ fn get_ff_reader_and_validate( if let Some((ff_type, field_cardinality)) = type_and_cardinality(field_type) { if ff_type == FastType::Date { - return Err(TantivyError::InvalidArgument(format!( - "Unsupported field type date in aggregation" - ))); + return Err(TantivyError::InvalidArgument( + "Unsupported field type date in aggregation".to_string(), + )); } if cardinality != field_cardinality { diff --git a/src/aggregation/bucket/range.rs b/src/aggregation/bucket/range.rs index e50ea1c64..0989b510c 100644 --- a/src/aggregation/bucket/range.rs +++ b/src/aggregation/bucket/range.rs @@ -110,7 +110,8 @@ pub(crate) struct SegmentRangeBucketEntry { pub sub_aggregation: Option, /// The from range of the bucket. Equals f64::MIN when None. pub from: Option, - /// The to range of the bucket. Equals f64::MAX when None. + /// The to range of the bucket. Equals f64::MAX when None. Open interval, `to` is not + /// inclusive. pub to: Option, } diff --git a/src/aggregation/mod.rs b/src/aggregation/mod.rs index 8dc3bd406..cf974d367 100644 --- a/src/aggregation/mod.rs +++ b/src/aggregation/mod.rs @@ -363,6 +363,7 @@ mod tests { searcher.search(&AllQuery, &collector)? }; + // Test serialization/deserialization rountrip let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?; Ok(res) } @@ -544,7 +545,6 @@ mod tests { }; let res: Value = serde_json::from_str(&serde_json::to_string(&agg_res)?)?; - // println!("{}", serde_json::to_string_pretty(&res).unwrap()); assert_eq!(res["bucketsL1"]["buckets"][0]["doc_count"], 3); assert_eq!( @@ -1138,7 +1138,7 @@ mod tests { let score_field_i64 = schema_builder.add_i64_field("score_i64", score_fieldtype); let index = Index::create_from_tempdir(schema_builder.build())?; let few_terms_data = vec!["INFO", "ERROR", "WARN", "DEBUG"]; - let many_terms_data = (0..150_000) + let many_terms_data = (0..15_000) .map(|num| format!("author{}", num)) .collect::>(); {