Skip to content

Commit

Permalink
feat: Consider the last query word be a prefix
Browse files Browse the repository at this point in the history
if the last word is not followed by a space.
  • Loading branch information
Kerollmops committed Dec 11, 2018
1 parent 2cbb943 commit f05af4b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/rank/query_builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{mem, vec, str, char};
use std::ops::{Deref, Range};
use std::error::Error;
use std::hash::Hash;
use std::{mem, vec, str};

use group_by::GroupByMut;
use hashbrown::HashMap;
Expand All @@ -16,15 +16,21 @@ use crate::{Match, DocumentId};
use crate::rank::Document;

fn split_whitespace_automatons(query: &str) -> Vec<DfaExt> {
let has_end_whitespace = query.chars().last().map_or(false, char::is_whitespace);
let mut automatons = Vec::new();
let mut words = query.split_whitespace().map(str::to_lowercase).peekable();

while let Some(word) = words.next() {
let lev = match words.peek() {
Some(_) => automaton::build_dfa(&word),
None => automaton::build_prefix_dfa(&word),

let has_following_word = words.peek().is_some();
let lev = if has_following_word || has_end_whitespace {
automaton::build_dfa(&word)
} else {
automaton::build_prefix_dfa(&word)
};
automatons.push(lev);
}

automatons
}

Expand Down

0 comments on commit f05af4b

Please sign in to comment.