Incremental caching - tests passing
This commit is contained in:
@@ -50,6 +50,7 @@ pub enum Filter {
|
||||
pub enum Comparator {
|
||||
Field { field: u8, ascending: bool },
|
||||
DocumentSet { set: RoaringBitmap, ascending: bool },
|
||||
SortedList { list: Vec<u32>, ascending: bool },
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -176,6 +177,10 @@ impl Comparator {
|
||||
Self::DocumentSet { set, ascending }
|
||||
}
|
||||
|
||||
pub fn sorted_list(list: Vec<u32>, ascending: bool) -> Self {
|
||||
Self::SortedList { list, ascending }
|
||||
}
|
||||
|
||||
pub fn ascending(field: impl Into<u8>) -> Self {
|
||||
Self::Field {
|
||||
field: field.into(),
|
||||
|
||||
@@ -13,6 +13,7 @@ use crate::{IndexKeyPrefix, IterateParams, Store, U32_LEN, write::key::Deseriali
|
||||
|
||||
use super::{Comparator, ResultSet, SortedResultSet};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Pagination<'x> {
|
||||
requested_position: i32,
|
||||
position: i32,
|
||||
@@ -99,6 +100,25 @@ impl Store {
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator::SortedList { list, ascending } => {
|
||||
if ascending {
|
||||
for document_id in list {
|
||||
if result_set.results.contains(document_id)
|
||||
&& !paginate.add(0, document_id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for document_id in list.into_iter().rev() {
|
||||
if result_set.results.contains(document_id)
|
||||
&& !paginate.add(0, document_id)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Obtain prefixes
|
||||
@@ -195,6 +215,23 @@ impl Store {
|
||||
}
|
||||
}
|
||||
}
|
||||
Comparator::SortedList { list, ascending } => {
|
||||
if ascending {
|
||||
for (idx, document_id) in list.into_iter().enumerate() {
|
||||
if result_set.results.contains(document_id) {
|
||||
sorted_ids.entry(document_id).or_insert([0u32; 4])[pos] =
|
||||
idx as u32;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (idx, document_id) in list.into_iter().rev().enumerate() {
|
||||
if result_set.results.contains(document_id) {
|
||||
sorted_ids.entry(document_id).or_insert([0u32; 4])[pos] =
|
||||
idx as u32;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user