Apply review suggestions

Add preconditions

Fix underflow

Remove unwrap

Turn methods to associated functions

Apply review suggestions
This commit is contained in:
Mubelotix
2025-07-15 17:04:08 +02:00
parent f60814b319
commit 77138a42d6
5 changed files with 58 additions and 95 deletions

Binary file not shown.

View File

@ -104,6 +104,4 @@ impl Analytics for MockAnalytics {
_request: &HttpRequest,
) {
}
fn get_fetch_documents(&self, _documents_query: &DocumentFetchKind, _request: &HttpRequest) {}
fn post_fetch_documents(&self, _documents_query: &DocumentFetchKind, _request: &HttpRequest) {}
}

View File

@ -73,12 +73,6 @@ pub enum DocumentDeletionKind {
PerFilter,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DocumentFetchKind {
PerDocumentId { retrieve_vectors: bool },
Normal { with_filter: bool, limit: usize, offset: usize, retrieve_vectors: bool },
}
/// To send an event to segment, your event must be able to aggregate itself with another event of the same type.
pub trait Aggregate: 'static + mopa::Any + Send {
/// The name of the event that will be sent to segment.

View File

@ -156,52 +156,6 @@ pub struct DocumentsFetchAggregator<Method: AggregateMethod> {
marker: std::marker::PhantomData<Method>,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum DocumentFetchKind {
PerDocumentId {
retrieve_vectors: bool,
sort: bool,
},
Normal {
with_filter: bool,
limit: usize,
offset: usize,
retrieve_vectors: bool,
sort: bool,
ids: usize,
},
}
impl<Method: AggregateMethod> DocumentsFetchAggregator<Method> {
pub fn from_query(query: &DocumentFetchKind) -> Self {
let (limit, offset, retrieve_vectors, sort) = match query {
DocumentFetchKind::PerDocumentId { retrieve_vectors, sort } => {
(1, 0, *retrieve_vectors, *sort)
}
DocumentFetchKind::Normal { limit, offset, retrieve_vectors, sort, .. } => {
(*limit, *offset, *retrieve_vectors, *sort)
}
};
let ids = match query {
DocumentFetchKind::Normal { ids, .. } => *ids,
DocumentFetchKind::PerDocumentId { .. } => 0,
};
Self {
per_document_id: matches!(query, DocumentFetchKind::PerDocumentId { .. }),
per_filter: matches!(query, DocumentFetchKind::Normal { with_filter, .. } if *with_filter),
max_limit: limit,
max_offset: offset,
sort,
retrieve_vectors,
max_document_ids: ids,
marker: PhantomData,
}
}
}
impl<Method: AggregateMethod> Aggregate for DocumentsFetchAggregator<Method> {
fn event_name(&self) -> &'static str {
Method::event_name()
@ -1573,16 +1527,19 @@ fn retrieve_documents<S: AsRef<str>>(
})?
}
let facet_sort;
let (it, number_of_documents) = if let Some(sort) = sort_criteria {
let number_of_documents = candidates.len();
facet_sort = recursive_sort(index, &rtxn, sort, &candidates)?;
let facet_sort = recursive_sort(index, &rtxn, sort, &candidates)?;
let iter = facet_sort.iter()?;
let mut documents = Vec::with_capacity(limit);
for result in iter.skip(offset).take(limit) {
documents.push(result?);
}
(
itertools::Either::Left(some_documents(
index,
&rtxn,
iter.map(|d| d.unwrap()).skip(offset).take(limit),
documents.into_iter(),
retrieve_vectors,
)?),
number_of_documents,