diff --git a/src/index.rs b/src/index.rs index ab7da0ed5..74105999d 100644 --- a/src/index.rs +++ b/src/index.rs @@ -14,6 +14,7 @@ use crate::{ BoRoaringBitmapCodec, CboRoaringBitmapCodec, }; +pub const DISPLAYED_FIELDS_KEY: &str = "displayed-fields"; 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"; @@ -126,6 +127,24 @@ impl Index { Ok(self.main.get::<_, Str, SerdeJson>(rtxn, FIELDS_IDS_MAP_KEY)?.unwrap_or_default()) } + /// Writes the fields ids that must be displayed in the defined order. + /// There must be not be any duplicate field id. + pub fn put_displayed_fields(&self, wtxn: &mut heed::RwTxn, fields: &[u8]) -> heed::Result<()> { + self.main.put::<_, Str, ByteSlice>(wtxn, DISPLAYED_FIELDS_KEY, fields) + } + + /// Deletes the displayed fields ids, this will make the engine to display + /// all the documents attributes in the order of the `FieldsIdsMap`. + pub fn delete_displayed_fields(&self, wtxn: &mut heed::RwTxn) -> heed::Result { + self.main.delete::<_, Str>(wtxn, DISPLAYED_FIELDS_KEY) + } + + /// Returns the displayed fields ids in the order they must be returned. If it returns + /// `None` it means that all the attributes are displayed in the order of the `FieldsIdsMap`. + pub fn displayed_fields<'t>(&self, rtxn: &'t heed::RoTxn) -> heed::Result> { + self.main.get::<_, Str, ByteSlice>(rtxn, DISPLAYED_FIELDS_KEY) + } + /// Writes the FST which is the words dictionnary of the engine. pub fn put_words_fst>(&self, wtxn: &mut heed::RwTxn, fst: &fst::Set) -> heed::Result<()> { self.main.put::<_, Str, ByteSlice>(wtxn, WORDS_FST_KEY, fst.as_fst().as_bytes())