Added CLI wizard for index new

This commit is contained in:
Paul Masurel
2016-08-11 00:37:07 +09:00
parent c53a930389
commit ca24daae51
8 changed files with 26 additions and 41 deletions

View File

@@ -28,9 +28,9 @@ uuid = "0.1"
iron = "0.4"
staticfile = "0.3.0"
persistent="*"
ansi_term = "*"
clap = "2"
[dev-dependencies]
rand = "0.3.13"

View File

@@ -197,7 +197,7 @@ impl Index {
self.metas.write().unwrap().clone_from(&loaded_meta);
Ok(())
}
pub fn save_metas(&mut self,) -> Result<()> {
let mut w = Vec::new();
{

View File

@@ -25,6 +25,7 @@ extern crate num_cpus;
extern crate combine;
extern crate itertools;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate rand;

View File

@@ -15,4 +15,4 @@ impl BinarySerializable for Field {
u8::deserialize(reader).map(Field)
}
}

View File

@@ -1,6 +1,7 @@
use schema::TextOptions;
use schema::U32Options;
#[derive(Clone, Debug, RustcDecodable, RustcEncodable)]
pub enum FieldEntry {
Text(String, TextOptions),

View File

@@ -20,13 +20,21 @@ pub use self::field_entry::FieldEntry;
pub use self::field_value::FieldValue;
pub use self::text_options::TextOptions;
pub use self::text_options::FAST;
pub use self::text_options::TEXT;
pub use self::text_options::STRING;
pub use self::text_options::STORED;
pub use self::text_options::TextIndexingOptions;
pub use self::u32_options::U32Options;
pub use self::u32_options::FAST_U32;
pub use self::u32_options::FAST;
use regex::Regex;
pub fn is_valid_field_name(field_name: &str) -> bool {
lazy_static! {
static ref FIELD_NAME_PTN: Regex = Regex::new("[_a-zA-Z0-9]+").unwrap();
}
FIELD_NAME_PTN.is_match(field_name)
}

View File

@@ -5,7 +5,6 @@ use std::ops::BitOr;
pub struct TextOptions {
indexing_options: TextIndexingOptions,
stored: bool,
fast: bool,
}
impl TextOptions {
@@ -18,20 +17,11 @@ impl TextOptions {
self.stored
}
pub fn is_fast(&self,) -> bool {
self.fast
}
pub fn set_stored(mut self,) -> TextOptions {
self.stored = true;
self
}
pub fn set_fast(mut self,) -> TextOptions {
self.fast = true;
self
}
pub fn set_indexing_options(mut self, indexing_options: TextIndexingOptions) -> TextOptions {
self.indexing_options = indexing_options;
self
@@ -39,7 +29,6 @@ impl TextOptions {
pub fn new() -> TextOptions {
TextOptions {
fast: false,
indexing_options: TextIndexingOptions::Unindexed,
stored: false,
}
@@ -115,7 +104,6 @@ impl BitOr for TextIndexingOptions {
pub const STRING: TextOptions = TextOptions {
indexing_options: TextIndexingOptions::Untokenized,
stored: false,
fast: false,
};
@@ -123,7 +111,6 @@ pub const STRING: TextOptions = TextOptions {
pub const TEXT: TextOptions = TextOptions {
indexing_options: TextIndexingOptions::TokenizedWithFreqAndPosition,
stored: false,
fast: false,
};
/// A stored fields of a document can be retrieved given its DocId.
@@ -133,15 +120,6 @@ pub const TEXT: TextOptions = TextOptions {
pub const STORED: TextOptions = TextOptions {
indexing_options: TextIndexingOptions::Unindexed,
stored: true,
fast: false,
};
/// Fast field are used for field you need to access many times during
/// collection. (e.g: for sort, aggregates).
pub const FAST: TextOptions = TextOptions {
indexing_options: TextIndexingOptions::Unindexed,
stored: false,
fast: true
};
@@ -153,7 +131,6 @@ impl BitOr for TextOptions {
let mut res = TextOptions::new();
res.indexing_options = self.indexing_options | other.indexing_options;
res.stored = self.stored || other.stored;
res.fast = self.fast || other.fast;
res
}
}
@@ -168,16 +145,9 @@ mod tests {
#[test]
fn test_field_options() {
{
let field_options = STORED | FAST;
assert!(field_options.is_stored());
assert!(field_options.is_fast());
assert!(!field_options.get_indexing_options().is_tokenized());
}
{
let field_options = STORED | TEXT;
assert!(field_options.is_stored());
assert!(!field_options.is_fast());
assert!(field_options.get_indexing_options().is_tokenized());
}
{

View File

@@ -22,16 +22,21 @@ impl U32Options {
pub fn is_indexed(&self,) -> bool {
self.indexed
}
pub fn is_fast(&self,) -> bool {
self.fast
}
pub fn set_stored(mut self,) -> U32Options {
self.stored = true;
self
}
pub fn set_indexed(mut self,) -> U32Options {
self.indexed = true;
self
}
pub fn is_fast(&self,) -> bool {
self.fast
}
pub fn set_fast(mut self,) -> U32Options {
self.fast = true;
self
@@ -42,7 +47,7 @@ impl U32Options {
/// The field will be tokenized and indexed
pub const FAST_U32: U32Options = U32Options {
pub const FAST: U32Options = U32Options {
indexed: false,
stored: false,
fast: true,