Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
fulmicoton committed Feb 21, 2018
2 parents 5cfc897 + a4af3a8 commit 771017b
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 89 deletions.
72 changes: 44 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tantivy-cli"
version = "0.4.5"
version = "0.5.0"
authors = ["Paul Masurel <[email protected]>"]

description = """Command line interface for Tantivy, a search engine library."""
Expand Down Expand Up @@ -31,7 +31,7 @@ log = "0.3"
futures = "0.1"
env_logger = "0.3"
version = "2"
tantivy = "0.4.4"
tantivy = "0.5.0"

[[bin]]
name = "tantivy"
Expand All @@ -44,6 +44,7 @@ debug = false
debug-assertions = false
lto = true


[features]
default = ["tantivy/simdcompression"]

20 changes: 10 additions & 10 deletions src/commands/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use std::path::PathBuf;
pub fn run_bench_cli(matches: &ArgMatches) -> Result<(), String> {
let index_path = PathBuf::from(matches.value_of("index").unwrap());
let queries_path = PathBuf::from(matches.value_of("queries").unwrap()); // the unwrap is safe as long as it is comming from the main cli.
let num_repeat = try!(value_t!(matches, "num_repeat", usize).map_err(|e|format!("Failed to read num_repeat argument as an integer. {:?}", e)));
let num_repeat = value_t!(matches, "num_repeat", usize).map_err(|e| format!("Failed to read num_repeat argument as an integer. {:?}", e))?;
run_bench(&index_path, &queries_path, num_repeat).map_err(From::from)
}

Expand All @@ -34,13 +34,11 @@ fn extract_search_fields(schema: &Schema) -> Vec<Field> {
}

fn read_query_file(query_path: &Path) -> io::Result<Vec<String>> {
let query_file: File = try!(File::open(&query_path));
let query_file: File = File::open(&query_path)?;
let file = BufReader::new(&query_file);
let mut queries = Vec::new();
for line_res in file.lines() {
let line = try!(line_res);
let query = String::from(line.trim());
queries.push(query);
queries.push(line_res?);
}
Ok(queries)
}
Expand All @@ -54,11 +52,11 @@ fn run_bench(index_path: &Path,
println!("Query : {:?}", index_path);
println!("-------------------------------\n\n\n");

let index = try!(Index::open(index_path).map_err(|e| format!("Failed to open index.\n{:?}", e)));
let index = Index::open(index_path).map_err(|e| format!("Failed to open index.\n{:?}", e))?;
let searcher = index.searcher();
let default_search_fields: Vec<Field> = extract_search_fields(&index.schema());
let queries = try!(read_query_file(query_filepath).map_err(|e| format!("Failed reading the query file: {}", e)));
let query_parser = QueryParser::new(index.schema(), default_search_fields);
let queries = read_query_file(query_filepath).map_err(|e| format!("Failed reading the query file: {}", e))?;
let query_parser = QueryParser::new(index.schema(), default_search_fields, index.tokenizers().clone());

println!("SEARCH\n");
println!("{}\t{}\t{}\t{}", "query", "num_terms", "num hits", "time in microsecs");
Expand All @@ -71,7 +69,8 @@ fn run_bench(index_path: &Path,
let timing;
{
let mut collector = chain().push(&mut top_collector).push(&mut count_collector);
timing = try!(query.search(&searcher, &mut collector).map_err(|e| format!("Failed while searching query {:?}.\n\n{:?}", query_txt, e)));
timing = query.search(&searcher, &mut collector)
.map_err(|e| format!("Failed while searching query {:?}.\n\n{:?}", query_txt, e))?;
}
println!("{}\t{}\t{}", query_txt, count_collector.count(), timing.total_time());
}
Expand All @@ -84,7 +83,8 @@ fn run_bench(index_path: &Path,
for query_txt in &queries {
let query = query_parser.parse_query(&query_txt).unwrap();
let mut top_collector = TopCollector::with_limit(10);
try!(query.search(&searcher, &mut top_collector).map_err(|e| format!("Failed while retrieving document for query {:?}.\n{:?}", query, e)));
query.search(&searcher, &mut top_collector)
.map_err(|e| format!("Failed while retrieving document for query {:?}.\n{:?}", query, e))?;
let mut timer = TimerTree::default();
{
let _scoped_timer_ = timer.open("total");
Expand Down
Loading

0 comments on commit 771017b

Please sign in to comment.