mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-30 00:34:26 +01:00
Support the typoTolerant.enabled parameter
This commit is contained in:
parent
8e86eb91bb
commit
7bd67543dd
@ -283,6 +283,7 @@ impl<'a> SearchForFacetValues<'a> {
|
|||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let fst = match self.search_query.index.facet_id_string_fst.get(rtxn, &BEU16::new(fid))? {
|
let fst = match self.search_query.index.facet_id_string_fst.get(rtxn, &BEU16::new(fid))? {
|
||||||
Some(fst) => fst,
|
Some(fst) => fst,
|
||||||
None => return Ok(vec![]),
|
None => return Ok(vec![]),
|
||||||
@ -292,37 +293,69 @@ impl<'a> SearchForFacetValues<'a> {
|
|||||||
|
|
||||||
match self.query.as_ref() {
|
match self.query.as_ref() {
|
||||||
Some(query) => {
|
Some(query) => {
|
||||||
let is_prefix = true;
|
if self.search_query.index.authorize_typos(rtxn)? {
|
||||||
let starts = StartsWith(Str::new(get_first(query)));
|
let is_prefix = true;
|
||||||
let first = Intersection(build_dfa(query, 1, is_prefix), Complement(&starts));
|
let starts = StartsWith(Str::new(get_first(query)));
|
||||||
let second_dfa = build_dfa(query, 2, is_prefix);
|
let first = Intersection(build_dfa(query, 1, is_prefix), Complement(&starts));
|
||||||
let second = Intersection(&second_dfa, &starts);
|
let second_dfa = build_dfa(query, 2, is_prefix);
|
||||||
let automaton = Union(first, &second);
|
let second = Intersection(&second_dfa, &starts);
|
||||||
|
let automaton = Union(first, &second);
|
||||||
|
|
||||||
let mut stream = fst.search(automaton).into_stream();
|
let mut stream = fst.search(automaton).into_stream();
|
||||||
let mut result = vec![];
|
let mut result = vec![];
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
while let Some(facet_value) = stream.next() {
|
while let Some(facet_value) = stream.next() {
|
||||||
let value = std::str::from_utf8(facet_value)?;
|
let value = std::str::from_utf8(facet_value)?;
|
||||||
let key = FacetGroupKey { field_id: fid, level: 0, left_bound: value };
|
let key = FacetGroupKey { field_id: fid, level: 0, left_bound: value };
|
||||||
let docids = match index.facet_id_string_docids.get(rtxn, &key)? {
|
let docids = match index.facet_id_string_docids.get(rtxn, &key)? {
|
||||||
Some(FacetGroupValue { bitmap, .. }) => bitmap,
|
Some(FacetGroupValue { bitmap, .. }) => bitmap,
|
||||||
None => {
|
None => {
|
||||||
error!("the facet value is missing from the facet database: {key:?}");
|
error!(
|
||||||
continue;
|
"the facet value is missing from the facet database: {key:?}"
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let count = search_candidates.intersection_len(&docids);
|
||||||
|
if count != 0 {
|
||||||
|
result.push(FacetValueHit { value: value.to_string(), count });
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
if length >= MAX_NUMBER_OF_FACETS {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
let count = search_candidates.intersection_len(&docids);
|
|
||||||
if count != 0 {
|
|
||||||
result.push(FacetValueHit { value: value.to_string(), count });
|
|
||||||
length += 1;
|
|
||||||
}
|
}
|
||||||
if length >= MAX_NUMBER_OF_FACETS {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result)
|
Ok(result)
|
||||||
|
} else {
|
||||||
|
let automaton = StartsWith(Str::new(query));
|
||||||
|
let mut stream = fst.search(automaton).into_stream();
|
||||||
|
let mut result = vec![];
|
||||||
|
let mut length = 0;
|
||||||
|
while let Some(facet_value) = stream.next() {
|
||||||
|
let value = std::str::from_utf8(facet_value)?;
|
||||||
|
let key = FacetGroupKey { field_id: fid, level: 0, left_bound: value };
|
||||||
|
let docids = match index.facet_id_string_docids.get(rtxn, &key)? {
|
||||||
|
Some(FacetGroupValue { bitmap, .. }) => bitmap,
|
||||||
|
None => {
|
||||||
|
error!(
|
||||||
|
"the facet value is missing from the facet database: {key:?}"
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let count = search_candidates.intersection_len(&docids);
|
||||||
|
if count != 0 {
|
||||||
|
result.push(FacetValueHit { value: value.to_string(), count });
|
||||||
|
length += 1;
|
||||||
|
}
|
||||||
|
if length >= MAX_NUMBER_OF_FACETS {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let mut stream = fst.stream();
|
let mut stream = fst.stream();
|
||||||
|
Loading…
Reference in New Issue
Block a user