Simplify getting the biggest level of a facet field

This commit is contained in:
Clément Renault 2020-11-18 16:00:23 +01:00
parent 7d67c9e2e7
commit ced0c29c56
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4

View File

@ -347,25 +347,12 @@ impl<'a> Search<'a> {
.facet_field_id_value_docids .facet_field_id_value_docids
.remap_key_type::<FacetLevelValueI64Codec>(); .remap_key_type::<FacetLevelValueI64Codec>();
let biggest_level = match fid.checked_add(1) { // Ask for the biggest value that can exist for this specific field, if it exists
Some(next_fid) => { // that's fine if it don't, the value just before will be returned instead.
// If we are able to find the next field id we ask the key that is before let biggest_level = db
// the first entry of it which corresponds to the last key of our field id. .remap_data_type::<DecodeIgnore>()
let db = db.remap_data_type::<DecodeIgnore>(); .get_lower_than_or_equal_to(self.rtxn, &(fid, u8::MAX, i64::MAX, i64::MAX))?
match db.get_lower_than(self.rtxn, &(next_fid, 0, i64::MIN, i64::MIN))? { .and_then(|((id, level, _, _), _)| if id == fid { Some(level) } else { None });
Some(((id, level, ..), _)) if fid == id => Some(level),
_ => None,
}
},
None => {
// If we can't generate a bigger field id, it must be equal to 255 and
// therefore the last key of the database must be the one we want.
match db.remap_data_type::<DecodeIgnore>().last(self.rtxn)? {
Some(((id, level, ..), _)) if fid == id => Some(level),
_ => None,
}
},
};
match biggest_level { match biggest_level {
Some(level) => { Some(level) => {