Browse Source

NOBUG updating tantivy

develop
Paul Masurel 7 years ago
parent
commit
c0cb01a919
3 changed files with 7 additions and 18 deletions
  1. +2
    -3
      src/commands/bench.rs
  2. +2
    -1
      src/commands/new.rs
  3. +3
    -14
      src/commands/serve.rs

+ 2
- 3
src/commands/bench.rs View File

@@ -1,7 +1,6 @@
use tantivy::Index;
use tantivy::schema::{Field, Schema};
use tantivy::query::QueryParser;
use tantivy::query::Query;
use std::path::Path;
use tantivy::TimerTree;
use std::io::BufReader;
@@ -67,7 +66,7 @@ fn run_bench(index_path: &Path,
for _ in 0..num_repeat {
for query_txt in &queries {
let query = query_parser.parse_query(&query_txt).unwrap();
let num_terms = query.num_terms();
// let num_terms = query.num_terms();
let mut top_collector = TopCollector::with_limit(10);
let mut count_collector = CountCollector::default();
let timing;
@@ -75,7 +74,7 @@ fn run_bench(index_path: &Path,
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)));
}
println!("{}\t{}\t{}\t{}", query_txt, num_terms, count_collector.count(), timing.total_time());
println!("{}\t{}\t{}", query_txt, count_collector.count(), timing.total_time());
}
}


+ 2
- 1
src/commands/new.rs View File

@@ -144,6 +144,7 @@ fn run_new(directory: PathBuf) -> tantivy::Result<()> {
let schema_json = format!("{}", json::as_pretty_json(&schema));
println!("\n{}\n", Style::new().fg(Green).paint(schema_json));
let mut index = try!(Index::create(&directory, schema));
index.save_metas()
// index.save_metas()
Ok(())
}


+ 3
- 14
src/commands/serve.rs View File

@@ -35,8 +35,6 @@ use tantivy::collector::CountCollector;
use tantivy::collector::TopCollector;
use tantivy::Document;
use tantivy::Index;
use tantivy::query::Explanation;
use tantivy::query::Query;
use tantivy::query::QueryParser;
use tantivy::schema::Field;
use tantivy::schema::FieldType;
@@ -65,7 +63,6 @@ struct Serp {
#[derive(RustcEncodable)]
struct Hit {
doc: NamedFieldDocument,
explain: Option<Explanation>,
}

struct IndexServer {
@@ -101,10 +98,9 @@ impl IndexServer {
}
}

fn create_hit(&self, doc: &Document, explain: Option<Explanation>) -> Hit {
fn create_hit(&self, doc: &Document) -> Hit {
Hit {
doc: self.schema.to_named_doc(&doc),
explain: explain,
doc: self.schema.to_named_doc(&doc)
}
}
@@ -127,14 +123,7 @@ impl IndexServer {
.iter()
.map(|doc_address| {
let doc: Document = searcher.doc(doc_address).unwrap();
let explanation;
if explain {
explanation = Some(query.explain(&searcher, doc_address).unwrap());
}
else {
explanation = None;
}
self.create_hit(&doc, explanation)
self.create_hit(&doc)
})
.collect()
};


Loading…
Cancel
Save