mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-07-27 00:31:02 +00:00
Add telemetry
This commit is contained in:
@ -135,6 +135,7 @@ pub struct DocumentsFetchAggregator<Method: AggregateMethod> {
|
|||||||
per_document_id: bool,
|
per_document_id: bool,
|
||||||
// if a filter was used
|
// if a filter was used
|
||||||
per_filter: bool,
|
per_filter: bool,
|
||||||
|
with_vector_filter: bool,
|
||||||
|
|
||||||
#[serde(rename = "vector.retrieve_vectors")]
|
#[serde(rename = "vector.retrieve_vectors")]
|
||||||
retrieve_vectors: bool,
|
retrieve_vectors: bool,
|
||||||
@ -153,8 +154,17 @@ pub struct DocumentsFetchAggregator<Method: AggregateMethod> {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||||
pub enum DocumentFetchKind {
|
pub enum DocumentFetchKind {
|
||||||
PerDocumentId { retrieve_vectors: bool },
|
PerDocumentId {
|
||||||
Normal { with_filter: bool, limit: usize, offset: usize, retrieve_vectors: bool, ids: usize },
|
retrieve_vectors: bool,
|
||||||
|
},
|
||||||
|
Normal {
|
||||||
|
with_filter: bool,
|
||||||
|
with_vector_filter: bool,
|
||||||
|
limit: usize,
|
||||||
|
offset: usize,
|
||||||
|
retrieve_vectors: bool,
|
||||||
|
ids: usize,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<Method: AggregateMethod> DocumentsFetchAggregator<Method> {
|
impl<Method: AggregateMethod> DocumentsFetchAggregator<Method> {
|
||||||
@ -174,6 +184,7 @@ impl<Method: AggregateMethod> DocumentsFetchAggregator<Method> {
|
|||||||
Self {
|
Self {
|
||||||
per_document_id: matches!(query, DocumentFetchKind::PerDocumentId { .. }),
|
per_document_id: matches!(query, DocumentFetchKind::PerDocumentId { .. }),
|
||||||
per_filter: matches!(query, DocumentFetchKind::Normal { with_filter, .. } if *with_filter),
|
per_filter: matches!(query, DocumentFetchKind::Normal { with_filter, .. } if *with_filter),
|
||||||
|
with_vector_filter: matches!(query, DocumentFetchKind::Normal { with_vector_filter, .. } if *with_vector_filter),
|
||||||
max_limit: limit,
|
max_limit: limit,
|
||||||
max_offset: offset,
|
max_offset: offset,
|
||||||
retrieve_vectors,
|
retrieve_vectors,
|
||||||
@ -193,6 +204,7 @@ impl<Method: AggregateMethod> Aggregate for DocumentsFetchAggregator<Method> {
|
|||||||
Box::new(Self {
|
Box::new(Self {
|
||||||
per_document_id: self.per_document_id | new.per_document_id,
|
per_document_id: self.per_document_id | new.per_document_id,
|
||||||
per_filter: self.per_filter | new.per_filter,
|
per_filter: self.per_filter | new.per_filter,
|
||||||
|
with_vector_filter: self.with_vector_filter | new.with_vector_filter,
|
||||||
retrieve_vectors: self.retrieve_vectors | new.retrieve_vectors,
|
retrieve_vectors: self.retrieve_vectors | new.retrieve_vectors,
|
||||||
max_limit: self.max_limit.max(new.max_limit),
|
max_limit: self.max_limit.max(new.max_limit),
|
||||||
max_offset: self.max_offset.max(new.max_offset),
|
max_offset: self.max_offset.max(new.max_offset),
|
||||||
@ -276,6 +288,7 @@ pub async fn get_document(
|
|||||||
retrieve_vectors: param_retrieve_vectors.0,
|
retrieve_vectors: param_retrieve_vectors.0,
|
||||||
per_document_id: true,
|
per_document_id: true,
|
||||||
per_filter: false,
|
per_filter: false,
|
||||||
|
with_vector_filter: false,
|
||||||
max_limit: 0,
|
max_limit: 0,
|
||||||
max_offset: 0,
|
max_offset: 0,
|
||||||
max_document_ids: 0,
|
max_document_ids: 0,
|
||||||
@ -495,6 +508,10 @@ pub async fn documents_by_query_post(
|
|||||||
analytics.publish(
|
analytics.publish(
|
||||||
DocumentsFetchAggregator::<DocumentsPOST> {
|
DocumentsFetchAggregator::<DocumentsPOST> {
|
||||||
per_filter: body.filter.is_some(),
|
per_filter: body.filter.is_some(),
|
||||||
|
with_vector_filter: body
|
||||||
|
.filter
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|f| f.to_string().contains("_vectors")),
|
||||||
retrieve_vectors: body.retrieve_vectors,
|
retrieve_vectors: body.retrieve_vectors,
|
||||||
max_limit: body.limit,
|
max_limit: body.limit,
|
||||||
max_offset: body.offset,
|
max_offset: body.offset,
|
||||||
@ -596,6 +613,10 @@ pub async fn get_documents(
|
|||||||
analytics.publish(
|
analytics.publish(
|
||||||
DocumentsFetchAggregator::<DocumentsGET> {
|
DocumentsFetchAggregator::<DocumentsGET> {
|
||||||
per_filter: query.filter.is_some(),
|
per_filter: query.filter.is_some(),
|
||||||
|
with_vector_filter: query
|
||||||
|
.filter
|
||||||
|
.as_ref()
|
||||||
|
.is_some_and(|f| f.to_string().contains("_vectors")),
|
||||||
retrieve_vectors: query.retrieve_vectors,
|
retrieve_vectors: query.retrieve_vectors,
|
||||||
max_limit: query.limit,
|
max_limit: query.limit,
|
||||||
max_offset: query.offset,
|
max_offset: query.offset,
|
||||||
|
@ -40,6 +40,7 @@ pub struct SearchAggregator<Method: AggregateMethod> {
|
|||||||
// filter
|
// filter
|
||||||
filter_with_geo_radius: bool,
|
filter_with_geo_radius: bool,
|
||||||
filter_with_geo_bounding_box: bool,
|
filter_with_geo_bounding_box: bool,
|
||||||
|
filter_on_vectors: bool,
|
||||||
// every time a request has a filter, this field must be incremented by the number of terms it contains
|
// every time a request has a filter, this field must be incremented by the number of terms it contains
|
||||||
filter_sum_of_criteria_terms: usize,
|
filter_sum_of_criteria_terms: usize,
|
||||||
// every time a request has a filter, this field must be incremented by one
|
// every time a request has a filter, this field must be incremented by one
|
||||||
@ -163,6 +164,7 @@ impl<Method: AggregateMethod> SearchAggregator<Method> {
|
|||||||
let stringified_filters = filter.to_string();
|
let stringified_filters = filter.to_string();
|
||||||
ret.filter_with_geo_radius = stringified_filters.contains("_geoRadius(");
|
ret.filter_with_geo_radius = stringified_filters.contains("_geoRadius(");
|
||||||
ret.filter_with_geo_bounding_box = stringified_filters.contains("_geoBoundingBox(");
|
ret.filter_with_geo_bounding_box = stringified_filters.contains("_geoBoundingBox(");
|
||||||
|
ret.filter_on_vectors = stringified_filters.contains("_vectors");
|
||||||
ret.filter_sum_of_criteria_terms = RE.split(&stringified_filters).count();
|
ret.filter_sum_of_criteria_terms = RE.split(&stringified_filters).count();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,6 +262,7 @@ impl<Method: AggregateMethod> Aggregate for SearchAggregator<Method> {
|
|||||||
distinct,
|
distinct,
|
||||||
filter_with_geo_radius,
|
filter_with_geo_radius,
|
||||||
filter_with_geo_bounding_box,
|
filter_with_geo_bounding_box,
|
||||||
|
filter_on_vectors,
|
||||||
filter_sum_of_criteria_terms,
|
filter_sum_of_criteria_terms,
|
||||||
filter_total_number_of_criteria,
|
filter_total_number_of_criteria,
|
||||||
used_syntax,
|
used_syntax,
|
||||||
@ -314,6 +317,7 @@ impl<Method: AggregateMethod> Aggregate for SearchAggregator<Method> {
|
|||||||
// filter
|
// filter
|
||||||
self.filter_with_geo_radius |= filter_with_geo_radius;
|
self.filter_with_geo_radius |= filter_with_geo_radius;
|
||||||
self.filter_with_geo_bounding_box |= filter_with_geo_bounding_box;
|
self.filter_with_geo_bounding_box |= filter_with_geo_bounding_box;
|
||||||
|
self.filter_on_vectors |= filter_on_vectors;
|
||||||
self.filter_sum_of_criteria_terms =
|
self.filter_sum_of_criteria_terms =
|
||||||
self.filter_sum_of_criteria_terms.saturating_add(filter_sum_of_criteria_terms);
|
self.filter_sum_of_criteria_terms.saturating_add(filter_sum_of_criteria_terms);
|
||||||
self.filter_total_number_of_criteria =
|
self.filter_total_number_of_criteria =
|
||||||
@ -388,6 +392,7 @@ impl<Method: AggregateMethod> Aggregate for SearchAggregator<Method> {
|
|||||||
distinct,
|
distinct,
|
||||||
filter_with_geo_radius,
|
filter_with_geo_radius,
|
||||||
filter_with_geo_bounding_box,
|
filter_with_geo_bounding_box,
|
||||||
|
filter_on_vectors,
|
||||||
filter_sum_of_criteria_terms,
|
filter_sum_of_criteria_terms,
|
||||||
filter_total_number_of_criteria,
|
filter_total_number_of_criteria,
|
||||||
used_syntax,
|
used_syntax,
|
||||||
@ -445,6 +450,7 @@ impl<Method: AggregateMethod> Aggregate for SearchAggregator<Method> {
|
|||||||
"filter": {
|
"filter": {
|
||||||
"with_geoRadius": filter_with_geo_radius,
|
"with_geoRadius": filter_with_geo_radius,
|
||||||
"with_geoBoundingBox": filter_with_geo_bounding_box,
|
"with_geoBoundingBox": filter_with_geo_bounding_box,
|
||||||
|
"on_vectors": filter_on_vectors,
|
||||||
"avg_criteria_number": format!("{:.2}", filter_sum_of_criteria_terms as f64 / filter_total_number_of_criteria as f64),
|
"avg_criteria_number": format!("{:.2}", filter_sum_of_criteria_terms as f64 / filter_total_number_of_criteria as f64),
|
||||||
"most_used_syntax": used_syntax.iter().max_by_key(|(_, v)| *v).map(|(k, _)| json!(k)).unwrap_or_else(|| json!(null)),
|
"most_used_syntax": used_syntax.iter().max_by_key(|(_, v)| *v).map(|(k, _)| json!(k)).unwrap_or_else(|| json!(null)),
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user