mirror of
https://github.com/quickwit-oss/tantivy.git
synced 2026-05-30 23:20:40 +00:00
add AsRef, expose object and array iter on Value (#2207)
add AsRef expose object and array iter add to_json on Document
This commit is contained in:
@@ -195,14 +195,6 @@ impl TantivyDocument {
|
||||
Ok(document)
|
||||
}
|
||||
|
||||
/// Encode the schema in JSON.
|
||||
///
|
||||
/// Encoding a document cannot fail.
|
||||
pub fn to_json(&self, schema: &Schema) -> String {
|
||||
serde_json::to_string(&self.to_named_doc(schema))
|
||||
.expect("doc encoding failed. This is a bug")
|
||||
}
|
||||
|
||||
/// Build a document object from a json-object.
|
||||
pub fn parse_json(schema: &Schema, doc_json: &str) -> Result<TantivyDocument, DocParsingError> {
|
||||
let json_obj: Map<String, serde_json::Value> =
|
||||
|
||||
@@ -235,6 +235,14 @@ pub trait Document: DocumentDeserialize + Send + Sync + 'static {
|
||||
}
|
||||
NamedFieldDocument(field_map)
|
||||
}
|
||||
|
||||
/// Encode the doc in JSON.
|
||||
///
|
||||
/// Encoding a document cannot fail.
|
||||
fn to_json(&self, schema: &Schema) -> String {
|
||||
serde_json::to_string(&self.to_named_doc(schema))
|
||||
.expect("doc encoding failed. This is a bug")
|
||||
}
|
||||
}
|
||||
|
||||
/// A single field value.
|
||||
@@ -357,6 +365,26 @@ pub trait Value<'a>: Send + Sync + Debug {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns the iterator over the array if the Value is an array.
|
||||
fn as_array(&self) -> Option<Self::ArrayIter> {
|
||||
if let ReferenceValue::Array(val) = self.as_value() {
|
||||
Some(val)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns the iterator over the object if the Value is an object.
|
||||
fn as_object(&self) -> Option<Self::ObjectIter> {
|
||||
if let ReferenceValue::Object(val) = self.as_value() {
|
||||
Some(val)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Returns true if the Value is an array.
|
||||
fn is_array(&self) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user