Skip to content

Commit 526b953

Browse files
committed
Rework search document
1 parent f7d7a86 commit 526b953

File tree

4 files changed

+190
-85
lines changed

4 files changed

+190
-85
lines changed

rust-toolchain

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1.88.0

src/index.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,25 @@ impl<DocId: DocumentId> ZeboIndex<DocId> {
179179

180180
Ok(())
181181
}
182+
183+
pub fn get_all_pages(&self) -> Result<Vec<(u64, PageId)>> {
184+
let mut buf = vec![0; (self.offset - 8 - 1) as usize];
185+
self.index_file
186+
.read_exact_at(&mut buf, 9)
187+
.map_err(ZeboError::OperationError)?;
188+
189+
let expected_page_size = (self.offset - 8 - 1) / (8 + 8);
190+
191+
let mut pages = Vec::with_capacity(expected_page_size as usize);
192+
for chunk in buf.chunks_exact(16) {
193+
let page_id = u64::from_be_bytes(chunk[0..8].try_into().unwrap());
194+
let starting_doc_id = u64::from_be_bytes(chunk[8..16].try_into().unwrap());
195+
pages.push((starting_doc_id, PageId(page_id)));
196+
}
197+
198+
Ok(pages)
199+
}
182200
}
183201

184-
#[derive(Debug)]
202+
#[derive(Debug, Clone, Copy)]
185203
pub struct ProbableIndex(pub u64);

src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ impl<const MAX_DOC_PER_PAGE: u32, const PAGE_SIZE: u64, DocId: DocumentId>
313313
Ok(total_count)
314314
}
315315

316+
pub fn get_all_pages(&self) -> Result<Vec<(u64, PageId)>> {
317+
self.index.get_all_pages()
318+
}
319+
316320
/// Returns information related the this Zebo instance
317321
pub fn get_info(&self) -> Result<ZeboInfo> {
318322
let mut page_headers = Vec::with_capacity(self.next_page_id as usize);
@@ -632,6 +636,7 @@ impl DocumentId for u64 {
632636

633637
#[cfg(test)]
634638
mod tests {
639+
635640
use super::*;
636641

637642
pub fn prepare_test_dir() -> PathBuf {

0 commit comments

Comments
 (0)