Skip to content

Commit

Permalink
issue/230 Add an optional commit message.
Browse files Browse the repository at this point in the history
Closes #230
  • Loading branch information
fulmicoton committed Dec 26, 2017
1 parent 442bc9a commit 7141636
Show file tree
Hide file tree
Showing 7 changed files with 269 additions and 102 deletions.
9 changes: 8 additions & 1 deletion src/core/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use core::SegmentMeta;
use super::pool::LeasedItem;
use std::path::Path;
use core::IndexMeta;
use indexer::DirectoryLock;
use IndexWriter;
use directory::ManagedDirectory;
use core::META_FILEPATH;
Expand Down Expand Up @@ -118,9 +119,14 @@ impl Index {
/// The opstamp is the number of documents that have been added
/// from the beginning of time, and until the moment of the last commit.
pub fn opstamp(&self) -> u64 {
// TODO remove unwrap
load_metas(self.directory()).unwrap().opstamp
}

pub fn load_metas(&self) -> Result<IndexMeta> {
load_metas(self.directory())
}

/// Open a new index writer. Attempts to acquire a lockfile.
///
/// The lockfile should be deleted on drop, but it is possible
Expand All @@ -141,7 +147,8 @@ impl Index {
num_threads: usize,
heap_size_in_bytes: usize,
) -> Result<IndexWriter> {
open_index_writer(self, num_threads, heap_size_in_bytes)
let directory_lock = DirectoryLock::lock(self.directory().box_clone())?;
open_index_writer(self, num_threads, heap_size_in_bytes, directory_lock)
}

/// Creates a multithreaded writer
Expand Down
30 changes: 30 additions & 0 deletions src/core/index_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ pub struct IndexMeta {
pub segments: Vec<SegmentMeta>,
pub schema: Schema,
pub opstamp: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub payload: Option<String>,
}

impl IndexMeta {
Expand All @@ -22,6 +24,34 @@ impl IndexMeta {
segments: vec![],
schema,
opstamp: 0u64,
payload: None,
}
}
}


#[cfg(test)]
mod tests {

use serde_json;
use super::IndexMeta;
use schema::{TEXT, SchemaBuilder};


#[test]
fn test_serialize_metas() {
let schema = {
let mut schema_builder = SchemaBuilder::new();
schema_builder.add_text_field("text", TEXT);
schema_builder.build()
};
let index_metas = IndexMeta {
segments: Vec::new(),
schema: schema,
opstamp: 0u64,
payload: None
};
let json = serde_json::ser::to_string(&index_metas).expect("serialization failed");
assert_eq!(json, r#"{"segments":[],"schema":[{"name":"text","type":"text","options":{"indexing":{"record":"position","tokenizer":"default"},"stored":false}}],"opstamp":0}"#);
}
}

0 comments on commit 7141636

Please sign in to comment.