Pass through excerpts from the Tantivy backend
This commit is contained in:
parent
eedf2ed183
commit
39ffdd1f1f
|
@ -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<Range<usize>>,
|
||||
pub tags: Vec<String>,
|
||||
pub url: String,
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue