pub enum Term {
Default {
value: Value,
},
Field {
field: String,
value: Value,
},
Negate {
term: Box<Term>,
},
Combine {
left: Box<Term>,
right: Box<Term>,
operator: Operator,
},
}Expand description
An expression term.
Variants§
Default
A term searching the default field set, see Value for more information on valid syntax.
§Examples
- Phrase
"boil 'em, mash 'em" - Single Term
potatoes - Ranges
[3 TO 5]
Field
A term searching a specific field. The searched value can be anything supported by Value.
Negate
Searches for the opposite of the contained term.
Combine
Applies a boolean operation to the two contained terms.
Implementations§
Source§impl Term
impl Term
Sourcepub const fn new_default(value: Value) -> Self
pub const fn new_default(value: Value) -> Self
Constructs a Self::Default term.
Purely for the syntactic convenience.
Sourcepub const fn new_negate(term: Box<Term>) -> Self
pub const fn new_negate(term: Box<Term>) -> Self
Constructs a Self::Negate term.
Purely for the syntactic convenience.
Sourcepub fn visit<T>(self, visitor: impl Fn(Term, &dyn Fn(Box<Term>) -> T) -> T) -> T
pub fn visit<T>(self, visitor: impl Fn(Term, &dyn Fn(Box<Term>) -> T) -> T) -> T
Calls the provided visitor with this node, and a function to recurse into another nodes.
Allows for iteration or reduction of the term tree.
§Example
use lucene_query_syntax::Term;
let root: Term = todo!("-name:Bob age:[20 TO 40]");
let complexity = root.visit(|term, recurse| match term {
Term::Combine { left, right, .. } => 1 + recurse(left) + recurse(right),
Term::Negate { term } => 1 + recurse(term),
_ => 1,
});
assert_eq!(complexity, 3);Trait Implementations§
impl Eq for Term
impl StructuralPartialEq for Term
Auto Trait Implementations§
impl Freeze for Term
impl RefUnwindSafe for Term
impl Send for Term
impl Sync for Term
impl Unpin for Term
impl UnsafeUnpin for Term
impl UnwindSafe for Term
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
Mutably borrows from an owned value. Read more