Update http-ui

This commit is contained in:
ManyTheFish 2022-06-02 15:55:26 +02:00
parent 86ac8568e6
commit 4dd3675d2b

View File

@ -19,7 +19,7 @@ use flate2::read::GzDecoder;
use futures::{stream, FutureExt, StreamExt}; use futures::{stream, FutureExt, StreamExt};
use heed::EnvOpenOptions; use heed::EnvOpenOptions;
use milli::documents::DocumentBatchReader; use milli::documents::DocumentBatchReader;
use milli::tokenizer::{Analyzer, AnalyzerConfig}; use milli::tokenizer::{Tokenizer, TokenizerBuilder};
use milli::update::UpdateIndexingStep::*; use milli::update::UpdateIndexingStep::*;
use milli::update::{ use milli::update::{
ClearDocuments, IndexDocumentsConfig, IndexDocumentsMethod, IndexerConfig, Setting, ClearDocuments, IndexDocumentsConfig, IndexDocumentsMethod, IndexerConfig, Setting,
@ -139,17 +139,16 @@ pub struct IndexerOpt {
pub max_positions_per_attributes: Option<u32>, pub max_positions_per_attributes: Option<u32>,
} }
struct Highlighter<'a, A> { struct Highlighter<'s, A> {
analyzer: Analyzer<'a, A>, tokenizer: Tokenizer<'s, A>,
} }
impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> { impl<'s, A: AsRef<[u8]>> Highlighter<'s, A> {
fn new(stop_words: &'a fst::Set<A>) -> Self { fn new(stop_words: &'s fst::Set<A>) -> Self {
let mut config = AnalyzerConfig::default(); let mut builder = TokenizerBuilder::new();
config.stop_words(stop_words); builder.stop_words(stop_words);
let analyzer = Analyzer::new(config);
Self { analyzer } Self { tokenizer: builder.build() }
} }
fn highlight_value(&self, value: Value, matcher_builder: &MatcherBuilder) -> Value { fn highlight_value(&self, value: Value, matcher_builder: &MatcherBuilder) -> Value {
@ -158,9 +157,8 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
Value::Bool(boolean) => Value::Bool(boolean), Value::Bool(boolean) => Value::Bool(boolean),
Value::Number(number) => Value::Number(number), Value::Number(number) => Value::Number(number),
Value::String(old_string) => { Value::String(old_string) => {
let analyzed = self.analyzer.analyze(&old_string); let tokens: Vec<_> = self.tokenizer.tokenize(&old_string).collect();
let analyzed: Vec<_> = analyzed.tokens().collect(); let mut matcher = matcher_builder.build(&tokens[..], &old_string);
let mut matcher = matcher_builder.build(&analyzed[..], &old_string);
let format_options = FormatOptions { highlight: true, crop: Some(10) }; let format_options = FormatOptions { highlight: true, crop: Some(10) };