Struct tantivy::schema::Term

source ·
pub struct Term<B = Vec<u8>>(/* private fields */)
where
    B: AsRef<[u8]>;
Expand description

Term represents the value that the token can take. It’s a serialized representation over different types.

It actually wraps a Vec<u8>. The first 5 bytes are metadata. 4 bytes are the field id, and the last byte is the type.

The serialized value ValueBytes is considered everything after the 4 first bytes (term id).

Implementations§

source§

impl Term

source

pub fn with_capacity(capacity: usize) -> Term

Create a new Term with a buffer with a given capacity.

source

pub fn is_empty(&self) -> bool

Is empty if there are no value bytes.

source

pub fn from_field_ip_addr(field: Field, ip_addr: Ipv6Addr) -> Term

Builds a term given a field, and a Ipv6Addr-value

source

pub fn from_field_u64(field: Field, val: u64) -> Term

Builds a term given a field, and a u64-value

source

pub fn from_field_i64(field: Field, val: i64) -> Term

Builds a term given a field, and a i64-value

source

pub fn from_field_f64(field: Field, val: f64) -> Term

Builds a term given a field, and a f64-value

source

pub fn from_field_bool(field: Field, val: bool) -> Term

Builds a term given a field, and a bool-value

source

pub fn from_field_date(field: Field, val: DateTime) -> Term

Builds a term given a field, and a DateTime value

source

pub fn from_facet(field: Field, facet: &Facet) -> Term

Creates a Term given a facet.

source

pub fn from_field_text(field: Field, text: &str) -> Term

Builds a term given a field, and a string value

source

pub fn from_field_bytes(field: Field, bytes: &[u8]) -> Term

Builds a term bytes.

source

pub fn clear_with_type(&mut self, typ: Type)

Removes the value_bytes and set the type code.

source

pub fn set_u64(&mut self, val: u64)

Sets a u64 value in the term.

U64 are serialized using (8-byte) BigEndian representation. The use of BigEndian has the benefit of preserving the natural order of the values.

source

pub fn set_i64(&mut self, val: i64)

Sets a i64 value in the term.

source

pub fn set_date(&mut self, date: DateTime)

Sets a DateTime value in the term.

source

pub fn set_f64(&mut self, val: f64)

Sets a f64 value in the term.

source

pub fn set_bool(&mut self, val: bool)

Sets a bool value in the term.

source

pub fn set_ip_addr(&mut self, val: Ipv6Addr)

Sets a Ipv6Addr value in the term.

source

pub fn set_bytes(&mut self, bytes: &[u8])

Sets the value of a Bytes field.

source

pub fn set_text(&mut self, text: &str)

Set the texts only, keeping the field untouched.

source

pub fn truncate_value_bytes(&mut self, len: usize)

Truncates the value bytes of the term. Value and field type stays the same.

source

pub fn len_bytes(&self) -> usize

The length of the bytes.

source

pub fn append_bytes(&mut self, bytes: &[u8]) -> &mut [u8]

Appends value bytes to the Term.

This function returns the segment that has just been added.

source

pub fn append_path(&mut self, bytes: &[u8]) -> &mut [u8]

Appends json path bytes to the Term. If the path contains 0 bytes, they are replaced by a “0” string. The 0 byte is used to mark the end of the path.

This function returns the segment that has just been added.

source

pub fn add_json_path_separator(&mut self)

Appends a JSON_PATH_SEGMENT_SEP to the term. Only used for JSON type.

source

pub fn set_json_path_end(&mut self)

Sets the current end to JSON_END_OF_PATH. Only used for JSON type.

source

pub fn set_json_path_separator(&mut self)

Sets the current end to JSON_PATH_SEGMENT_SEP. Only used for JSON type.

source§

impl<B> Term<B>
where B: AsRef<[u8]>,

source

pub fn wrap(data: B) -> Term<B>

Wraps a object holding bytes

source

pub fn typ(&self) -> Type

Return the type of the term.

source

pub fn field(&self) -> Field

Returns the field.

source

pub fn serialized_value_bytes(&self) -> &[u8]

Returns the serialized representation of the value. (this does neither include the field id nor the value type.)

If the term is a string, its value is utf-8 encoded. If the term is a u64, its value is encoded according to byteorder::BigEndian.

source

pub fn value(&self) -> ValueBytes<&[u8]>

Returns the value of the term. address or JSON path + value. (this does not include the field.)

source

pub fn serialized_term(&self) -> &[u8]

Returns the serialized representation of Term. This includes field_id, value type and value.

Do NOT rely on this byte representation in the index. This value is likely to change in the future.

Trait Implementations§

source§

impl<B> Clone for Term<B>
where B: AsRef<[u8]> + Clone,

source§

fn clone(&self) -> Term<B>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<B> Debug for Term<B>
where B: AsRef<[u8]>,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<B> Hash for Term<B>
where B: AsRef<[u8]>,

source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<B> Ord for Term<B>
where B: AsRef<[u8]>,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<B> PartialEq for Term<B>
where B: AsRef<[u8]>,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<B> PartialOrd for Term<B>
where B: AsRef<[u8]>,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<B> Eq for Term<B>
where B: AsRef<[u8]>,

Auto Trait Implementations§

§

impl<B> Freeze for Term<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Term<B>
where B: RefUnwindSafe,

§

impl<B> Send for Term<B>
where B: Send,

§

impl<B> Sync for Term<B>
where B: Sync,

§

impl<B> Unpin for Term<B>
where B: Unpin,

§

impl<B> UnwindSafe for Term<B>
where B: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> Downcast for T
where T: Any,

source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &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)

Convert &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> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> Fruit for T
where T: Send + Downcast,