mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-26 23:04:26 +01:00
set max typos on ngram to 1
This commit is contained in:
parent
38d23546a5
commit
642c01d0dc
@ -260,12 +260,12 @@ fn split_best_frequency(ctx: &impl Context, word: &str) -> heed::Result<Option<O
|
|||||||
|
|
||||||
/// Return the `QueryKind` of a word depending on `authorize_typos`
|
/// Return the `QueryKind` of a word depending on `authorize_typos`
|
||||||
/// and the provided word length.
|
/// and the provided word length.
|
||||||
fn typos(word: String, authorize_typos: bool) -> QueryKind {
|
fn typos(word: String, authorize_typos: bool, max_typos: u8) -> QueryKind {
|
||||||
if authorize_typos {
|
if authorize_typos {
|
||||||
match word.chars().count() {
|
match word.chars().count() {
|
||||||
0..=4 => QueryKind::exact(word),
|
0..=4 => QueryKind::exact(word),
|
||||||
5..=8 => QueryKind::tolerant(1, word),
|
5..=8 => QueryKind::tolerant(1.min(max_typos), word),
|
||||||
_ => QueryKind::tolerant(2, word),
|
_ => QueryKind::tolerant(2.min(max_typos), word),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
QueryKind::exact(word)
|
QueryKind::exact(word)
|
||||||
@ -316,8 +316,10 @@ fn create_query_tree(
|
|||||||
if let Some(child) = split_best_frequency(ctx, &word)? {
|
if let Some(child) = split_best_frequency(ctx, &word)? {
|
||||||
children.push(child);
|
children.push(child);
|
||||||
}
|
}
|
||||||
children
|
children.push(Operation::Query(Query {
|
||||||
.push(Operation::Query(Query { prefix, kind: typos(word, authorize_typos) }));
|
prefix,
|
||||||
|
kind: typos(word, authorize_typos, 2),
|
||||||
|
}));
|
||||||
Ok(Operation::or(false, children))
|
Ok(Operation::or(false, children))
|
||||||
}
|
}
|
||||||
// create a CONSECUTIVE operation wrapping all word in the phrase
|
// create a CONSECUTIVE operation wrapping all word in the phrase
|
||||||
@ -363,8 +365,9 @@ fn create_query_tree(
|
|||||||
.collect();
|
.collect();
|
||||||
let mut operations = synonyms(ctx, &words)?.unwrap_or_default();
|
let mut operations = synonyms(ctx, &words)?.unwrap_or_default();
|
||||||
let concat = words.concat();
|
let concat = words.concat();
|
||||||
let query =
|
let query = Query { prefix: is_prefix, kind: typos(concat, true, 1) };
|
||||||
Query { prefix: is_prefix, kind: typos(concat, authorize_typos) };
|
// let query =
|
||||||
|
// Query { prefix: is_prefix, kind: typos(concat, authorize_typos) };
|
||||||
operations.push(Operation::Query(query));
|
operations.push(Operation::Query(query));
|
||||||
and_op_children.push(Operation::or(false, operations));
|
and_op_children.push(Operation::or(false, operations));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user