mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-09-11 15:16:35 +00:00
feat: add a method to get an iterator over all documents ids
This commit is contained in:
@ -55,6 +55,11 @@ impl DocumentsIndex {
|
||||
Ok(DocumentFieldsIter(iter))
|
||||
}
|
||||
|
||||
pub fn documents_ids(&self) -> RocksDbResult<DocumentsIdsIter> {
|
||||
let iter = DocumentsKeysIter(self.0.iter()?);
|
||||
Ok(DocumentsIdsIter { inner: iter, last: None })
|
||||
}
|
||||
|
||||
pub fn documents_fields_repartition(&self, schema: Schema) -> RocksDbResult<HashMap<String, u64>> {
|
||||
let iter = self.0.iter()?;
|
||||
let mut repartition_attributes_id = HashMap::new();
|
||||
@ -120,3 +125,22 @@ impl Iterator for DocumentsKeysIter<'_> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DocumentsIdsIter<'a> {
|
||||
inner: DocumentsKeysIter<'a>,
|
||||
last: Option<DocumentId>,
|
||||
}
|
||||
|
||||
impl Iterator for DocumentsIdsIter<'_> {
|
||||
type Item = DocumentId;
|
||||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
for DocumentAttrKey { document_id, .. } in &mut self.inner {
|
||||
if self.last != Some(document_id) {
|
||||
self.last = Some(document_id);
|
||||
return Some(document_id)
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use crate::serde::{Deserializer, DeserializerError};
|
||||
|
||||
pub use self::custom_settings_index::{CustomSettingsIndex, RankingOrdering, StopWords, RankingOrder, DistinctField, RankingRules};
|
||||
pub use self::common_index::CommonIndex;
|
||||
pub use self::documents_index::DocumentsIdsIter;
|
||||
use self::docs_words_index::DocsWordsIndex;
|
||||
use self::documents_index::DocumentsIndex;
|
||||
use self::main_index::MainIndex;
|
||||
@ -374,6 +375,10 @@ impl Index {
|
||||
Ok(self.update_status(update_id)?.unwrap())
|
||||
}
|
||||
|
||||
pub fn documents_ids(&self) -> Result<DocumentsIdsIter, Error> {
|
||||
Ok(self.documents_index.documents_ids()?)
|
||||
}
|
||||
|
||||
pub fn document<T>(
|
||||
&self,
|
||||
fields: Option<&HashSet<&str>>,
|
||||
|
Reference in New Issue
Block a user