From 95c8ad0f80c602f34ba1d9bef6e38884dc5d03c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 31 Oct 2019 16:15:07 +0100 Subject: [PATCH] Allow users to specify the index name to use with examples bins --- meilidb-core/examples/from_file.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/meilidb-core/examples/from_file.rs b/meilidb-core/examples/from_file.rs index a6b20da0f..49f1f2657 100644 --- a/meilidb-core/examples/from_file.rs +++ b/meilidb-core/examples/from_file.rs @@ -15,14 +15,15 @@ use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; use meilidb_core::{Database, Highlight, ProcessedUpdateResult}; use meilidb_schema::SchemaAttr; -const INDEX_NAME: &str = "default"; - #[derive(Debug, StructOpt)] struct IndexCommand { /// The destination where the database must be created. #[structopt(parse(from_os_str))] database_path: PathBuf, + #[structopt(long, default_value = "default")] + index_name: String, + /// The csv file to index. #[structopt(parse(from_os_str))] csv_data_path: PathBuf, @@ -44,6 +45,9 @@ struct SearchCommand { #[structopt(parse(from_os_str))] database_path: PathBuf, + #[structopt(long, default_value = "default")] + index_name: String, + /// Timeout after which the search will return results. #[structopt(long)] fetch_timeout_ms: Option, @@ -70,6 +74,9 @@ struct ShowUpdatesCommand { /// The path of the database to work with. #[structopt(parse(from_os_str))] database_path: PathBuf, + + #[structopt(long, default_value = "default")] + index_name: String, } #[derive(Debug, StructOpt)] @@ -98,12 +105,12 @@ fn index_command(command: IndexCommand, database: Database) -> Result<(), Box index, - None => database.create_index(INDEX_NAME).unwrap(), + None => database.create_index(&command.index_name).unwrap(), }; - let done = database.set_update_callback(INDEX_NAME, Box::new(update_fn)); + let done = database.set_update_callback(&command.index_name, Box::new(update_fn)); assert!(done, "could not set the index update function"); let env = &database.env; @@ -306,7 +313,7 @@ fn crop_text( fn search_command(command: SearchCommand, database: Database) -> Result<(), Box> { let env = &database.env; let index = database - .open_index(INDEX_NAME) + .open_index(&command.index_name) .expect("Could not find index"); let reader = env.read_txn().unwrap(); @@ -429,12 +436,12 @@ fn search_command(command: SearchCommand, database: Database) -> Result<(), Box< } fn show_updates_command( - _command: ShowUpdatesCommand, + command: ShowUpdatesCommand, database: Database, ) -> Result<(), Box> { let env = &database.env; let index = database - .open_index(INDEX_NAME) + .open_index(&command.index_name) .expect("Could not find index"); let reader = env.read_txn().unwrap();