From 8bcfdb8e80060c55086b2ea8e8c8ae3a916a8dbc Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Sun, 26 Feb 2017 21:35:18 +0900 Subject: [PATCH] NOBUG misc ... --- src/core/segment_id.rs | 10 +++++++++ src/indexer/segment_writer.rs | 19 ------------------ src/schema/document.rs | 15 ++++++-------- src/schema/mod.rs | 2 ++ src/schema/text_options.rs | 2 +- src/schema/u32_options.rs | 38 ++++++++++++++++++++++++++++++++++- 6 files changed, 56 insertions(+), 30 deletions(-) diff --git a/src/core/segment_id.rs b/src/core/segment_id.rs index 92920c6cb..6515ab423 100644 --- a/src/core/segment_id.rs +++ b/src/core/segment_id.rs @@ -42,14 +42,24 @@ fn create_uuid() -> Uuid { } impl SegmentId { + #[doc(hidden)] pub fn generate_random() -> SegmentId { SegmentId(create_uuid()) } + + /// Returns a shorter identifier of the segment. + /// + /// We are using UUID4, so only 6 bits are fixed, + /// and the rest is random. + /// + /// Picking the first 8 chars is ok to identify + /// segments in a display message. pub fn short_uuid_string(&self,) -> String { (&self.0.simple().to_string()[..8]).to_string() } + /// Returns a segment uuid string. pub fn uuid_string(&self,) -> String { self.0.simple().to_string() } diff --git a/src/indexer/segment_writer.rs b/src/indexer/segment_writer.rs index feae0e5e5..bd324bd97 100644 --- a/src/indexer/segment_writer.rs +++ b/src/indexer/segment_writer.rs @@ -130,25 +130,6 @@ impl<'a> SegmentWriter<'a> { pub fn is_buffer_full(&self,) -> bool { self.heap.num_free_bytes() <= MARGIN_IN_BYTES } - - // pub fn compute_doc_mapping_after_delete(&self, mut delete_queue_cursor: DeleteQueueCursor) -> Vec> { - // let delete_docs = self.compute_delete_mask(&mut delete_queue_cursor); - // let max_doc: usize = self.max_doc as usize; - // let mut doc_autoinc = 0u32; - // (0..max_doc) - // .map(|doc| { - // if delete_docs.contains(doc) { - // None - // } - // else { - // let new_doc = doc_autoinc; - // doc_autoinc += 1; - // Some(new_doc) - // } - // }) - // .collect::>() - // } - /// Indexes a new document /// diff --git a/src/schema/document.rs b/src/schema/document.rs index 671237155..87d0b46f7 100644 --- a/src/schema/document.rs +++ b/src/schema/document.rs @@ -11,7 +11,7 @@ use itertools::Itertools; /// Documents are really just a list of couple `(field, value)`. /// In this list, one field may appear more than once. -#[derive(Debug, RustcEncodable, RustcDecodable)] +#[derive(Debug, RustcEncodable, RustcDecodable, Default)] pub struct Document { field_values: Vec, } @@ -31,6 +31,11 @@ impl Eq for Document {} impl Document { + /// Creates a new, empty document object + pub fn new() -> Document { + Document::default() + } + /// Returns the number of `(field, value)` pairs. pub fn len(&self,) -> usize { self.field_values.len() @@ -97,14 +102,6 @@ impl Document { } } -impl Default for Document { - - fn default() -> Document { - Document { - field_values: Vec::new(), - } - } -} impl From> for Document { fn from(field_values: Vec) -> Document { diff --git a/src/schema/mod.rs b/src/schema/mod.rs index 224d9f47d..b1802d1e5 100644 --- a/src/schema/mod.rs +++ b/src/schema/mod.rs @@ -131,6 +131,8 @@ pub use self::text_options::STORED; pub use self::u32_options::U32Options; pub use self::u32_options::FAST; +pub use self::u32_options::U32_INDEXED; +pub use self::u32_options::U32_STORED; use regex::Regex; diff --git a/src/schema/text_options.rs b/src/schema/text_options.rs index 91000de81..c718e2a87 100644 --- a/src/schema/text_options.rs +++ b/src/schema/text_options.rs @@ -206,7 +206,7 @@ impl BitOr for TextOptions { fn bitor(self, other: TextOptions) -> TextOptions { let mut res = TextOptions::default(); res.indexing = self.indexing | other.indexing; - res.stored = self.stored || other.stored; + res.stored = self.stored | other.stored; res } } diff --git a/src/schema/u32_options.rs b/src/schema/u32_options.rs index 39be904ed..5f29f63b5 100644 --- a/src/schema/u32_options.rs +++ b/src/schema/u32_options.rs @@ -1,3 +1,5 @@ +use std::ops::BitOr; + /// Define how a U32 field should be handled by tantivy. #[derive(Clone,Debug,PartialEq,Eq, RustcDecodable, RustcEncodable)] pub struct U32Options { @@ -65,9 +67,43 @@ impl Default for U32Options { } -/// Shortcut for +/// Shortcut for a u32 fast field. +/// +/// Such a shortcut can be composed as follows `STORED | FAST | U32_INDEXED` pub const FAST: U32Options = U32Options { indexed: false, stored: false, fast: true, }; + +/// Shortcut for a u32 indexed field. +/// +/// Such a shortcut can be composed as follows `STORED | FAST | U32_INDEXED` +pub const U32_INDEXED: U32Options = U32Options { + indexed: true, + stored: false, + fast: false, +}; + +/// Shortcut for a u32 stored field. +/// +/// Such a shortcut can be composed as follows `STORED | FAST | U32_INDEXED` +pub const U32_STORED: U32Options = U32Options { + indexed: false, + stored: true, + fast: false, +}; + + +impl BitOr for U32Options { + + type Output = U32Options; + + fn bitor(self, other: U32Options) -> U32Options { + let mut res = U32Options::default(); + res.indexed = self.indexed | other.indexed; + res.stored = self.stored | other.stored; + res.fast = self.fast | other.fast; + res + } +} \ No newline at end of file