Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove Document: DocumentDeserialize dependency #2211

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/core/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{fmt, io};
use crate::collector::Collector;
use crate::core::{Executor, SegmentReader};
use crate::query::{Bm25StatisticsProvider, EnableScoring, Query};
use crate::schema::document::Document;
use crate::schema::document::{Document, DocumentDeserialize};
use crate::schema::{Schema, Term};
use crate::space_usage::SearcherSpaceUsage;
use crate::store::{CacheStats, StoreReader};
Expand Down Expand Up @@ -84,7 +84,10 @@ impl Searcher {
///
/// The searcher uses the segment ordinal to route the
/// request to the right `Segment`.
pub fn doc<D: Document>(&self, doc_address: DocAddress) -> crate::Result<D> {
pub fn doc<D: Document + DocumentDeserialize>(
PSeitz marked this conversation as resolved.
Show resolved Hide resolved
&self,
doc_address: DocAddress,
) -> crate::Result<D> {
let store_reader = &self.inner.store_readers[doc_address.segment_ord as usize];
store_reader.get(doc_address.doc_id)
}
Expand All @@ -104,7 +107,10 @@ impl Searcher {

/// Fetches a document in an asynchronous manner.
#[cfg(feature = "quickwit")]
pub async fn doc_async<D: Document>(&self, doc_address: DocAddress) -> crate::Result<D> {
pub async fn doc_async<D: Document + DocumentDeserialize>(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question as above

&self,
doc_address: DocAddress,
) -> crate::Result<D> {
let store_reader = &self.inner.store_readers[doc_address.segment_ord as usize];
store_reader.get_async(doc_address.doc_id).await
}
Expand Down
2 changes: 1 addition & 1 deletion src/schema/document/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub use self::value::{ReferenceValue, Value};
use super::*;

/// 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.
type Value<'a>: Value<'a> + Clone
where Self: 'a;
Expand Down
11 changes: 7 additions & 4 deletions src/store/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use super::Decompressor;
use crate::directory::FileSlice;
use crate::error::DataCorruption;
use crate::fastfield::AliveBitSet;
use crate::schema::document::{BinaryDocumentDeserializer, Document};
use crate::schema::document::{BinaryDocumentDeserializer, Document, DocumentDeserialize};
use crate::space_usage::StoreSpaceUsage;
use crate::store::index::Checkpoint;
use crate::DocId;
Expand Down Expand Up @@ -198,7 +198,7 @@ impl StoreReader {
///
/// It should not be called to score documents
/// for instance.
pub fn get<D: Document>(&self, doc_id: DocId) -> crate::Result<D> {
pub fn get<D: Document + DocumentDeserialize>(&self, doc_id: DocId) -> crate::Result<D> {
let mut doc_bytes = self.get_document_bytes(doc_id)?;

let deserializer = BinaryDocumentDeserializer::from_reader(&mut doc_bytes)
Expand Down Expand Up @@ -235,7 +235,7 @@ impl StoreReader {
/// 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.
/// 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,
alive_bitset: Option<&'a AliveBitSet>,
) -> impl Iterator<Item = crate::Result<D>> + 'b {
Expand Down Expand Up @@ -370,7 +370,10 @@ impl StoreReader {
}

/// 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: Document + DocumentDeserialize>(
&self,
doc_id: DocId,
) -> crate::Result<D> {
let mut doc_bytes = self.get_document_bytes_async(doc_id).await?;

let deserializer = BinaryDocumentDeserializer::from_reader(&mut doc_bytes)
Expand Down