Renamed u64options

This commit is contained in:
Paul Masurel
2017-04-21 09:13:26 +09:00
parent deb04eb090
commit 1dbd54edbb
6 changed files with 20 additions and 127 deletions

View File

@@ -311,7 +311,7 @@ mod tests {
.set_indexing_options(TextIndexingOptions::TokenizedWithFreq)
.set_stored();
let text_field = schema_builder.add_text_field("text", text_fieldtype);
let score_fieldtype = schema::U64Options::default().set_fast();
let score_fieldtype = schema::IntOptions::default().set_fast();
let score_field = schema_builder.add_u64_field("score", score_fieldtype);
let index = Index::create_in_ram(schema_builder.build());
@@ -432,7 +432,7 @@ mod tests {
.set_indexing_options(TextIndexingOptions::TokenizedWithFreq)
.set_stored();
let text_field = schema_builder.add_text_field("text", text_fieldtype);
let score_fieldtype = schema::U64Options::default().set_fast();
let score_fieldtype = schema::IntOptions::default().set_fast();
let score_field = schema_builder.add_u64_field("score", score_fieldtype);
let index = Index::create_in_ram(schema_builder.build());
let mut index_writer = index.writer_with_num_threads(1, 40_000_000).unwrap();

View File

@@ -1,5 +1,5 @@
use schema::TextOptions;
use schema::U64Options;
use schema::IntOptions;
use rustc_serialize::Decodable;
use rustc_serialize::Decoder;
@@ -33,7 +33,7 @@ impl FieldEntry {
/// Creates a new u64 field entry in the schema, given
/// a name, and some options.
pub fn new_u64(field_name: String, field_type: U64Options) -> FieldEntry {
pub fn new_u64(field_name: String, field_type: IntOptions) -> FieldEntry {
FieldEntry {
name: field_name,
field_type: FieldType::U64(field_type),
@@ -123,7 +123,7 @@ impl Decodable for FieldEntry {
d.read_struct_field("options", 2, |d| {
match field_type.as_ref() {
"u64" => {
let u64_options = try!(U64Options::decode(d));
let u64_options = try!(IntOptions::decode(d));
Ok(FieldEntry::new_u64(name, u64_options))
}
"text" => {

View File

@@ -1,5 +1,5 @@
use schema::TextOptions;
use schema::U64Options;
use schema::IntOptions;
use rustc_serialize::json::Json;
use schema::Value;
@@ -23,8 +23,10 @@ pub enum ValueParsingError {
pub enum FieldType {
/// String field type configuration
Str(TextOptions),
/// U64 field type configuration
U64(U64Options),
/// Unsigned 64-bits integers field type configuration
U64(IntOptions),
// /// Signed 64-bits integers 64 field type configuration
// I64(IntOptions),
}
impl FieldType {

View File

@@ -71,7 +71,7 @@ let schema = schema_builder.build();
```
use tantivy::schema::*;
let mut schema_builder = SchemaBuilder::default();
let num_stars_options = U64Options::default()
let num_stars_options = IntOptions::default()
.set_stored()
.set_indexed();
schema_builder.add_u64_field("num_stars", num_stars_options);
@@ -104,7 +104,7 @@ mod field_entry;
mod field_value;
mod text_options;
mod u64_options;
mod int_options;
mod field;
mod value;
mod named_field_document;
@@ -129,10 +129,10 @@ pub use self::text_options::TEXT;
pub use self::text_options::STRING;
pub use self::text_options::STORED;
pub use self::u64_options::U64Options;
pub use self::u64_options::FAST;
pub use self::u64_options::U64_INDEXED;
pub use self::u64_options::U64_STORED;
pub use self::int_options::IntOptions;
pub use self::int_options::FAST;
pub use self::int_options::U64_INDEXED;
pub use self::int_options::U64_STORED;
use regex::Regex;

View File

@@ -59,7 +59,7 @@ impl SchemaBuilder {
pub fn add_u64_field(
&mut self,
field_name_str: &str,
field_options: U64Options) -> Field {
field_options: IntOptions) -> Field {
let field_name = String::from(field_name_str);
let field_entry = FieldEntry::new_u64(field_name, field_options);
self.add_field(field_entry)
@@ -328,7 +328,7 @@ mod tests {
#[test]
pub fn test_schema_serialization() {
let mut schema_builder = SchemaBuilder::default();
let count_options = U64Options::default().set_stored().set_fast();
let count_options = IntOptions::default().set_stored().set_fast();
schema_builder.add_text_field("title", TEXT);
schema_builder.add_text_field("author", STRING);
schema_builder.add_u64_field("count", count_options);
@@ -370,7 +370,7 @@ mod tests {
#[test]
pub fn test_document_to_json() {
let mut schema_builder = SchemaBuilder::default();
let count_options = U64Options::default().set_stored().set_fast();
let count_options = IntOptions::default().set_stored().set_fast();
schema_builder.add_text_field("title", TEXT);
schema_builder.add_text_field("author", STRING);
schema_builder.add_u64_field("count", count_options);
@@ -388,7 +388,7 @@ mod tests {
#[test]
pub fn test_parse_document() {
let mut schema_builder = SchemaBuilder::default();
let count_options = U64Options::default().set_stored().set_fast();
let count_options = IntOptions::default().set_stored().set_fast();
let title_field = schema_builder.add_text_field("title", TEXT);
let author_field = schema_builder.add_text_field("author", STRING);
let count_field = schema_builder.add_u64_field("count", count_options);

View File

@@ -1,109 +0,0 @@
use std::ops::BitOr;
/// Define how a u64 field should be handled by tantivy.
#[derive(Clone,Debug,PartialEq,Eq, RustcDecodable, RustcEncodable)]
pub struct U64Options {
indexed: bool,
fast: bool,
stored: bool,
}
impl U64Options {
/// Returns true iff the value is stored.
pub fn is_stored(&self,) -> bool {
self.stored
}
/// Returns true iff the value is indexed.
pub fn is_indexed(&self,) -> bool {
self.indexed
}
/// Returns true iff the value is a fast field.
pub fn is_fast(&self,) -> bool {
self.fast
}
/// Set the u64 options as stored.
///
/// Only the fields that are set as *stored* are
/// persisted into the Tantivy's store.
pub fn set_stored(mut self,) -> U64Options {
self.stored = true;
self
}
/// Set the u64 options as indexed.
///
/// Setting an integer as indexed will generate
/// a posting list for each value taken by the integer.
pub fn set_indexed(mut self,) -> U64Options {
self.indexed = true;
self
}
/// Set the u64 options as a fast field.
///
/// Fast fields are designed for random access.
/// Access time are similar to a random lookup in an array.
/// If more than one value is associated to a fast field, only the last one is
/// kept.
pub fn set_fast(mut self,) -> U64Options {
self.fast = true;
self
}
}
impl Default for U64Options {
fn default() -> U64Options {
U64Options {
fast: false,
indexed: false,
stored: false,
}
}
}
/// Shortcut for a u64 fast field.
///
/// Such a shortcut can be composed as follows `STORED | FAST | U64_INDEXED`
pub const FAST: U64Options = U64Options {
indexed: false,
stored: false,
fast: true,
};
/// Shortcut for a u64 indexed field.
///
/// Such a shortcut can be composed as follows `STORED | FAST | U64_INDEXED`
pub const U64_INDEXED: U64Options = U64Options {
indexed: true,
stored: false,
fast: false,
};
/// Shortcut for a u64 stored field.
///
/// Such a shortcut can be composed as follows `STORED | FAST | U64_INDEXED`
pub const U64_STORED: U64Options = U64Options {
indexed: false,
stored: true,
fast: false,
};
impl BitOr for U64Options {
type Output = U64Options;
fn bitor(self, other: U64Options) -> U64Options {
let mut res = U64Options::default();
res.indexed = self.indexed | other.indexed;
res.stored = self.stored | other.stored;
res.fast = self.fast | other.fast;
res
}
}