Skip to content

Commit 68b68f2

Browse files
committed
add deprecated functions
1 parent d057f42 commit 68b68f2

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/postings/json_postings_writer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::indexer::path_to_unordered_id::OrderedPathId;
88
use crate::postings::postings_writer::SpecializedPostingsWriter;
99
use crate::postings::recorder::{BufferLender, DocIdRecorder, Recorder};
1010
use crate::postings::{FieldSerializer, IndexingContext, IndexingPosition, PostingsWriter};
11-
use crate::schema::{Field, Type, ValueBytes};
11+
use crate::schema::{Field, Type};
1212
use crate::tokenizer::TokenStream;
1313
use crate::DocId;
1414

src/schema/term.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{fmt, str};
55
use columnar::MonotonicallyMappableToU128;
66
use common::json_path_writer::{JSON_END_OF_PATH, JSON_PATH_SEGMENT_SEP_STR};
77
use common::JsonPathWriter;
8+
use serde::{Deserialize, Serialize};
89

910
use super::date_time_options::DATE_TIME_PRECISION_INDEXED;
1011
use super::{Field, Schema};
@@ -18,7 +19,7 @@ use crate::DateTime;
1819
///
1920
/// A term is composed of Field and the serialized value bytes.
2021
/// The serialized value bytes themselves start with a one byte type tag followed by the payload.
21-
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
22+
#[derive(Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
2223
pub struct Term {
2324
field: Field,
2425
serialized_value_bytes: Vec<u8>,
@@ -28,6 +29,34 @@ pub struct Term {
2829
const TERM_TYPE_TAG_LEN: usize = 1;
2930

3031
impl Term {
32+
/// Takes a serialized term and wraps it as a Term.
33+
/// First 4 bytes are the field id
34+
#[deprecated(
35+
note = "we want to avoid working on the serialized representation directly, replace with \
36+
typed API calls (add more if needed)"
37+
)]
38+
pub fn wrap(serialized: &[u8]) -> Term {
39+
let field_id_bytes: [u8; 4] = serialized[0..4].try_into().unwrap();
40+
let field_id = u32::from_be_bytes(field_id_bytes);
41+
Term {
42+
field: Field::from_field_id(field_id),
43+
serialized_value_bytes: serialized[4..].to_vec(),
44+
}
45+
}
46+
47+
/// Returns the serialized representation of the term.
48+
/// First 4 bytes are the field id
49+
#[deprecated(
50+
note = "we want to avoid working on the serialized representation directly, replace with \
51+
typed API calls (add more if needed)"
52+
)]
53+
pub fn serialized_term(&self) -> Vec<u8> {
54+
let mut serialized = Vec::with_capacity(4 + self.serialized_value_bytes.len());
55+
serialized.extend(self.field.field_id().to_be_bytes().as_ref());
56+
serialized.extend_from_slice(&self.serialized_value_bytes);
57+
serialized
58+
}
59+
3160
/// Create a new Term with a buffer with a given capacity.
3261
pub fn with_capacity(capacity: usize) -> Term {
3362
let mut data = Vec::with_capacity(TERM_TYPE_TAG_LEN + capacity);

0 commit comments

Comments
 (0)