mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-12-25 14:10:06 +01:00
Extract the primary key name and make it accessible
This commit is contained in:
parent
6a0a0ae94f
commit
5f1bfb73ee
@ -17,17 +17,20 @@ use crate::FieldId;
|
|||||||
/// `FieldId`. The mapping between the field ids and the field names is done thanks to the index.
|
/// `FieldId`. The mapping between the field ids and the field names is done thanks to the index.
|
||||||
pub struct EnrichedDocumentsBatchReader<R> {
|
pub struct EnrichedDocumentsBatchReader<R> {
|
||||||
documents: DocumentsBatchReader<R>,
|
documents: DocumentsBatchReader<R>,
|
||||||
|
primary_key: String,
|
||||||
external_ids: grenad::ReaderCursor<File>,
|
external_ids: grenad::ReaderCursor<File>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: io::Read + io::Seek> EnrichedDocumentsBatchReader<R> {
|
impl<R: io::Read + io::Seek> EnrichedDocumentsBatchReader<R> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
documents: DocumentsBatchReader<R>,
|
documents: DocumentsBatchReader<R>,
|
||||||
|
primary_key: String,
|
||||||
external_ids: grenad::Reader<File>,
|
external_ids: grenad::Reader<File>,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
if documents.documents_count() as u64 == external_ids.len() {
|
if documents.documents_count() as u64 == external_ids.len() {
|
||||||
Ok(EnrichedDocumentsBatchReader {
|
Ok(EnrichedDocumentsBatchReader {
|
||||||
documents,
|
documents,
|
||||||
|
primary_key,
|
||||||
external_ids: external_ids.into_cursor()?,
|
external_ids: external_ids.into_cursor()?,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -39,6 +42,10 @@ impl<R: io::Read + io::Seek> EnrichedDocumentsBatchReader<R> {
|
|||||||
self.documents.documents_count()
|
self.documents.documents_count()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn primary_key(&self) -> &str {
|
||||||
|
&self.primary_key
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.documents.is_empty()
|
self.documents.is_empty()
|
||||||
}
|
}
|
||||||
@ -49,9 +56,13 @@ impl<R: io::Read + io::Seek> EnrichedDocumentsBatchReader<R> {
|
|||||||
|
|
||||||
/// This method returns a forward cursor over the enriched documents.
|
/// This method returns a forward cursor over the enriched documents.
|
||||||
pub fn into_cursor(self) -> EnrichedDocumentsBatchCursor<R> {
|
pub fn into_cursor(self) -> EnrichedDocumentsBatchCursor<R> {
|
||||||
let EnrichedDocumentsBatchReader { documents, mut external_ids } = self;
|
let EnrichedDocumentsBatchReader { documents, primary_key, mut external_ids } = self;
|
||||||
external_ids.reset();
|
external_ids.reset();
|
||||||
EnrichedDocumentsBatchCursor { documents: documents.into_cursor(), external_ids }
|
EnrichedDocumentsBatchCursor {
|
||||||
|
documents: documents.into_cursor(),
|
||||||
|
primary_key,
|
||||||
|
external_ids,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,13 +74,22 @@ pub struct EnrichedDocument<'a> {
|
|||||||
|
|
||||||
pub struct EnrichedDocumentsBatchCursor<R> {
|
pub struct EnrichedDocumentsBatchCursor<R> {
|
||||||
documents: DocumentsBatchCursor<R>,
|
documents: DocumentsBatchCursor<R>,
|
||||||
|
primary_key: String,
|
||||||
external_ids: grenad::ReaderCursor<File>,
|
external_ids: grenad::ReaderCursor<File>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R> EnrichedDocumentsBatchCursor<R> {
|
impl<R> EnrichedDocumentsBatchCursor<R> {
|
||||||
pub fn into_reader(self) -> EnrichedDocumentsBatchReader<R> {
|
pub fn into_reader(self) -> EnrichedDocumentsBatchReader<R> {
|
||||||
let EnrichedDocumentsBatchCursor { documents, external_ids } = self;
|
let EnrichedDocumentsBatchCursor { documents, primary_key, external_ids } = self;
|
||||||
EnrichedDocumentsBatchReader { documents: documents.into_reader(), external_ids }
|
EnrichedDocumentsBatchReader {
|
||||||
|
documents: documents.into_reader(),
|
||||||
|
primary_key,
|
||||||
|
external_ids,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn primary_key(&self) -> &str {
|
||||||
|
&self.primary_key
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn documents_batch_index(&self) -> &DocumentsBatchIndex {
|
pub fn documents_batch_index(&self) -> &DocumentsBatchIndex {
|
||||||
|
@ -94,7 +94,11 @@ pub fn validate_and_enrich_documents_batch<R: Read + Seek>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
let external_ids = writer_into_reader(external_ids)?;
|
let external_ids = writer_into_reader(external_ids)?;
|
||||||
let reader = EnrichedDocumentsBatchReader::new(cursor.into_reader(), external_ids)?;
|
let reader = EnrichedDocumentsBatchReader::new(
|
||||||
|
cursor.into_reader(),
|
||||||
|
primary_key.primary_key().to_string(),
|
||||||
|
external_ids,
|
||||||
|
)?;
|
||||||
|
|
||||||
Ok(Ok(reader))
|
Ok(Ok(reader))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user