use schemars::JsonSchema;
use crate::segment::data_types::load_profile::LoadProfile;
use crate::segment::data_types::order_by::OrderByInterface;
use crate::segment::types::{Filter, PointIdType, WithPayloadInterface, WithVector};
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Clone, Debug, PartialEq, Hash, Deserialize, Serialize, JsonSchema, Validate)]
#[serde(rename_all = "snake_case")]
pub struct ScrollRequestInternal {
pub offset: Option<PointIdType>,
#[validate(range(min = 1))]
pub limit: Option<usize>,
#[validate(nested)]
pub filter: Option<Filter>,
pub with_payload: Option<WithPayloadInterface>,
#[serde(default, alias = "with_vectors")]
pub with_vector: WithVector,
pub order_by: Option<OrderByInterface>,
}
impl Default for ScrollRequestInternal {
fn default() -> Self {
ScrollRequestInternal {
offset: None,
limit: Some(Self::default_limit()),
filter: None,
with_payload: Some(Self::default_with_payload()),
with_vector: Self::default_with_vector(),
order_by: None,
}
}
}
impl ScrollRequestInternal {
pub fn load_profile(&self) -> LoadProfile {
let Self {
offset: _,
limit: _,
filter,
with_payload,
with_vector: _,
order_by,
} = self;
let order_by_key = order_by.as_ref().map(|order_by| match order_by {
OrderByInterface::Key(key) => key,
OrderByInterface::Struct(order_by) => &order_by.key,
});
let with_payload = with_payload.as_ref().is_none_or(|wp| wp.is_required());
LoadProfile::for_scroll(filter.as_ref(), order_by_key, with_payload)
}
pub const fn default_limit() -> usize {
10
}
pub const fn default_with_payload() -> WithPayloadInterface {
WithPayloadInterface::Bool(true)
}
pub const fn default_with_vector() -> WithVector {
WithVector::Bool(false)
}
}