mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08:00
fix(facet): string fields sorting
This commit is contained in:
parent
5cbe879325
commit
c2517e7d5f
@ -243,24 +243,27 @@ impl<'t> Iterator for FacetStringGroupRevRange<'t> {
|
|||||||
type Item = heed::Result<((NonZeroU8, u32, u32), (Option<(&'t str, &'t str)>, RoaringBitmap))>;
|
type Item = heed::Result<((NonZeroU8, u32, u32), (Option<(&'t str, &'t str)>, RoaringBitmap))>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
match self.iter.next() {
|
loop {
|
||||||
Some(Ok(((_fid, level, left, right), docids))) => {
|
match self.iter.next() {
|
||||||
let must_be_returned = match self.end {
|
Some(Ok(((_fid, level, left, right), docids))) => {
|
||||||
Included(end) => right <= end,
|
let must_be_returned = match self.end {
|
||||||
Excluded(end) => right < end,
|
Included(end) => right <= end,
|
||||||
Unbounded => true,
|
Excluded(end) => right < end,
|
||||||
};
|
Unbounded => true,
|
||||||
if must_be_returned {
|
};
|
||||||
match docids.decode() {
|
if must_be_returned {
|
||||||
Ok((bounds, docids)) => Some(Ok(((level, left, right), (bounds, docids)))),
|
match docids.decode() {
|
||||||
Err(e) => Some(Err(e)),
|
Ok((bounds, docids)) => {
|
||||||
|
return Some(Ok(((level, left, right), (bounds, docids))))
|
||||||
|
}
|
||||||
|
Err(e) => return Some(Err(e)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
continue;
|
||||||
None
|
|
||||||
}
|
}
|
||||||
|
Some(Err(e)) => return Some(Err(e)),
|
||||||
|
None => return None,
|
||||||
}
|
}
|
||||||
Some(Err(e)) => Some(Err(e)),
|
|
||||||
None => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -545,18 +548,18 @@ impl<'t> Iterator for FacetStringIter<'t> {
|
|||||||
// the algorithm less complex to understand.
|
// the algorithm less complex to understand.
|
||||||
let last = match last {
|
let last = match last {
|
||||||
Left(ascending) => match ascending {
|
Left(ascending) => match ascending {
|
||||||
Left(last) => Left(Left(last)),
|
Left(group) => Left(Left(group)),
|
||||||
Right(last) => Right(Left(last)),
|
Right(zero_level) => Right(Left(zero_level)),
|
||||||
},
|
},
|
||||||
Right(descending) => match descending {
|
Right(descending) => match descending {
|
||||||
Left(last) => Left(Right(last)),
|
Left(group) => Left(Right(group)),
|
||||||
Right(last) => Right(Right(last)),
|
Right(zero_level) => Right(Right(zero_level)),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
match last {
|
match last {
|
||||||
Left(last) => {
|
Left(group) => {
|
||||||
for result in last {
|
for result in group {
|
||||||
match result {
|
match result {
|
||||||
Ok(((level, left, right), (string_bounds, mut docids))) => {
|
Ok(((level, left, right), (string_bounds, mut docids))) => {
|
||||||
docids &= &*documents_ids;
|
docids &= &*documents_ids;
|
||||||
@ -566,6 +569,27 @@ impl<'t> Iterator for FacetStringIter<'t> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let result = if is_ascending {
|
let result = if is_ascending {
|
||||||
|
match string_bounds {
|
||||||
|
Some((left, right)) => FacetStringLevelZeroRange::new(
|
||||||
|
self.rtxn,
|
||||||
|
self.db,
|
||||||
|
self.field_id,
|
||||||
|
Included(left),
|
||||||
|
Included(right),
|
||||||
|
)
|
||||||
|
.map(Right),
|
||||||
|
None => FacetStringGroupRange::new(
|
||||||
|
self.rtxn,
|
||||||
|
self.db,
|
||||||
|
self.field_id,
|
||||||
|
NonZeroU8::new(level.get() - 1).unwrap(),
|
||||||
|
Included(left),
|
||||||
|
Included(right),
|
||||||
|
)
|
||||||
|
.map(Left),
|
||||||
|
}
|
||||||
|
.map(Left)
|
||||||
|
} else {
|
||||||
match string_bounds {
|
match string_bounds {
|
||||||
Some((left, right)) => {
|
Some((left, right)) => {
|
||||||
FacetStringLevelZeroRevRange::new(
|
FacetStringLevelZeroRevRange::new(
|
||||||
@ -588,27 +612,6 @@ impl<'t> Iterator for FacetStringIter<'t> {
|
|||||||
.map(Left),
|
.map(Left),
|
||||||
}
|
}
|
||||||
.map(Right)
|
.map(Right)
|
||||||
} else {
|
|
||||||
match string_bounds {
|
|
||||||
Some((left, right)) => FacetStringLevelZeroRange::new(
|
|
||||||
self.rtxn,
|
|
||||||
self.db,
|
|
||||||
self.field_id,
|
|
||||||
Included(left),
|
|
||||||
Included(right),
|
|
||||||
)
|
|
||||||
.map(Right),
|
|
||||||
None => FacetStringGroupRange::new(
|
|
||||||
self.rtxn,
|
|
||||||
self.db,
|
|
||||||
self.field_id,
|
|
||||||
NonZeroU8::new(level.get() - 1).unwrap(),
|
|
||||||
Included(left),
|
|
||||||
Included(right),
|
|
||||||
)
|
|
||||||
.map(Left),
|
|
||||||
}
|
|
||||||
.map(Left)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match result {
|
match result {
|
||||||
@ -624,9 +627,9 @@ impl<'t> Iterator for FacetStringIter<'t> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Right(last) => {
|
Right(zero_level) => {
|
||||||
// level zero only
|
// level zero only
|
||||||
for result in last {
|
for result in zero_level {
|
||||||
match result {
|
match result {
|
||||||
Ok((normalized, original, mut docids)) => {
|
Ok((normalized, original, mut docids)) => {
|
||||||
docids &= &*documents_ids;
|
docids &= &*documents_ids;
|
||||||
|
Loading…
Reference in New Issue
Block a user