@@ -375,7 +375,16 @@ mod proptest_boolean_query {
375
375
}
376
376
}
377
377
378
- fn create_index_with_boolean_permutations ( num_fields : usize ) -> ( Index , Vec < Field > ) {
378
+ fn doc_ids ( num_docs : usize , num_fields : usize ) -> impl Iterator < Item = DocId > {
379
+ let permutations = 1 << num_fields;
380
+ let copies = ( num_docs as f32 / permutations as f32 ) . ceil ( ) as u32 ;
381
+ ( 0 ..( permutations * copies) ) . into_iter ( )
382
+ }
383
+
384
+ fn create_index_with_boolean_permutations (
385
+ num_docs : usize ,
386
+ num_fields : usize ,
387
+ ) -> ( Index , Vec < Field > ) {
379
388
let mut schema_builder = Schema :: builder ( ) ;
380
389
let fields: Vec < Field > = ( 0 ..num_fields)
381
390
. map ( |i| schema_builder. add_text_field ( & format ! ( "field_{}" , i) , TEXT ) )
@@ -384,10 +393,10 @@ mod proptest_boolean_query {
384
393
let index = Index :: create_in_ram ( schema) ;
385
394
let mut writer = index. writer_for_tests ( ) . unwrap ( ) ;
386
395
387
- for doc_id in 0 .. ( 1 << num_fields) {
396
+ for doc_id in doc_ids ( num_docs , num_fields) {
388
397
let mut doc: BTreeMap < _ , OwnedValue > = BTreeMap :: default ( ) ;
389
398
for ( field_idx, & field) in fields. iter ( ) . enumerate ( ) {
390
- if ( doc_id >> field_idx) & 1 == 1 {
399
+ if BooleanQueryAST :: matches_field ( doc_id, field_idx) {
391
400
doc. insert ( field, "true" . into ( ) ) ;
392
401
}
393
402
}
@@ -414,14 +423,15 @@ mod proptest_boolean_query {
414
423
415
424
#[ test]
416
425
fn proptest_boolean_query ( ) {
426
+ let num_docs = 10000 ;
417
427
let num_fields = 8 ;
418
- let ( index, fields) = create_index_with_boolean_permutations ( num_fields) ;
428
+ let ( index, fields) = create_index_with_boolean_permutations ( num_docs , num_fields) ;
419
429
let searcher = index. reader ( ) . unwrap ( ) . searcher ( ) ;
420
430
proptest ! ( |( ast in arb_boolean_query_ast( num_fields) ) | {
421
431
let query = ast. to_query( & fields) ;
422
432
423
433
let mut matching_docs = HashSet :: new( ) ;
424
- for doc_id in 0 .. ( 1 << num_fields) {
434
+ for doc_id in doc_ids ( num_docs , num_fields) {
425
435
if ast. matches( doc_id as DocId ) {
426
436
matching_docs. insert( doc_id as DocId ) ;
427
437
}
0 commit comments