From 360f4132eb72f0707a286957b8ff5e4e7694f565 Mon Sep 17 00:00:00 2001 From: Dru Sellers Date: Thu, 14 Jun 2018 22:16:41 -0500 Subject: [PATCH] Standardizes the Index::open_* APIs (#318) * Relocate `from_directory` closer to its usage * Specific methods come before the generic method * Rename open methods to follow the lead of the create methods --- src/core/index.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/core/index.rs b/src/core/index.rs index 4842152c7..fcc700a02 100644 --- a/src/core/index.rs +++ b/src/core/index.rs @@ -45,13 +45,6 @@ pub struct Index { } impl Index { - /// Create a new index from a directory. - fn from_directory(mut directory: ManagedDirectory, schema: Schema) -> Result { - save_new_metas(schema.clone(), 0, directory.borrow_mut())?; - let metas = IndexMeta::with_schema(schema); - Index::create_from_metas(directory, &metas) - } - /// Creates a new index using the `RAMDirectory`. /// /// The index will be allocated in anonymous memory. @@ -91,6 +84,13 @@ impl Index { Index::from_directory(directory, schema) } + /// Create a new index from a directory. + fn from_directory(mut directory: ManagedDirectory, schema: Schema) -> Result { + save_new_metas(schema.clone(), 0, directory.borrow_mut())?; + let metas = IndexMeta::with_schema(schema); + Index::create_from_metas(directory, &metas) + } + /// Creates a new index given a directory and an `IndexMeta`. fn create_from_metas(directory: ManagedDirectory, metas: &IndexMeta) -> Result { let schema = metas.schema.clone(); @@ -109,20 +109,20 @@ impl Index { &self.tokenizers } + /// Opens a new directory from an index path. + #[cfg(feature = "mmap")] + pub fn open_in_dir>(directory_path: P) -> Result { + let mmap_directory = MmapDirectory::open(directory_path)?; + Index::open(mmap_directory) + } + /// Open the index using the provided directory - pub fn open_directory(directory: D) -> Result { + pub fn open(directory: D) -> Result { let directory = ManagedDirectory::new(directory)?; let metas = load_metas(&directory)?; Index::create_from_metas(directory, &metas) } - /// Opens a new directory from an index path. - #[cfg(feature = "mmap")] - pub fn open>(directory_path: P) -> Result { - let mmap_directory = MmapDirectory::open(directory_path)?; - Index::open_directory(mmap_directory) - } - /// Reads the index meta file from the directory. pub fn load_metas(&self) -> Result { load_metas(self.directory())