2022-10-20 18:00:07 +02:00
|
|
|
use std::any::Any;
|
|
|
|
use std::sync::Arc;
|
2021-10-27 18:16:13 +02:00
|
|
|
|
|
|
|
use actix_web::HttpRequest;
|
2022-10-13 15:02:59 +02:00
|
|
|
use meilisearch_types::InstanceUid;
|
2021-10-27 18:16:13 +02:00
|
|
|
use serde_json::Value;
|
|
|
|
|
2023-05-09 19:52:11 +02:00
|
|
|
use super::{find_user_id, Analytics, DocumentDeletionKind, DocumentFetchKind};
|
2024-07-08 16:30:50 +02:00
|
|
|
use crate::routes::indexes::documents::{DocumentEditionByFunction, UpdateDocumentsQuery};
|
2023-01-12 14:09:15 +01:00
|
|
|
use crate::Opt;
|
2021-10-27 18:16:13 +02:00
|
|
|
|
2022-10-13 15:02:59 +02:00
|
|
|
pub struct MockAnalytics {
|
|
|
|
instance_uid: Option<InstanceUid>,
|
|
|
|
}
|
2021-10-27 18:16:13 +02:00
|
|
|
|
2021-10-28 16:28:41 +02:00
|
|
|
#[derive(Default)]
|
2022-10-13 15:02:59 +02:00
|
|
|
pub struct SearchAggregator;
|
2021-10-28 16:28:41 +02:00
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
impl SearchAggregator {
|
|
|
|
pub fn from_query(_: &dyn Any, _: &dyn Any) -> Self {
|
2023-08-10 11:27:56 +02:00
|
|
|
Self
|
2021-10-28 16:28:41 +02:00
|
|
|
}
|
|
|
|
|
2021-11-02 12:38:01 +01:00
|
|
|
pub fn succeed(&mut self, _: &dyn Any) {}
|
2021-10-28 16:28:41 +02:00
|
|
|
}
|
|
|
|
|
2024-05-27 10:54:12 +02:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct SimilarAggregator;
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
impl SimilarAggregator {
|
|
|
|
pub fn from_query(_: &dyn Any, _: &dyn Any) -> Self {
|
|
|
|
Self
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn succeed(&mut self, _: &dyn Any) {}
|
|
|
|
}
|
|
|
|
|
2023-02-20 09:21:52 +01:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct MultiSearchAggregator;
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
impl MultiSearchAggregator {
|
|
|
|
pub fn from_queries(_: &dyn Any, _: &dyn Any) -> Self {
|
2023-08-10 11:27:56 +02:00
|
|
|
Self
|
2023-02-20 09:21:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn succeed(&mut self) {}
|
|
|
|
}
|
|
|
|
|
2023-04-26 17:08:55 +02:00
|
|
|
#[derive(Default)]
|
|
|
|
pub struct FacetSearchAggregator;
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
impl FacetSearchAggregator {
|
|
|
|
pub fn from_query(_: &dyn Any, _: &dyn Any) -> Self {
|
2023-08-10 11:27:56 +02:00
|
|
|
Self
|
2023-04-26 17:08:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn succeed(&mut self, _: &dyn Any) {}
|
|
|
|
}
|
|
|
|
|
2021-10-27 18:16:13 +02:00
|
|
|
impl MockAnalytics {
|
2021-10-29 16:10:58 +02:00
|
|
|
#[allow(clippy::new_ret_no_self)]
|
2022-10-13 15:02:59 +02:00
|
|
|
pub fn new(opt: &Opt) -> Arc<dyn Analytics> {
|
|
|
|
let instance_uid = find_user_id(&opt.db_path);
|
|
|
|
Arc::new(Self { instance_uid })
|
2021-10-27 18:16:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Analytics for MockAnalytics {
|
2022-10-13 15:02:59 +02:00
|
|
|
fn instance_uid(&self) -> Option<&meilisearch_types::InstanceUid> {
|
|
|
|
self.instance_uid.as_ref()
|
|
|
|
}
|
|
|
|
|
2021-10-27 18:16:13 +02:00
|
|
|
// These methods are noop and should be optimized out
|
2021-10-29 15:58:06 +02:00
|
|
|
fn publish(&self, _event_name: String, _send: Value, _request: Option<&HttpRequest>) {}
|
|
|
|
fn get_search(&self, _aggregate: super::SearchAggregator) {}
|
|
|
|
fn post_search(&self, _aggregate: super::SearchAggregator) {}
|
2024-05-27 10:54:12 +02:00
|
|
|
fn get_similar(&self, _aggregate: super::SimilarAggregator) {}
|
|
|
|
fn post_similar(&self, _aggregate: super::SimilarAggregator) {}
|
2023-02-20 09:21:52 +01:00
|
|
|
fn post_multi_search(&self, _aggregate: super::MultiSearchAggregator) {}
|
2023-04-26 17:08:55 +02:00
|
|
|
fn post_facet_search(&self, _aggregate: super::FacetSearchAggregator) {}
|
2021-10-27 18:16:13 +02:00
|
|
|
fn add_documents(
|
2021-10-29 15:58:06 +02:00
|
|
|
&self,
|
2021-10-27 18:16:13 +02:00
|
|
|
_documents_query: &UpdateDocumentsQuery,
|
|
|
|
_index_creation: bool,
|
|
|
|
_request: &HttpRequest,
|
|
|
|
) {
|
|
|
|
}
|
2022-11-28 16:27:41 +01:00
|
|
|
fn delete_documents(&self, _kind: DocumentDeletionKind, _request: &HttpRequest) {}
|
2021-10-27 18:16:13 +02:00
|
|
|
fn update_documents(
|
2021-10-29 15:58:06 +02:00
|
|
|
&self,
|
2021-10-27 18:16:13 +02:00
|
|
|
_documents_query: &UpdateDocumentsQuery,
|
|
|
|
_index_creation: bool,
|
|
|
|
_request: &HttpRequest,
|
|
|
|
) {
|
|
|
|
}
|
2024-07-08 16:30:50 +02:00
|
|
|
fn update_documents_by_function(
|
|
|
|
&self,
|
|
|
|
_documents_query: &DocumentEditionByFunction,
|
|
|
|
_index_creation: bool,
|
|
|
|
_request: &HttpRequest,
|
|
|
|
) {
|
|
|
|
}
|
2023-05-09 19:52:11 +02:00
|
|
|
fn get_fetch_documents(&self, _documents_query: &DocumentFetchKind, _request: &HttpRequest) {}
|
|
|
|
fn post_fetch_documents(&self, _documents_query: &DocumentFetchKind, _request: &HttpRequest) {}
|
2021-10-27 18:16:13 +02:00
|
|
|
}
|