From 58a0c41a2032e4249d89f90df544abb351903c78 Mon Sep 17 00:00:00 2001 From: Paul Masurel Date: Thu, 2 May 2019 08:55:50 +0900 Subject: [PATCH] Closes #40. Added score to the `serve` output. --- src/commands/serve.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/commands/serve.rs b/src/commands/serve.rs index 7cca7c9..ba3b5d5 100644 --- a/src/commands/serve.rs +++ b/src/commands/serve.rs @@ -34,7 +34,7 @@ use tantivy::schema::FieldType; use tantivy::schema::NamedFieldDocument; use tantivy::schema::Schema; use tantivy::tokenizer::*; -use tantivy::DocAddress; +use tantivy::{DocAddress, Score}; use tantivy::Document; use tantivy::Index; use tantivy::IndexReader; @@ -59,6 +59,7 @@ struct Serp { #[derive(Serialize)] struct Hit { + score: Score, doc: NamedFieldDocument, id: u32, } @@ -103,8 +104,9 @@ impl IndexServer { } } - fn create_hit(&self, doc: &Document, doc_address: &DocAddress) -> Hit { + fn create_hit(&self, score: Score, doc: &Document, doc_address: &DocAddress) -> Hit { Hit { + score, doc: self.schema.to_named_doc(&doc), id: doc_address.doc(), } @@ -125,9 +127,9 @@ impl IndexServer { let _fetching_timer = timer_tree.open("fetching docs"); top_docs .iter() - .map(|(_score, doc_address)| { + .map(|(score, doc_address)| { let doc: Document = searcher.doc(*doc_address).unwrap(); - self.create_hit(&doc, doc_address) + self.create_hit(*score, &doc, doc_address) }) .collect() };