File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -481,10 +481,16 @@ impl MemorySearchIndex {
481
481
) ;
482
482
0
483
483
} ) ;
484
- } else if field == & Field :: from_field_id ( SEARCH_FIELD_ID ) {
485
- stats
486
- . num_terms_by_field
487
- . insert ( * field, ( * total_term_diff as i64 ) . try_into ( ) ?) ;
484
+ } else {
485
+ let total_term_diff =
486
+ ( * total_term_diff as i64 ) . try_into ( ) . unwrap_or_else ( |e| {
487
+ tracing:: warn!(
488
+ "Inserting 0 for num_terms for field {field:?} with \
489
+ {total_term_diff} and error {e}"
490
+ ) ;
491
+ 0
492
+ } ) ;
493
+ stats. num_terms_by_field . insert ( * field, total_term_diff) ;
488
494
}
489
495
}
490
496
for ( term, term_id) in & term_ids {
Original file line number Diff line number Diff line change @@ -958,7 +958,7 @@ impl<RT: Runtime> SearcherImpl<RT> {
958
958
// Tantivy's total_num_tokens count is only approximate, so we can't guarantee this won't underflow.
959
959
. unwrap_or_else ( || {
960
960
tracing:: warn!(
961
- "num_terms underflowed for field {field:?}, subtracted num_terms_deleted: {num_terms_deleted} from \
961
+ "num_terms underflowed for field {field:?} in query_bm_25_stats_impl , subtracted num_terms_deleted: {num_terms_deleted} from \
962
962
total_num_tokens: {total_num_tokens}"
963
963
) ;
964
964
0
@@ -971,6 +971,9 @@ impl<RT: Runtime> SearcherImpl<RT> {
971
971
num_documents,
972
972
doc_frequencies,
973
973
} ;
974
+ if stats. is_empty ( ) {
975
+ tracing:: warn!( "Empty BM25 stats" ) ;
976
+ }
974
977
Ok ( stats)
975
978
} ,
976
979
}
@@ -1360,6 +1363,12 @@ impl Bm25Stats {
1360
1363
doc_frequencies : BTreeMap :: new ( ) ,
1361
1364
}
1362
1365
}
1366
+
1367
+ pub fn is_empty ( & self ) -> bool {
1368
+ self . num_terms_by_field . is_empty ( )
1369
+ && self . num_documents == 0
1370
+ && self . doc_frequencies . is_empty ( )
1371
+ }
1363
1372
}
1364
1373
1365
1374
impl Add for Bm25Stats {
You can’t perform that action at this time.
0 commit comments