issue/67 First stab. Iterator working.

This commit is contained in:
Paul Masurel
2016-12-16 23:20:05 +01:00
parent 1559733b03
commit ca5f3e1d46
9 changed files with 296 additions and 188 deletions

View File

@@ -8,7 +8,8 @@ use common::BinarySerializable;
/// The schema is in charge of holding mapping between field names
/// to `Field` objects.
///
/// Because the field id is a `u8`, tantivy can only have at most `256` fields
/// Because the field id is a `u8`, tantivy can only have at most `255` fields.
/// Value 255 is reserved.
#[derive(Copy,Clone,Debug,PartialEq,PartialOrd,Eq,Ord,Hash, RustcEncodable, RustcDecodable)]
pub struct Field(pub u8);

View File

@@ -8,9 +8,11 @@ use super::Field;
/// Term represents the value that the token can take.
///
/// It actually wraps a `Vec<u8>`.
/// TODO remove pub
#[derive(Clone, PartialEq, PartialOrd, Ord, Eq, Hash)]
pub struct Term(Vec<u8>);
impl Term {
/// Pre-allocate a term buffer.
@@ -63,6 +65,14 @@ impl Term {
Term(buffer)
}
/// Returns the serialized value associated to the field.
/// If the term is a string, its value is utf-8 encoded.
/// If the term is a u32, its value is encoded according
/// to `byteorder::LittleEndian`.
pub fn value(&self) -> &[u8] {
&self.0[1..]
}
/// Set the texts only, keeping the field untouched.
pub fn set_text(&mut self, text: &str) {
self.0.resize(1, 0u8);