mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-23 05:14:27 +01:00
Introduce primary key methods on the index
This commit is contained in:
parent
0d01e4854b
commit
ddbd336387
20
src/index.rs
20
src/index.rs
@ -14,10 +14,11 @@ use crate::{
|
||||
BoRoaringBitmapCodec, CboRoaringBitmapCodec,
|
||||
};
|
||||
|
||||
pub const WORDS_FST_KEY: &str = "words-fst";
|
||||
pub const FIELDS_IDS_MAP_KEY: &str = "fields-ids-map";
|
||||
pub const DOCUMENTS_IDS_KEY: &str = "documents-ids";
|
||||
pub const FIELDS_IDS_MAP_KEY: &str = "fields-ids-map";
|
||||
pub const PRIMARY_KEY_KEY: &str = "primary-key";
|
||||
pub const USERS_IDS_DOCUMENTS_IDS_KEY: &str = "users-ids-documents-ids";
|
||||
pub const WORDS_FST_KEY: &str = "words-fst";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Index {
|
||||
@ -83,6 +84,21 @@ impl Index {
|
||||
Ok(self.main.get::<_, Str, RoaringBitmapCodec>(rtxn, DOCUMENTS_IDS_KEY)?.unwrap_or_default())
|
||||
}
|
||||
|
||||
/// Writes the documents primary key, this is the field name that is used to store the id.
|
||||
pub fn put_primary_key(&self, wtxn: &mut heed::RwTxn, primary_key: u8) -> heed::Result<()> {
|
||||
self.main.put::<_, Str, OwnedType<u8>>(wtxn, PRIMARY_KEY_KEY, &primary_key)
|
||||
}
|
||||
|
||||
/// Delete the primary key of the documents, this can be done to reset indexes settings.
|
||||
pub fn delete_primary_key(&self, wtxn: &mut heed::RwTxn) -> heed::Result<bool> {
|
||||
self.main.delete::<_, Str>(wtxn, PRIMARY_KEY_KEY)
|
||||
}
|
||||
|
||||
/// Returns the documents primary key, `None` if it hasn't been defined.
|
||||
pub fn primary_key(&self, rtxn: &heed::RoTxn) -> heed::Result<Option<u8>> {
|
||||
self.main.get::<_, Str, OwnedType<u8>>(rtxn, PRIMARY_KEY_KEY)
|
||||
}
|
||||
|
||||
/// Writes the users ids documents ids, a user id is a byte slice (i.e. `[u8]`)
|
||||
/// and refers to an internal id (i.e. `u32`).
|
||||
pub fn put_users_ids_documents_ids<A: AsRef<[u8]>>(&self, wtxn: &mut heed::RwTxn, fst: &fst::Map<A>) -> heed::Result<()> {
|
||||
|
Loading…
Reference in New Issue
Block a user