Skip to main content

qdrant_edge/shard/
facet.rs

1use schemars::JsonSchema;
2use crate::segment::json_path::JsonPath;
3use crate::segment::types::Filter;
4use serde::{Deserialize, Serialize};
5use validator::Validate;
6
7/// Facet Request
8/// Counts the number of points for each unique value of a payload key.
9#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, JsonSchema, Validate)]
10#[serde(rename_all = "snake_case")]
11pub struct FacetRequestInternal {
12    /// Payload key to facet on
13    pub key: JsonPath,
14    /// Maximum number of facet hits to return. Default: 10
15    #[serde(default = "FacetRequestInternal::default_limit")]
16    #[validate(range(min = 1))]
17    pub limit: usize,
18    /// Look only for points which satisfy these conditions
19    #[validate(nested)]
20    pub filter: Option<Filter>,
21    /// If true, count exact number of points for each value.
22    /// If false, count approximate number of points faster.
23    /// Default: false
24    #[serde(default = "FacetRequestInternal::default_exact")]
25    pub exact: bool,
26}
27
28impl FacetRequestInternal {
29    pub const DEFAULT_LIMIT: usize = 10;
30
31    pub const fn default_limit() -> usize {
32        Self::DEFAULT_LIMIT
33    }
34
35    pub const fn default_exact() -> bool {
36        false
37    }
38}