From 2968ccfc5d3b29a2d455a38131a41bc6bc57e969 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Thu, 13 Jul 2017 20:47:53 +0900 Subject: [PATCH] NOBUG reenabled various commands. --- src/commands/index.rs | 14 +++++++++++++- src/commands/mod.rs | 20 ++++++++++---------- src/commands/search.rs | 5 ++--- src/main.rs | 11 ++++++----- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/src/commands/index.rs b/src/commands/index.rs index 7018bf0..a441306 100644 --- a/src/commands/index.rs +++ b/src/commands/index.rs @@ -50,7 +50,7 @@ fn run_index(directory: PathBuf, } }); - let num_threads_to_parse_json = cmp::max(1, num_threads / 2); + let num_threads_to_parse_json = cmp::max(1, num_threads / 4); info!("Using {} threads to parse json", num_threads_to_parse_json); for _ in 0..num_threads_to_parse_json { let schema_clone = schema.clone(); @@ -84,13 +84,25 @@ fn run_index(directory: PathBuf, index_writer.set_merge_policy(Box::new(NoMergePolicy)); } + let start_overall = PreciseTime::now(); let index_result = index_documents(&mut index_writer, doc_receiver); + { + let duration = start_overall.to(PreciseTime::now()); + info!("Indexing the documents took {} s", duration.num_seconds()); + } + + + match index_result { Ok(docstamp) => { println!("Commit succeed, docstamp at {}", docstamp); println!("Waiting for merging threads"); index_writer.wait_merging_threads()?; println!("Terminated successfully!"); + { + let duration = start_overall.to(PreciseTime::now()); + info!("Indexing the documents took {} overall (indexing + merge)", duration.num_seconds()); + } Ok(()) } Err(e) => { diff --git a/src/commands/mod.rs b/src/commands/mod.rs index ef8c11a..71574bc 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -1,13 +1,13 @@ mod index; -// mod serve; -// mod new; -// mod bench; -// mod merge; -// mod search; +mod serve; +mod new; +mod bench; +mod merge; +mod search; -// pub use self::new::run_new_cli; +pub use self::new::run_new_cli; pub use self::index::run_index_cli; -// pub use self::serve::run_serve_cli; -// pub use self::bench::run_bench_cli; -// pub use self::merge::run_merge_cli; -// pub use self::search::run_search_cli; \ No newline at end of file +pub use self::serve::run_serve_cli; +pub use self::search::run_search_cli; +pub use self::bench::run_bench_cli; +pub use self::merge::run_merge_cli; diff --git a/src/commands/search.rs b/src/commands/search.rs index 8080ae7..882c15d 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -12,9 +12,8 @@ use tantivy::schema::FieldType; pub fn run_search_cli(matches: &ArgMatches) -> Result<(), String> { let index_directory = PathBuf::from(matches.value_of("index").unwrap()); let query = matches.value_of("query").unwrap(); - loop { - run_search(&index_directory, &query).map_err(|e| format!("{:?}", e)) - } + run_search(&index_directory, &query) + .map_err(|e| format!("{:?}", e)) } fn run_search(directory: &Path, query: &str) -> tantivy::Result<()> { diff --git a/src/main.rs b/src/main.rs index 7e88122..46c3c3c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,6 +22,7 @@ extern crate byteorder; #[macro_use] extern crate serde_derive; + use clap::{AppSettings, Arg, App, SubCommand}; mod commands; use self::commands::*; @@ -128,12 +129,12 @@ fn main() { let (subcommand, some_options) = cli_options.subcommand(); let options = some_options.unwrap(); let run_cli = match subcommand { - // "new" => run_new_cli, + "new" => run_new_cli, "index" => run_index_cli, - // "serve" => run_serve_cli, - // "search" => run_search_cli, - // "merge" => run_merge_cli, - // "bench" => run_bench_cli, + "serve" => run_serve_cli, + "search" => run_search_cli, + "merge" => run_merge_cli, + "bench" => run_bench_cli, _ => panic!("Subcommand {} is unknown", subcommand) }; run_cli(options).unwrap();