Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Update http-ui
Browse files Browse the repository at this point in the history
  • Loading branch information
ManyTheFish committed Jun 2, 2022
1 parent 7c6379a commit 10dab35
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions http-ui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use flate2::read::GzDecoder;
use futures::{stream, FutureExt, StreamExt};
use heed::EnvOpenOptions;
use milli::documents::DocumentBatchReader;
use milli::tokenizer::{Analyzer, AnalyzerConfig};
use milli::tokenizer::{Tokenizer, TokenizerBuilder};
use milli::update::UpdateIndexingStep::*;
use milli::update::{
ClearDocuments, IndexDocumentsConfig, IndexDocumentsMethod, IndexerConfig, Setting,
Expand Down Expand Up @@ -139,17 +139,16 @@ pub struct IndexerOpt {
pub max_positions_per_attributes: Option<u32>,
}

struct Highlighter<'a, A> {
analyzer: Analyzer<'a, A>,
struct Highlighter<'s, A> {
tokenizer: Tokenizer<'s, A>,
}

impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
fn new(stop_words: &'a fst::Set<A>) -> Self {
let mut config = AnalyzerConfig::default();
config.stop_words(stop_words);
let analyzer = Analyzer::new(config);
impl<'s, A: AsRef<[u8]>> Highlighter<'s, A> {
fn new(stop_words: &'s fst::Set<A>) -> Self {
let mut builder = TokenizerBuilder::new();
builder.stop_words(stop_words);

Self { analyzer }
Self { tokenizer: builder.build() }
}

fn highlight_value(&self, value: Value, matcher_builder: &MatcherBuilder) -> Value {
Expand All @@ -158,9 +157,8 @@ impl<'a, A: AsRef<[u8]>> Highlighter<'a, A> {
Value::Bool(boolean) => Value::Bool(boolean),
Value::Number(number) => Value::Number(number),
Value::String(old_string) => {
let analyzed = self.analyzer.analyze(&old_string);
let analyzed: Vec<_> = analyzed.tokens().collect();
let mut matcher = matcher_builder.build(&analyzed[..], &old_string);
let tokens: Vec<_> = self.tokenizer.tokenize(&old_string).collect();
let mut matcher = matcher_builder.build(&tokens[..], &old_string);

let format_options = FormatOptions { highlight: true, crop: Some(10) };

Expand Down

0 comments on commit 10dab35

Please sign in to comment.