Skip to content

Commit 8e004f5

Browse files
emmaling27Convex, Inc.
authored and
Convex, Inc.
committed
Fix num_terms underflow (#27357)
GitOrigin-RevId: a687eb36552b39f7ca52aaaa4af55b83c1ea99be
1 parent 88a8a82 commit 8e004f5

File tree

1 file changed

+8
-1
lines changed
  • crates/search/src/memory_index

1 file changed

+8
-1
lines changed

crates/search/src/memory_index/mod.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,14 @@ impl MemorySearchIndex {
473473
if let Some(term_diff) = stats.num_terms_by_field.get_mut(field) {
474474
*term_diff = term_diff
475475
.checked_add_signed(*total_term_diff as i64)
476-
.context("num_terms underflow")?;
476+
// Tantivy's total_num_tokens count is only approximate, so we can't guarantee this won't underflow.
477+
.unwrap_or_else(|| {
478+
tracing::warn!(
479+
"num_terms underflowed for field {field:?}, added {term_diff} and \
480+
{total_term_diff}"
481+
);
482+
0
483+
});
477484
} else if field == &Field::from_field_id(SEARCH_FIELD_ID) {
478485
stats
479486
.num_terms_by_field

0 commit comments

Comments
 (0)