mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-01-06 01:02:55 +00:00
Merge branch 'issue/query-ergonomics-3' into staged_collector_with_multi
This commit is contained in:
@@ -66,6 +66,7 @@ impl BooleanQuery {
|
||||
BooleanQuery::from(occur_term_queries)
|
||||
}
|
||||
|
||||
/// Deconstructed view of the clauses making up this query.
|
||||
pub fn clauses(&self) -> &[(Occur, Box<Query>)] {
|
||||
&self.subqueries[..]
|
||||
}
|
||||
|
||||
@@ -48,10 +48,12 @@ impl PhraseQuery {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `Field` this `PhraseQuery` is targeting.
|
||||
pub fn field(&self) -> Field {
|
||||
self.field
|
||||
}
|
||||
|
||||
/// The `Term`s in the phrase making up this `PhraseQuery`.
|
||||
pub fn phrase_terms(&self) -> &[Term] {
|
||||
&self.phrase_terms[..]
|
||||
}
|
||||
|
||||
@@ -12,14 +12,14 @@ use std::ops::Range;
|
||||
use termdict::{TermDictionary, TermStreamer};
|
||||
use Result;
|
||||
|
||||
fn map_bound<TFrom, Transform: Fn(TFrom) -> Vec<u8>>(
|
||||
bound: Bound<TFrom>,
|
||||
fn map_bound<TFrom, TTo, Transform: Fn(&TFrom) -> TTo>(
|
||||
bound: &Bound<TFrom>,
|
||||
transform: &Transform,
|
||||
) -> Bound<Vec<u8>> {
|
||||
) -> Bound<TTo> {
|
||||
use self::Bound::*;
|
||||
match bound {
|
||||
Excluded(from_val) => Excluded(transform(from_val)),
|
||||
Included(from_val) => Included(transform(from_val)),
|
||||
Excluded(ref from_val) => Excluded(transform(from_val)),
|
||||
Included(ref from_val) => Included(transform(from_val)),
|
||||
Unbounded => Unbounded,
|
||||
}
|
||||
}
|
||||
@@ -112,12 +112,12 @@ impl RangeQuery {
|
||||
left_bound: Bound<i64>,
|
||||
right_bound: Bound<i64>,
|
||||
) -> RangeQuery {
|
||||
let make_term_val = |val: i64| Term::from_field_i64(field, val).value_bytes().to_owned();
|
||||
let make_term_val = |val: &i64| Term::from_field_i64(field, *val).value_bytes().to_owned();
|
||||
RangeQuery {
|
||||
field,
|
||||
value_type: Type::I64,
|
||||
left_bound: map_bound(left_bound, &make_term_val),
|
||||
right_bound: map_bound(right_bound, &make_term_val),
|
||||
left_bound: map_bound(&left_bound, &make_term_val),
|
||||
right_bound: map_bound(&right_bound, &make_term_val),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,12 +133,12 @@ impl RangeQuery {
|
||||
left_bound: Bound<u64>,
|
||||
right_bound: Bound<u64>,
|
||||
) -> RangeQuery {
|
||||
let make_term_val = |val: u64| Term::from_field_u64(field, val).value_bytes().to_owned();
|
||||
let make_term_val = |val: &u64| Term::from_field_u64(field, *val).value_bytes().to_owned();
|
||||
RangeQuery {
|
||||
field,
|
||||
value_type: Type::U64,
|
||||
left_bound: map_bound(left_bound, &make_term_val),
|
||||
right_bound: map_bound(right_bound, &make_term_val),
|
||||
left_bound: map_bound(&left_bound, &make_term_val),
|
||||
right_bound: map_bound(&right_bound, &make_term_val),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,12 +166,12 @@ impl RangeQuery {
|
||||
left: Bound<&'b str>,
|
||||
right: Bound<&'b str>,
|
||||
) -> RangeQuery {
|
||||
let make_term_val = |val: &str| val.as_bytes().to_vec();
|
||||
let make_term_val = |val: &&str| val.as_bytes().to_vec();
|
||||
RangeQuery {
|
||||
field,
|
||||
value_type: Type::Str,
|
||||
left_bound: map_bound(left, &make_term_val),
|
||||
right_bound: map_bound(right, &make_term_val),
|
||||
left_bound: map_bound(&left, &make_term_val),
|
||||
right_bound: map_bound(&right, &make_term_val),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,6 +186,21 @@ impl RangeQuery {
|
||||
Bound::Excluded(range.end),
|
||||
)
|
||||
}
|
||||
|
||||
/// Field to search over
|
||||
pub fn field(&self) -> Field {
|
||||
self.field
|
||||
}
|
||||
|
||||
/// Lower bound of range
|
||||
pub fn left_bound(&self) -> Bound<Term> {
|
||||
map_bound(&self.left_bound, &|bytes| Term::from_field_bytes(self.field, bytes))
|
||||
}
|
||||
|
||||
/// Upper bound of range
|
||||
pub fn right_bound(&self) -> Bound<Term> {
|
||||
map_bound(&self.right_bound, &|bytes| Term::from_field_bytes(self.field, bytes))
|
||||
}
|
||||
}
|
||||
|
||||
impl Query for RangeQuery {
|
||||
|
||||
@@ -31,6 +31,7 @@ impl TermQuery {
|
||||
}
|
||||
}
|
||||
|
||||
/// The `Term` this query is built out of.
|
||||
pub fn term(&self) -> &Term {
|
||||
&self.term
|
||||
}
|
||||
|
||||
@@ -109,6 +109,12 @@ impl Term {
|
||||
self.0.extend(bytes);
|
||||
}
|
||||
|
||||
pub(crate) fn from_field_bytes(field: Field, bytes: &[u8]) -> Term {
|
||||
let mut term = Term::for_field(field);
|
||||
term.set_bytes(bytes);
|
||||
term
|
||||
}
|
||||
|
||||
/// Set the texts only, keeping the field untouched.
|
||||
pub fn set_text(&mut self, text: &str) {
|
||||
self.set_bytes(text.as_bytes());
|
||||
|
||||
Reference in New Issue
Block a user