From 0990e95830a43dd7b0b4f513f86f442efedc42d5 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Mon, 11 Apr 2022 14:18:47 +0200 Subject: [PATCH] Feat(Analytics): Add analytics for search format options --- .../src/analytics/segment_analytics.rs | 31 ++++++++++++++++++- meilisearch-lib/src/index/mod.rs | 3 +- meilisearch-lib/src/index/search.rs | 6 ++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/meilisearch-http/src/analytics/segment_analytics.rs b/meilisearch-http/src/analytics/segment_analytics.rs index 693d63015..3d3b23d70 100644 --- a/meilisearch-http/src/analytics/segment_analytics.rs +++ b/meilisearch-http/src/analytics/segment_analytics.rs @@ -8,7 +8,10 @@ use actix_web::http::header::USER_AGENT; use actix_web::HttpRequest; use http::header::CONTENT_TYPE; use meilisearch_auth::SearchRules; -use meilisearch_lib::index::{SearchQuery, SearchResult}; +use meilisearch_lib::index::{ + SearchQuery, SearchResult, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER, + DEFAULT_HIGHLIGHT_POST_TAG, DEFAULT_HIGHLIGHT_PRE_TAG, +}; use meilisearch_lib::index_controller::Stats; use meilisearch_lib::MeiliSearch; use once_cell::sync::Lazy; @@ -355,6 +358,13 @@ pub struct SearchAggregator { // pagination max_limit: usize, max_offset: usize, + + // formatting + highlight_pre_tag: bool, + highlight_post_tag: bool, + crop_marker: bool, + matches: bool, + crop_length: bool, } impl SearchAggregator { @@ -405,6 +415,12 @@ impl SearchAggregator { ret.max_limit = query.limit; ret.max_offset = query.offset.unwrap_or_default(); + ret.highlight_pre_tag = query.highlight_pre_tag != DEFAULT_HIGHLIGHT_PRE_TAG; + ret.highlight_post_tag = query.highlight_post_tag != DEFAULT_HIGHLIGHT_POST_TAG; + ret.crop_marker = query.crop_marker != DEFAULT_CROP_MARKER; + ret.crop_length = query.crop_length != DEFAULT_CROP_LENGTH; + ret.matches = query.matches; + ret } @@ -452,6 +468,12 @@ impl SearchAggregator { // pagination self.max_limit = self.max_limit.max(other.max_limit); self.max_offset = self.max_offset.max(other.max_offset); + + self.highlight_pre_tag |= other.highlight_pre_tag; + self.highlight_post_tag |= other.highlight_post_tag; + self.crop_marker |= other.crop_marker; + self.matches |= other.matches; + self.crop_length |= other.crop_length; } pub fn into_event(self, user: &User, event_name: &str) -> Option { @@ -489,6 +511,13 @@ impl SearchAggregator { "max_limit": self.max_limit, "max_offset": self.max_offset, }, + "formatting": { + "highlight_pre_tag": self.highlight_pre_tag, + "highlight_post_tag": self.highlight_post_tag, + "crop_marker": self.crop_marker, + "matches": self.matches, + "crop_length": self.crop_length, + }, }); Some(Track { diff --git a/meilisearch-lib/src/index/mod.rs b/meilisearch-lib/src/index/mod.rs index cbeeffdfd..3a42b2617 100644 --- a/meilisearch-lib/src/index/mod.rs +++ b/meilisearch-lib/src/index/mod.rs @@ -1,6 +1,7 @@ pub use search::{ default_crop_length, default_crop_marker, default_highlight_post_tag, - default_highlight_pre_tag, SearchQuery, SearchResult, DEFAULT_SEARCH_LIMIT, + default_highlight_pre_tag, SearchQuery, SearchResult, DEFAULT_CROP_LENGTH, DEFAULT_CROP_MARKER, + DEFAULT_HIGHLIGHT_POST_TAG, DEFAULT_HIGHLIGHT_PRE_TAG, DEFAULT_SEARCH_LIMIT, }; pub use updates::{apply_settings_to_builder, Checked, Facets, Settings, Unchecked}; diff --git a/meilisearch-lib/src/index/search.rs b/meilisearch-lib/src/index/search.rs index c63be6aab..c628980d2 100644 --- a/meilisearch-lib/src/index/search.rs +++ b/meilisearch-lib/src/index/search.rs @@ -35,17 +35,17 @@ pub const fn default_crop_length() -> usize { DEFAULT_CROP_LENGTH } -const DEFAULT_CROP_MARKER: &str = "…"; +pub const DEFAULT_CROP_MARKER: &str = "…"; pub fn default_crop_marker() -> String { DEFAULT_CROP_MARKER.to_string() } -const DEFAULT_HIGHLIGHT_PRE_TAG: &str = ""; +pub const DEFAULT_HIGHLIGHT_PRE_TAG: &str = ""; pub fn default_highlight_pre_tag() -> String { DEFAULT_HIGHLIGHT_PRE_TAG.to_string() } -const DEFAULT_HIGHLIGHT_POST_TAG: &str = ""; +pub const DEFAULT_HIGHLIGHT_POST_TAG: &str = ""; pub fn default_highlight_post_tag() -> String { DEFAULT_HIGHLIGHT_POST_TAG.to_string() }