mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Expose the DocumentId
struct to be sure to inject the generated ids
This commit is contained in:
parent
d1a4da9812
commit
0bbcc7b180
7 changed files with 41 additions and 25 deletions
|
@ -7,6 +7,7 @@ use super::{
|
|||
DocumentsBatchCursor, DocumentsBatchCursorError, DocumentsBatchIndex, DocumentsBatchReader,
|
||||
Error,
|
||||
};
|
||||
use crate::update::DocumentId;
|
||||
use crate::FieldId;
|
||||
|
||||
/// The `EnrichedDocumentsBatchReader` provides a way to iterate over documents that have
|
||||
|
@ -66,10 +67,10 @@ impl<R: io::Read + io::Seek> EnrichedDocumentsBatchReader<R> {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct EnrichedDocument<'a> {
|
||||
pub document: KvReader<'a, FieldId>,
|
||||
pub external_id: &'a str,
|
||||
pub document_id: DocumentId,
|
||||
}
|
||||
|
||||
pub struct EnrichedDocumentsBatchCursor<R> {
|
||||
|
@ -110,13 +111,13 @@ impl<R: io::Read + io::Seek> EnrichedDocumentsBatchCursor<R> {
|
|||
&mut self,
|
||||
) -> Result<Option<EnrichedDocument>, DocumentsBatchCursorError> {
|
||||
let document = self.documents.next_document()?;
|
||||
let external_id = match self.external_ids.move_on_next()? {
|
||||
Some((_, bytes)) => Some(str::from_utf8(bytes)?),
|
||||
let document_id = match self.external_ids.move_on_next()? {
|
||||
Some((_, bytes)) => serde_json::from_slice(bytes).map(Some)?,
|
||||
None => None,
|
||||
};
|
||||
|
||||
match document.zip(external_id) {
|
||||
Some((document, external_id)) => Ok(Some(EnrichedDocument { document, external_id })),
|
||||
match document.zip(document_id) {
|
||||
Some((document, document_id)) => Ok(Some(EnrichedDocument { document, document_id })),
|
||||
None => Ok(None),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use std::convert::TryInto;
|
||||
use std::{error, fmt, io, str};
|
||||
use std::{error, fmt, io};
|
||||
|
||||
use obkv::KvReader;
|
||||
|
||||
|
@ -95,7 +95,7 @@ impl<R: io::Read + io::Seek> DocumentsBatchCursor<R> {
|
|||
#[derive(Debug)]
|
||||
pub enum DocumentsBatchCursorError {
|
||||
Grenad(grenad::Error),
|
||||
Utf8(str::Utf8Error),
|
||||
SerdeJson(serde_json::Error),
|
||||
}
|
||||
|
||||
impl From<grenad::Error> for DocumentsBatchCursorError {
|
||||
|
@ -104,9 +104,9 @@ impl From<grenad::Error> for DocumentsBatchCursorError {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<str::Utf8Error> for DocumentsBatchCursorError {
|
||||
fn from(error: str::Utf8Error) -> DocumentsBatchCursorError {
|
||||
DocumentsBatchCursorError::Utf8(error)
|
||||
impl From<serde_json::Error> for DocumentsBatchCursorError {
|
||||
fn from(error: serde_json::Error) -> DocumentsBatchCursorError {
|
||||
DocumentsBatchCursorError::SerdeJson(error)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -116,7 +116,7 @@ impl fmt::Display for DocumentsBatchCursorError {
|
|||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match self {
|
||||
DocumentsBatchCursorError::Grenad(e) => e.fmt(f),
|
||||
DocumentsBatchCursorError::Utf8(e) => e.fmt(f),
|
||||
DocumentsBatchCursorError::SerdeJson(e) => e.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue