From 39ffdd1f1f52eee24395a158b0629819fc3d8bfb Mon Sep 17 00:00:00 2001 From: Olivier Date: Sat, 26 Mar 2022 17:25:43 +0000 Subject: [PATCH] Pass through excerpts from the Tantivy backend --- quickpeep_index/src/backend.rs | 3 --- quickpeep_index/src/backend/tantivy.rs | 15 +++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/quickpeep_index/src/backend.rs b/quickpeep_index/src/backend.rs index 1e98dac..cf76c01 100644 --- a/quickpeep_index/src/backend.rs +++ b/quickpeep_index/src/backend.rs @@ -1,5 +1,3 @@ -use std::ops::Range; - pub mod meili; pub mod tantivy; @@ -29,7 +27,6 @@ pub struct SearchDocument { pub score: f32, pub title: String, pub excerpt: String, - pub excerpt_highlights: Vec>, pub tags: Vec, pub url: String, } diff --git a/quickpeep_index/src/backend/tantivy.rs b/quickpeep_index/src/backend/tantivy.rs index 4843c4f..e395c93 100644 --- a/quickpeep_index/src/backend/tantivy.rs +++ b/quickpeep_index/src/backend/tantivy.rs @@ -10,7 +10,7 @@ use tantivy::collector::TopDocs; use tantivy::query::QueryParser; use tantivy::schema::{Facet, Field, SchemaBuilder, STORED, TEXT}; use tantivy::tokenizer::TokenizerManager; -use tantivy::{doc, Index, IndexWriter}; +use tantivy::{doc, Index, IndexWriter, SnippetGenerator}; pub struct Fields { title: Field, @@ -174,6 +174,10 @@ impl Backend for TantivyBackend { let results = searcher.search(&query, &TopDocs::with_limit(50))?; let mut out = Vec::with_capacity(results.len()); + let article_snippet_generator = + SnippetGenerator::create(&searcher, &query, self.fields.article)?; + // TODO ? let nonarticle_snippet_generator = SnippetGenerator::create(&searcher, &query, self.fields.article)?; + for (score, doc_address) in results { let doc = searcher.doc(doc_address)?; let url = doc @@ -187,14 +191,13 @@ impl Backend for TantivyBackend { .get(&txn, url.to_owned())? .context("Document row not found in doc store")?; + let snippet = article_snippet_generator.snippet(&doc_row.body); + let excerpt = snippet.to_html(); + out.push(SearchDocument { score, title: doc_row.title, - // TODO - excerpt: "".to_string(), - // TODO - excerpt_highlights: vec![], - // TODO + excerpt, tags: vec![], url: url.to_owned(), })