issue/77 Added managed directory

This commit is contained in:
Paul Masurel
2017-03-03 22:41:30 +09:00
parent 590a8582c9
commit 4b7afa2ae7
13 changed files with 168 additions and 124 deletions

View File

@@ -1,4 +1,6 @@
use core::SegmentId;
use super::SegmentComponent;
use std::path::PathBuf;
#[derive(Clone, Debug, RustcDecodable,RustcEncodable)]
@@ -43,6 +45,35 @@ impl SegmentMeta {
.unwrap_or(0u32)
}
pub fn alive_files(&self) -> Vec<PathBuf> {
SegmentComponent::iterator()
.map(|component| {
self.relative_path(*component)
})
.collect::<Vec<PathBuf>>()
}
/// Returns the relative path of a component of our segment.
///
/// It just joins the segment id with the extension
/// associated to a segment component.
pub fn relative_path(&self, component: SegmentComponent) -> PathBuf {
use self::SegmentComponent::*;
let mut path = self.id().uuid_string();
path.push_str(&*match component {
POSITIONS => ".pos".to_string(),
INFO => ".info".to_string(),
POSTINGS => ".idx".to_string(),
TERMS => ".term".to_string(),
STORE => ".store".to_string(),
FASTFIELDS => ".fast".to_string(),
FIELDNORMS => ".fieldnorm".to_string(),
DELETE => {format!(".{}.del", self.delete_opstamp().unwrap_or(0))},
});
PathBuf::from(path)
}
/// Return the highest doc id + 1
///
/// If there are no deletes, then num_docs = max_docs