Skip to content

Commit

Permalink
Merge pull request #78 from meilisearch/expose-the-known-universe
Browse files Browse the repository at this point in the history
Add a method on reader to get all the item ids
  • Loading branch information
Kerollmops committed Jun 20, 2024
2 parents 8aaeae7 + 4b43f6d commit 67e74b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ impl<'t, D: Distance> Reader<'t, D> {
self.items.len()
}

/// Returns all the item ids contained in this index.
pub fn item_ids(&self) -> &RoaringBitmap {
&self.items
}

/// Returns the index of this reader in the database.
pub fn index(&self) -> u16 {
self.index
Expand Down
17 changes: 17 additions & 0 deletions src/tests/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,23 @@ fn two_dimension_on_a_column() {
"###);
}

#[test]
fn get_item_ids() {
let handle = create_database();
let mut wtxn = handle.env.write_txn().unwrap();
let writer = Writer::new(handle.database, 0, 2);
for i in 0..10 {
writer.add_item(&mut wtxn, i, &[0.0, i as f32]).unwrap();
}

writer.build(&mut wtxn, &mut rng(), Some(50)).unwrap();

let reader = Reader::<Euclidean>::open(&wtxn, 0, handle.database).unwrap();
let ret = reader.item_ids();

insta::assert_debug_snapshot!(ret, @"RoaringBitmap<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>");
}

#[test]
fn filtering() {
let handle = create_database();
Expand Down

0 comments on commit 67e74b8

Please sign in to comment.