remove Document: DocumentDeserialize dependency (#2211)

* remove Document: DocumentDeserialize dependency

The dependency requires users to implement an API they may not use.

* remove unnecessary Document bounds
This commit is contained in:
PSeitz
2023-10-13 07:59:54 +02:00
committed by GitHub
parent 337ffadefd
commit 182f58cea6
3 changed files with 11 additions and 8 deletions

View File

@@ -5,7 +5,7 @@ use std::{fmt, io};
use crate::collector::Collector; use crate::collector::Collector;
use crate::core::{Executor, SegmentReader}; use crate::core::{Executor, SegmentReader};
use crate::query::{Bm25StatisticsProvider, EnableScoring, Query}; use crate::query::{Bm25StatisticsProvider, EnableScoring, Query};
use crate::schema::document::Document; use crate::schema::document::{Document, DocumentDeserialize};
use crate::schema::{Schema, Term}; use crate::schema::{Schema, Term};
use crate::space_usage::SearcherSpaceUsage; use crate::space_usage::SearcherSpaceUsage;
use crate::store::{CacheStats, StoreReader}; use crate::store::{CacheStats, StoreReader};
@@ -84,7 +84,7 @@ impl Searcher {
/// ///
/// The searcher uses the segment ordinal to route the /// The searcher uses the segment ordinal to route the
/// request to the right `Segment`. /// request to the right `Segment`.
pub fn doc<D: Document>(&self, doc_address: DocAddress) -> crate::Result<D> { pub fn doc<D: DocumentDeserialize>(&self, doc_address: DocAddress) -> crate::Result<D> {
let store_reader = &self.inner.store_readers[doc_address.segment_ord as usize]; let store_reader = &self.inner.store_readers[doc_address.segment_ord as usize];
store_reader.get(doc_address.doc_id) store_reader.get(doc_address.doc_id)
} }
@@ -104,7 +104,10 @@ impl Searcher {
/// Fetches a document in an asynchronous manner. /// Fetches a document in an asynchronous manner.
#[cfg(feature = "quickwit")] #[cfg(feature = "quickwit")]
pub async fn doc_async<D: Document>(&self, doc_address: DocAddress) -> crate::Result<D> { pub async fn doc_async<D: DocumentDeserialize>(
&self,
doc_address: DocAddress,
) -> crate::Result<D> {
let store_reader = &self.inner.store_readers[doc_address.segment_ord as usize]; let store_reader = &self.inner.store_readers[doc_address.segment_ord as usize];
store_reader.get_async(doc_address.doc_id).await store_reader.get_async(doc_address.doc_id).await
} }

View File

@@ -174,7 +174,7 @@ pub use self::value::{ReferenceValue, Value};
use super::*; use super::*;
/// The core trait representing a document within the index. /// The core trait representing a document within the index.
pub trait Document: DocumentDeserialize + Send + Sync + 'static { pub trait Document: Send + Sync + 'static {
/// The value of the field. /// The value of the field.
type Value<'a>: Value<'a> + Clone type Value<'a>: Value<'a> + Clone
where Self: 'a; where Self: 'a;

View File

@@ -14,7 +14,7 @@ use super::Decompressor;
use crate::directory::FileSlice; use crate::directory::FileSlice;
use crate::error::DataCorruption; use crate::error::DataCorruption;
use crate::fastfield::AliveBitSet; use crate::fastfield::AliveBitSet;
use crate::schema::document::{BinaryDocumentDeserializer, Document}; use crate::schema::document::{BinaryDocumentDeserializer, Document, DocumentDeserialize};
use crate::space_usage::StoreSpaceUsage; use crate::space_usage::StoreSpaceUsage;
use crate::store::index::Checkpoint; use crate::store::index::Checkpoint;
use crate::DocId; use crate::DocId;
@@ -198,7 +198,7 @@ impl StoreReader {
/// ///
/// It should not be called to score documents /// It should not be called to score documents
/// for instance. /// for instance.
pub fn get<D: Document>(&self, doc_id: DocId) -> crate::Result<D> { pub fn get<D: DocumentDeserialize>(&self, doc_id: DocId) -> crate::Result<D> {
let mut doc_bytes = self.get_document_bytes(doc_id)?; let mut doc_bytes = self.get_document_bytes(doc_id)?;
let deserializer = BinaryDocumentDeserializer::from_reader(&mut doc_bytes) let deserializer = BinaryDocumentDeserializer::from_reader(&mut doc_bytes)
@@ -235,7 +235,7 @@ impl StoreReader {
/// Iterator over all Documents in their order as they are stored in the doc store. /// Iterator over all Documents in their order as they are stored in the doc store.
/// Use this, if you want to extract all Documents from the doc store. /// Use this, if you want to extract all Documents from the doc store.
/// The `alive_bitset` has to be forwarded from the `SegmentReader` or the results may be wrong. /// The `alive_bitset` has to be forwarded from the `SegmentReader` or the results may be wrong.
pub fn iter<'a: 'b, 'b, D: Document>( pub fn iter<'a: 'b, 'b, D: Document + DocumentDeserialize>(
&'b self, &'b self,
alive_bitset: Option<&'a AliveBitSet>, alive_bitset: Option<&'a AliveBitSet>,
) -> impl Iterator<Item = crate::Result<D>> + 'b { ) -> impl Iterator<Item = crate::Result<D>> + 'b {
@@ -370,7 +370,7 @@ impl StoreReader {
} }
/// Fetches a document asynchronously. Async version of [`get`](Self::get). /// Fetches a document asynchronously. Async version of [`get`](Self::get).
pub async fn get_async<D: Document>(&self, doc_id: DocId) -> crate::Result<D> { pub async fn get_async<D: DocumentDeserialize>(&self, doc_id: DocId) -> crate::Result<D> {
let mut doc_bytes = self.get_document_bytes_async(doc_id).await?; let mut doc_bytes = self.get_document_bytes_async(doc_id).await?;
let deserializer = BinaryDocumentDeserializer::from_reader(&mut doc_bytes) let deserializer = BinaryDocumentDeserializer::from_reader(&mut doc_bytes)