@@ -70,7 +70,7 @@ fn bench_agg(mut group: InputGroup<Index>) {
7070 register ! ( group, terms_status_with_date_histogram) ;
7171 register ! ( group, terms_status_with_date_histogram_hard_bounds) ;
7272 register ! ( group, terms_status_with_date_histogram_and_sibling_terms) ;
73- register ! ( group, terms_zipf_1000 ) ;
73+ register ! ( group, terms_zipf_1000_only ) ;
7474 register ! ( group, terms_zipf_1000_with_histogram) ;
7575 register ! ( group, terms_zipf_1000_with_avg_sub_agg) ;
7676 register ! ( group, terms_zipf_90) ;
@@ -490,7 +490,7 @@ fn terms_zipf_1000_with_avg_sub_agg(index: &Index) {
490490 execute_agg ( index, agg_req) ;
491491}
492492
493- fn terms_zipf_1000 ( index : & Index ) {
493+ fn terms_zipf_1000_only ( index : & Index ) {
494494 let agg_req = json ! ( {
495495 "my_texts" : { "terms" : { "field" : "text_1000_terms_zipf" } } ,
496496 } ) ;
@@ -763,13 +763,13 @@ fn get_collector(agg_req: Aggregations) -> AggregationCollector {
763763}
764764
765765fn get_test_index_bench ( cardinality : Cardinality ) -> tantivy:: Result < Index > {
766- // Flag to use existing index
766+ // Flag to reuse an on-disk index across runs. The generated data differs per cardinality, so
767+ // the path must include the cardinality — otherwise one cardinality reuses another's index.
767768 let reuse_index = std:: env:: var ( "REUSE_AGG_BENCH_INDEX" ) . is_ok ( ) ;
768- if reuse_index && std:: path:: Path :: new ( "agg_bench" ) . exists ( ) {
769- return Index :: open_in_dir ( "agg_bench" ) ;
769+ let index_dir = format ! ( "agg_bench/{cardinality:?}" ) ;
770+ if reuse_index && std:: path:: Path :: new ( & index_dir) . exists ( ) {
771+ return Index :: open_in_dir ( & index_dir) ;
770772 }
771- // crreate dir
772- std:: fs:: create_dir_all ( "agg_bench" ) ?;
773773 let mut schema_builder = Schema :: builder ( ) ;
774774 let text_fieldtype = tantivy:: schema:: TextOptions :: default ( )
775775 . set_indexing_options (
@@ -796,7 +796,8 @@ fn get_test_index_bench(cardinality: Cardinality) -> tantivy::Result<Index> {
796796 let date_field = schema_builder. add_date_field ( "timestamp" , FAST ) ;
797797 // use tmp dir
798798 let index = if reuse_index {
799- Index :: create_in_dir ( "agg_bench" , schema_builder. build ( ) ) ?
799+ std:: fs:: create_dir_all ( & index_dir) ?;
800+ Index :: create_in_dir ( & index_dir, schema_builder. build ( ) ) ?
800801 } else {
801802 Index :: create_from_tempdir ( schema_builder. build ( ) ) ?
802803 } ;
@@ -821,7 +822,7 @@ fn get_test_index_bench(cardinality: Cardinality) -> tantivy::Result<Index> {
821822 . collect :: < Vec < _ > > ( ) ;
822823
823824 // Prepare 1000 unique terms sampled using a Zipf distribution.
824- // Exponent ~ 1.1 approximates top-20 terms covering around ~20 %.
825+ // Exponent 1.1: heavy head — term_1 alone ~18%, top-20 terms ~57 %.
825826 let terms_1000: Vec < String > = ( 1 ..=1000 ) . map ( |i| format ! ( "term_{i}" ) ) . collect ( ) ;
826827 let zipf_1000 = rand_distr:: Zipf :: new ( 1000.0 , 1.1f64 ) . unwrap ( ) ;
827828
0 commit comments