pub struct Document { /* private fields */ }Expand description
A document to be indexed
Implementations§
Source§impl Document
impl Document
pub fn new() -> Self
pub fn add_text(&mut self, field: Field, value: impl Into<String>)
pub fn add_u64(&mut self, field: Field, value: u64)
pub fn add_i64(&mut self, field: Field, value: i64)
pub fn add_f64(&mut self, field: Field, value: f64)
pub fn add_bytes(&mut self, field: Field, value: Vec<u8>)
pub fn add_sparse_vector( &mut self, field: Field, indices: Vec<u32>, values: Vec<f32>, )
pub fn add_dense_vector(&mut self, field: Field, values: Vec<f32>)
pub fn add_json(&mut self, field: Field, value: Value)
pub fn get_first(&self, field: Field) -> Option<&FieldValue>
pub fn get_all(&self, field: Field) -> impl Iterator<Item = &FieldValue>
pub fn field_values(&self) -> &[(Field, FieldValue)]
Sourcepub fn to_json(&self, schema: &Schema) -> Value
pub fn to_json(&self, schema: &Schema) -> Value
Convert document to a JSON object using field names from schema
Fields marked as multi in the schema are always returned as JSON arrays.
Other fields with multiple values are also returned as arrays.
Fields with a single value (and not marked multi) are returned as scalar values.
Sourcepub fn from_json(json: &Value, schema: &Schema) -> Option<Self>
pub fn from_json(json: &Value, schema: &Schema) -> Option<Self>
Create a Document from a JSON object using field names from schema
Supports:
- String values -> Text fields
- Number values -> U64/I64/F64 fields (based on schema type)
- Array values -> Multiple values for the same field (multifields)
Unknown fields (not in schema) are silently ignored.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnwindSafe for Document
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
Converts
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>
Converts
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.