pub struct RangeQuery { /* private fields */ }Expand description
RangeQuery matches all documents that have at least one term within a defined range.
Matched document will all get a constant Score of one.
§Implementation
§Default
The default implementation collects all documents upfront into a BitSet.
This is done by iterating over the terms within the range and loading all docs for each
TermInfo from the inverted index (posting list) and put them into a BitSet.
Depending on the number of terms matched, this is a potentially expensive operation.
§IP fast field
For IP fast fields a custom variant is used, by scanning the fast field. Unlike the default variant we can walk in a lazy fashion over it, since the fastfield is implicit orderered by DocId.
§Example
use tantivy::collector::Count;
use tantivy::query::RangeQuery;
use tantivy::Term;
use tantivy::schema::{Schema, INDEXED};
use tantivy::{doc, Index, IndexWriter};
use std::ops::Bound;
let mut schema_builder = Schema::builder();
let year_field = schema_builder.add_u64_field("year", INDEXED);
let schema = schema_builder.build();
let index = Index::create_in_ram(schema);
let mut index_writer: IndexWriter = index.writer_with_num_threads(1, 20_000_000)?;
for year in 1950u64..2017u64 {
let num_docs_within_year = 10 + (year - 1950) * (year - 1950);
for _ in 0..num_docs_within_year {
index_writer.add_document(doc!(year_field => year))?;
}
}
index_writer.commit()?;
let reader = index.reader()?;
let searcher = reader.searcher();
let docs_in_the_sixties = RangeQuery::new(
Bound::Included(Term::from_field_u64(year_field, 1960)),
Bound::Excluded(Term::from_field_u64(year_field, 1970)),
);
let num_60s_books = searcher.search(&docs_in_the_sixties, &Count)?;
assert_eq!(num_60s_books, 2285);
Ok(())Implementations§
Source§impl RangeQuery
impl RangeQuery
Sourcepub fn new(lower_bound: Bound<Term>, upper_bound: Bound<Term>) -> RangeQuery
pub fn new(lower_bound: Bound<Term>, upper_bound: Bound<Term>) -> RangeQuery
Creates a new RangeQuery from bounded start and end terms.
If the value type is not correct, something may go terribly wrong when
the Weight object is created.
Sourcepub fn value_type(&self) -> Type
pub fn value_type(&self) -> Type
The value type of the field
Trait Implementations§
Source§impl Clone for RangeQuery
impl Clone for RangeQuery
Source§fn clone(&self) -> RangeQuery
fn clone(&self) -> RangeQuery
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for RangeQuery
impl Debug for RangeQuery
Source§impl Query for RangeQuery
impl Query for RangeQuery
Source§fn weight(&self, enable_scoring: EnableScoring<'_>) -> Result<Box<dyn Weight>>
fn weight(&self, enable_scoring: EnableScoring<'_>) -> Result<Box<dyn Weight>>
Source§fn explain(
&self,
searcher: &Searcher,
doc_address: DocAddress,
) -> Result<Explanation>
fn explain( &self, searcher: &Searcher, doc_address: DocAddress, ) -> Result<Explanation>
Explanation for the score of the document.Auto Trait Implementations§
impl Freeze for RangeQuery
impl RefUnwindSafe for RangeQuery
impl Send for RangeQuery
impl Sync for RangeQuery
impl Unpin for RangeQuery
impl UnsafeUnpin for RangeQuery
impl UnwindSafe for RangeQuery
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
impl<T> Fruit for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more