Browse Source

NOBUG updating tantivy

develop
Paul Masurel 8 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::Index;
use tantivy::schema::{Field, Schema}; use tantivy::schema::{Field, Schema};
use tantivy::query::QueryParser; use tantivy::query::QueryParser;
use tantivy::query::Query;
use std::path::Path; use std::path::Path;
use tantivy::TimerTree; use tantivy::TimerTree;
use std::io::BufReader; use std::io::BufReader;
@@ -67,7 +66,7 @@ fn run_bench(index_path: &Path,
for _ in 0..num_repeat { for _ in 0..num_repeat {
for query_txt in &queries { for query_txt in &queries {
let query = query_parser.parse_query(&query_txt).unwrap(); 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 top_collector = TopCollector::with_limit(10);
let mut count_collector = CountCollector::default(); let mut count_collector = CountCollector::default();
let timing; let timing;
@@ -75,7 +74,7 @@ fn run_bench(index_path: &Path,
let mut collector = chain().push(&mut top_collector).push(&mut count_collector); 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 = 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)); let schema_json = format!("{}", json::as_pretty_json(&schema));
println!("\n{}\n", Style::new().fg(Green).paint(schema_json)); println!("\n{}\n", Style::new().fg(Green).paint(schema_json));
let mut index = try!(Index::create(&directory, schema)); 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::collector::TopCollector;
use tantivy::Document; use tantivy::Document;
use tantivy::Index; use tantivy::Index;
use tantivy::query::Explanation;
use tantivy::query::Query;
use tantivy::query::QueryParser; use tantivy::query::QueryParser;
use tantivy::schema::Field; use tantivy::schema::Field;
use tantivy::schema::FieldType; use tantivy::schema::FieldType;
@@ -65,7 +63,6 @@ struct Serp {
#[derive(RustcEncodable)] #[derive(RustcEncodable)]
struct Hit { struct Hit {
doc: NamedFieldDocument, doc: NamedFieldDocument,
explain: Option<Explanation>,
} }


struct IndexServer { 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 { Hit {
doc: self.schema.to_named_doc(&doc),
explain: explain,
doc: self.schema.to_named_doc(&doc)
} }
} }
@@ -127,14 +123,7 @@ impl IndexServer {
.iter() .iter()
.map(|doc_address| { .map(|doc_address| {
let doc: Document = searcher.doc(doc_address).unwrap(); 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() .collect()
}; };


Loading…
Cancel
Save