fix split_query_string

This commit is contained in:
mpostma 2020-11-26 20:19:15 +01:00 committed by many
parent c6434f609c
commit b574960755
No known key found for this signature in database
GPG Key ID: 2CEF23B75189EACA
3 changed files with 6 additions and 22 deletions

View File

@ -882,6 +882,7 @@ mod tests {
// even try to search for a document
let reader = db.main_read_txn().unwrap();
println!("here");
let SortResult {documents, .. } = index.query_builder().query(&reader, Some("21 "), 0..20).unwrap();
assert_matches!(documents.len(), 1);

View File

@ -181,26 +181,9 @@ fn split_query_string<'a, A: AsRef<[u8]>>(s: &str, stop_words: &'a fst::Set<A>)
analyzer
.analyze(s)
.tokens()
.scan((0, false), |(offset, is_hard_sep), mut token| {
match token.kind {
TokenKind::Word | TokenKind::StopWord | TokenKind::Any => {
if *is_hard_sep {
*offset += 8;
} else {
*offset += 1;
}
*is_hard_sep = false;
token.char_index += *offset;
}
TokenKind::Separator(SeparatorKind::Hard) => {
*is_hard_sep = true;
}
_ => (),
}
Some((*offset, token))
})
.filter(|(_, t)| t.is_word())
.map(|(i, Token { word, .. })| (i, word.to_string()))
.filter(|t| t.is_word())
.map(| Token { word, .. }| word.to_string())
.enumerate()
.collect()
}

View File

@ -55,13 +55,13 @@ where
.scan((0, false), |(offset, is_hard_sep), mut token| {
match token.kind {
TokenKind::Word => {
token.char_index += *offset;
if *is_hard_sep {
*offset += 8;
} else {
*offset += 1;
}
*is_hard_sep = false;
token.char_index += *offset;
}
TokenKind::Separator(SeparatorKind::Hard) => {
*is_hard_sep = true;
@ -110,13 +110,13 @@ where
.scan((0, false), |(offset, is_hard_sep), mut token| {
match token.kind {
TokenKind::Word | TokenKind::StopWord | TokenKind::Any => {
token.char_index += *offset;
if *is_hard_sep {
*offset += 8;
} else {
*offset += 1;
}
*is_hard_sep = false;
token.char_index += *offset;
}
TokenKind::Separator(SeparatorKind::Hard) => {
*is_hard_sep = true;