Skip to content

Commit 83350f6

Browse files
committed
Added range query optimization
1 parent dc4c218 commit 83350f6

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/query/range_query/range_query_fastfield.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::net::Ipv6Addr;
66
use std::ops::{Bound, RangeInclusive};
77

88
use columnar::{
9-
Column, ColumnType, MonotonicallyMappableToU128, MonotonicallyMappableToU64, NumericalType,
10-
StrColumn,
9+
Cardinality, Column, ColumnType, MonotonicallyMappableToU128, MonotonicallyMappableToU64,
10+
NumericalType, StrColumn,
1111
};
1212
use common::bounds::{BoundsRange, TransformBound};
1313

@@ -397,6 +397,8 @@ fn search_on_u64_ff(
397397
boost: Score,
398398
bounds: BoundsRange<u64>,
399399
) -> crate::Result<Box<dyn Scorer>> {
400+
let col_min_value = column.min_value();
401+
let col_max_value = column.max_value();
400402
#[expect(clippy::reversed_empty_ranges)]
401403
let value_range = bound_to_value_range(
402404
&bounds.lower_bound,
@@ -408,6 +410,18 @@ fn search_on_u64_ff(
408410
if value_range.is_empty() {
409411
return Ok(Box::new(EmptyScorer));
410412
}
413+
if col_min_value >= *value_range.start() && col_max_value <= *value_range.end() {
414+
// all values in the column are within the range.
415+
if column.index.get_cardinality() == Cardinality::Full {
416+
return Ok(Box::new(ConstScorer::new(
417+
AllScorer::new(column.num_docs()),
418+
boost,
419+
)));
420+
} else {
421+
// TODO Make it a field presence request for that specific column
422+
}
423+
}
424+
411425
let docset = RangeDocSet::new(value_range, column);
412426
Ok(Box::new(ConstScorer::new(docset, boost)))
413427
}

0 commit comments

Comments
 (0)