use crate::bridge::scan_filter::ScanFilter;
use crate::data::executor::core_loop::CoreLoop;
impl CoreLoop {
pub(in crate::data::executor) fn scan_matching_documents(
&self,
database_id: u64,
tid: u64,
collection: &str,
filters: &[ScanFilter],
) -> crate::Result<Vec<String>> {
let prefix = crate::engine::sparse::btree::coll_prefix(database_id, tid, collection);
let end = format!("{prefix}\u{ffff}");
let read_txn = self
.sparse
.db()
.begin_read()
.map_err(|e| crate::Error::Storage {
engine: "sparse".into(),
detail: format!("read txn: {e}"),
})?;
let table = read_txn
.open_table(crate::engine::sparse::btree::DOCUMENTS)
.map_err(|e| crate::Error::Storage {
engine: "sparse".into(),
detail: format!("open table: {e}"),
})?;
let matches = self.strict_aware_matcher(database_id, tid, collection, filters);
let mut ids = Vec::new();
if let Ok(range) = table.range(prefix.as_str()..end.as_str()) {
for entry in range.flatten() {
let key = entry.0.value();
let value_bytes = entry.1.value();
if matches(value_bytes)
&& let Some(doc_id) = key.strip_prefix(&prefix)
{
ids.push(doc_id.to_string());
}
}
}
Ok(ids)
}
}
pub(in crate::data::executor) fn ollp_predicted_doc_ids(predicted: &[u32]) -> Vec<String> {
let mut surrogates: Vec<u32> = predicted.to_vec();
surrogates.sort_unstable();
surrogates
.into_iter()
.map(|s| {
crate::engine::document::store::surrogate_to_doc_id(nodedb_types::Surrogate::new(s))
})
.collect()
}
pub(in crate::data::executor) fn ollp_actual_surrogates(doc_ids: &[String]) -> Vec<u32> {
let mut surrogates: Vec<u32> = doc_ids
.iter()
.filter_map(|id| {
if id.len() == 8 {
u32::from_str_radix(id, 16).ok()
} else {
None
}
})
.collect();
surrogates.sort_unstable();
surrogates
}
pub(in crate::data::executor) fn ollp_surrogates_match(
matching_ids: &[String],
predicted: &[u32],
) -> bool {
let actual = ollp_actual_surrogates(matching_ids);
let mut predicted_sorted: Vec<u32> = predicted.to_vec();
predicted_sorted.sort_unstable();
actual == predicted_sorted
}
pub(in crate::data::executor) fn ollp_edges_match(
mut actual: Vec<nodedb_physical::physical_plan::OllpPredictedEdge>,
predicted: &[nodedb_physical::physical_plan::OllpPredictedEdge],
) -> bool {
actual.sort_unstable();
let mut predicted_sorted = predicted.to_vec();
predicted_sorted.sort_unstable();
actual == predicted_sorted
}