Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(search): add highlight support for owner fields (#597)
Will Hutchinson874535821c9a
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 0af2e7579f..e893a2ed1f 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -5960,9 +5960,9 @@ dependencies = [[[package]]name = "opensearch_query_builder"-version = "0.2.2"+version = "0.2.4"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "3f4d171bfc21961e61231a8b8f7b06d34befb4152627d1c6b591aadd621c4681"+checksum = "2be0ec85f59a03d8bc068a79c4397f48695d89d6129a3bfec8712b378bc5b73c"dependencies = ["serde","serde_json",diff --git a/rust/cloud-storage/models_search/src/lib.rs b/rust/cloud-storage/models_search/src/lib.rsindex 15ee2febbf..dca80980d9 100644--- a/rust/cloud-storage/models_search/src/lib.rs+++ b/rust/cloud-storage/models_search/src/lib.rs@@ -102,6 +102,21 @@ pub struct SearchHighlight {/// The highlight match on the content field#[serde(default, skip_serializing_if = "Vec::is_empty")]pub content: Vec<String>,+ /// The highlight match on the user (owner) of the entity+ #[serde(skip_serializing_if = "Option::is_none")]+ pub user_id: Option<String>,+ /// The highlight match on the sender (email only)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub sender: Option<String>,+ /// The highlight match on the recipients (email only)+ #[serde(skip_serializing_if = "Vec::is_empty", default)]+ pub recipients: Vec<String>,+ /// The highlight match on the cc (email only)+ #[serde(skip_serializing_if = "Vec::is_empty", default)]+ pub cc: Vec<String>,+ /// The highlight match on the bcc (email only)+ #[serde(skip_serializing_if = "Vec::is_empty", default)]+ pub bcc: Vec<String>,}impl From<opensearch_client::search::model::Highlight> for SearchHighlight {@@ -109,6 +124,11 @@ impl From<opensearch_client::search::model::Highlight> for SearchHighlight {Self {name: highlight.name,content: highlight.content,+ user_id: highlight.user_id,+ sender: highlight.sender,+ recipients: highlight.recipients,+ cc: highlight.cc,+ bcc: highlight.bcc,}}}diff --git a/rust/cloud-storage/opensearch_client/Cargo.toml b/rust/cloud-storage/opensearch_client/Cargo.tomlindex 4fea255899..37ba0c8292 100644--- a/rust/cloud-storage/opensearch_client/Cargo.toml+++ b/rust/cloud-storage/opensearch_client/Cargo.toml@@ -15,7 +15,7 @@ uuid = { workspace = true }[dependencies]anyhow = { workspace = true }opensearch = { version = "2.3.0" }-opensearch_query_builder = { version = "0.2.2", default-features = false }+opensearch_query_builder = { version = "0.2.4", default-features = false }serde = { workspace = true }serde_json = { workspace = true }thiserror = { workspace = true }diff --git a/rust/cloud-storage/opensearch_client/src/search/builder.rs b/rust/cloud-storage/opensearch_client/src/search/builder.rsindex 380bfd3622..57d3839cbd 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder.rs@@ -46,6 +46,18 @@ macro_rules! delegate_methods {};}+/// Creates a highlight field+pub(crate) fn create_highlight_field<'a>(+ highlight_type: &'a str,+ number_of_fragments: u32,+) -> HighlightField<'a> {+ HighlightField::new()+ .highlight_type(highlight_type)+ .pre_tags(vec![MacroEm::Open.to_string()])+ .post_tags(vec![MacroEm::Close.to_string()])+ .number_of_fragments(number_of_fragments)+}+pub trait SearchQueryConfig {/// Key for item idconst ID_KEY: &'static str = "entity_id";@@ -78,6 +90,12 @@ pub trait SearchQueryConfig {.number_of_fragments(500),)}++ /// Override this method if you want to add custom owner highlight fields+ /// By default, this will add a user_id highlight field+ fn append_owner_highlights<'a>(highlight: Highlight<'a>) -> Highlight<'a> {+ highlight.field("user_id", create_highlight_field("plain", 1))+ }}#[derive(Default)]@@ -200,49 +218,76 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {inner_bool_query.minimum_should_match(1);- // Create a vec of owner queries for each term- // We want to search over the content **and** the owner here- let mut owner_queries: Vec<QueryType> = Vec::new();-- for term in &self.terms {- let formatted_term = format!("*{}*", term);- owner_queries.push(QueryType::wildcard(T::USER_ID_KEY, formatted_term, true));- }-- // Add the owner queries to the bool query- for owner_query in owner_queries {- inner_bool_query.should(owner_query);- }-- // If the search is on email, we need to add in participants to the query as well- if T::ENTITY_INDEX == SearchEntityType::Emails {- let mut participant_queries: Vec<QueryType> = Vec::new();- for term in &self.terms {- let formatted_term = format!("*{}*", term);- participant_queries.push(QueryType::wildcard(- "sender",- formatted_term.clone(),- true,- ));- participant_queries.push(QueryType::wildcard(- "cc",- formatted_term.clone(),- true,- ));- participant_queries.push(QueryType::wildcard(- "bcc",- formatted_term.clone(),- true,- ));- participant_queries.push(QueryType::wildcard(- "recipients",- formatted_term.clone(),- true,- ));+ // For email search, we want to search over the participants+ // For all other indices we want to search over the owner+ match T::ENTITY_INDEX {+ SearchEntityType::Emails => {+ let mut participant_queries: Vec<QueryType> = Vec::new();+ for term in &self.terms {+ let formatted_term = format!("{}*", term);+ participant_queries.push(+ WildcardQuery::new(+ "sender",+ formatted_term.clone(),+ true,+ Some(5000.0),+ )+ .into(),+ );+ participant_queries.push(+ WildcardQuery::new(+ "cc",+ formatted_term.clone(),+ true,+ Some(5000.0),+ )+ .into(),+ );+ participant_queries.push(+ WildcardQuery::new(+ "bcc",+ formatted_term.clone(),+ true,+ Some(5000.0),+ )+ .into(),+ );+ participant_queries.push(+ WildcardQuery::new(+ "recipients",+ formatted_term.clone(),+ true,+ Some(5000.0),+ )+ .into(),+ );+ }++ for participant_query in participant_queries {+ inner_bool_query.should(participant_query);+ }}-- for participant_query in participant_queries {- inner_bool_query.should(participant_query);+ _ => {+ // Create a vec of owner queries for each term+ // We want to search over the content **and** the owner here+ let mut owner_queries: Vec<QueryType> = Vec::new();+ for term in &self.terms {+ let formatted_term = format!("macro|{}*", term);+ owner_queries.push(+ WildcardQuery::new(+ T::USER_ID_KEY,+ formatted_term,+ true,+ Some(5000.0),+ )+ .into(),+ );+ }++ // Add the owner queries to the bool query+ for owner_query in owner_queries {+ inner_bool_query.should(owner_query);+ }}}@@ -381,7 +426,7 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {search_request.collapse(Collapse::new(T::ID_KEY));}- let highlight = match self.search_on {+ let mut highlight = match self.search_on {SearchOn::Content => T::default_highlight(),SearchOn::Name => Highlight::new().require_field_match(true).field(T::TITLE_KEY,@@ -411,6 +456,8 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {),};+ highlight = T::append_owner_highlights(highlight);+search_request.highlight(highlight);search_request.set_sorts(T::default_sort_types().into());diff --git a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs b/rust/cloud-storage/opensearch_client/src/search/builder/test.rsindex afd173b9a2..dcf48f9073 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder/test.rs@@ -8,6 +8,14 @@ impl SearchQueryConfig for TestSearchConfig {const USER_ID_KEY: &'static str = "test_user_id";const TITLE_KEY: &'static str = "test_title";const ENTITY_INDEX: SearchEntityType = SearchEntityType::Documents;++ fn append_owner_highlights<'a>(+ highlight: opensearch_query_builder::Highlight<'a>,+ ) -> opensearch_query_builder::Highlight<'a> {+ let highlight = highlight.field("test_user_id", create_highlight_field("plain", 1));++ highlight+ }}#[test]@@ -33,7 +41,7 @@ fn test_build_search_request() -> anyhow::Result<()> {"field": "entity_id"},"sort": TestSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),- "highlight": TestSearchConfig::default_highlight().to_json(),+ "highlight": TestSearchConfig::append_owner_highlights(TestSearchConfig::default_highlight()).to_json(),"query": {"bool": {}}@@ -88,6 +96,12 @@ fn test_build_search_request() -> anyhow::Result<()> {"number_of_fragments": 1,"pre_tags": ["<macro_em>"],"post_tags": ["</macro_em>"],+ },+ "test_user_id": {+ "type": "plain",+ "number_of_fragments": 1,+ "pre_tags": ["<macro_em>"],+ "post_tags": ["</macro_em>"],}}},@@ -157,6 +171,12 @@ fn test_build_search_request() -> anyhow::Result<()> {"number_of_fragments": 1,"pre_tags": ["<macro_em>"],"post_tags": ["</macro_em>"],+ },+ "test_user_id": {+ "type": "plain",+ "number_of_fragments": 1,+ "pre_tags": ["<macro_em>"],+ "post_tags": ["</macro_em>"],}}},@@ -198,8 +218,9 @@ fn test_build_bool_query() -> anyhow::Result<()> {{"wildcard": {"test_user_id": {- "value": "*test*",+ "value": "macro|test*","case_insensitive": true,+ "boost": 5000.0}}},@@ -252,8 +273,9 @@ fn test_build_bool_query() -> anyhow::Result<()> {{"wildcard": {"test_user_id": {- "value": "*test*",+ "value": "macro|test*","case_insensitive": true,+ "boost": 5000.0}}},@@ -309,7 +331,8 @@ fn test_build_bool_query() -> anyhow::Result<()> {"wildcard": {"test_user_id": {"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*",+ "boost": 5000.0}}},diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 1efd1ccd6b..4a867cdb94 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -2,7 +2,7 @@ use crate::{Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{- builder::{SearchQueryBuilder, SearchQueryConfig},+ builder::{SearchQueryBuilder, SearchQueryConfig, create_highlight_field},model::{DefaultSearchResponse, NameIndex, SearchGotoChannel, SearchGotoContent, SearchHit,parse_highlight_hit,@@ -55,6 +55,12 @@ impl SearchQueryConfig for ChannelMessageSearchConfig {SortType::Field(FieldSort::new("message_id", SortOrder::Asc)),]}++ fn append_owner_highlights<'a>(+ highlight: opensearch_query_builder::Highlight<'a>,+ ) -> opensearch_query_builder::Highlight<'a> {+ highlight.field("sender_id", create_highlight_field("plain", 1))+ }}#[derive(Default)]diff --git a/rust/cloud-storage/opensearch_client/src/search/channels/test.rs b/rust/cloud-storage/opensearch_client/src/search/channels/test.rsindex 536f17d91e..220cff9c7d 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels/test.rs@@ -22,17 +22,7 @@ fn test_build_search_request() -> anyhow::Result<()> {"field": "entity_id"},"from": 20,- "highlight": {- "fields": {- "content": {- "number_of_fragments": 500,- "post_tags": ["</macro_em>"],- "pre_tags": ["<macro_em>"],- "type": "plain"- }- },- "require_field_match": true- },+ "highlight": ChannelMessageSearchConfig::append_owner_highlights(ChannelMessageSearchConfig::default_highlight()).to_json(),"query": {"bool": {"minimum_should_match": 1,@@ -45,7 +35,8 @@ fn test_build_search_request() -> anyhow::Result<()> {"wildcard": {"sender_id": {"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*",+ "boost": 5000.0}}},diff --git a/rust/cloud-storage/opensearch_client/src/search/chats/test.rs b/rust/cloud-storage/opensearch_client/src/search/chats/test.rsindex a5c70a83ff..771c61d6a2 100644--- a/rust/cloud-storage/opensearch_client/src/search/chats/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/chats/test.rs@@ -22,7 +22,7 @@ fn test_build_search_request() -> anyhow::Result<()> {"field": "entity_id"},"sort": ChatSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),- "highlight": ChatSearchConfig::default_highlight().to_json(),+ "highlight": ChatSearchConfig::append_owner_highlights(ChatSearchConfig::default_highlight()).to_json(),"query": {"bool": {"must": [@@ -33,8 +33,9 @@ fn test_build_search_request() -> anyhow::Result<()> {{"wildcard": {"user_id": {- "value": "*test*",+ "value": "macro|test*","case_insensitive": true,+ "boost": 5000.0}}},diff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rsindex d585a5ef1e..89ab9e8120 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs@@ -2,7 +2,7 @@ use crate::{Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{- builder::{SearchQueryBuilder, SearchQueryConfig},+ builder::{SearchQueryBuilder, SearchQueryConfig, create_highlight_field},model::{DefaultSearchResponse, NameIndex, SearchGotoContent, SearchGotoDocument, SearchHit,parse_highlight_hit,@@ -34,6 +34,12 @@ impl SearchQueryConfig for DocumentSearchConfig {SortType::Field(FieldSort::new("node_id", SortOrder::Asc)),]}++ fn append_owner_highlights<'a>(+ highlight: opensearch_query_builder::Highlight<'a>,+ ) -> opensearch_query_builder::Highlight<'a> {+ highlight.field("owner_id", create_highlight_field("plain", 1))+ }}pub(crate) struct DocumentQueryBuilder {diff --git a/rust/cloud-storage/opensearch_client/src/search/documents/test.rs b/rust/cloud-storage/opensearch_client/src/search/documents/test.rsindex 76f0a976bf..4db3684c90 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents/test.rs@@ -21,7 +21,7 @@ fn test_build_search_request() -> anyhow::Result<()> {"field": "entity_id"},"sort": DocumentSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),- "highlight": DocumentSearchConfig::default_highlight().to_json(),+ "highlight": DocumentSearchConfig::append_owner_highlights(DocumentSearchConfig::default_highlight()).to_json(),"query": {"bool": {"must": [@@ -32,8 +32,9 @@ fn test_build_search_request() -> anyhow::Result<()> {{"wildcard": {"owner_id": {- "value": "*test*",- "case_insensitive": true,+ "value": "macro|test*",+ "case_insensitive": true,+ "boost": 5000.0}}},diff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex 7d9f75f94e..e4bac6d547 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -2,7 +2,7 @@ use crate::{Result, delegate_methods,error::{OpensearchClientError, ResponseExt},search::{- builder::{SearchQueryBuilder, SearchQueryConfig},+ builder::{SearchQueryBuilder, SearchQueryConfig, create_highlight_field},model::{NameIndex, SearchGotoContent, SearchGotoEmail, SearchHit, parse_highlight_hit},query::Keys,utils::should_wildcard_field_query_builder,@@ -32,6 +32,16 @@ impl SearchQueryConfig for EmailSearchConfig {SortType::Field(FieldSort::new(Self::ID_KEY, SortOrder::Asc)),]}++ fn append_owner_highlights<'a>(+ highlight: opensearch_query_builder::Highlight<'a>,+ ) -> opensearch_query_builder::Highlight<'a> {+ let highlight = highlight.field("sender", create_highlight_field("plain", 1));+ let highlight = highlight.field("recipients", create_highlight_field("plain", 1));+ let highlight = highlight.field("cc", create_highlight_field("plain", 1));++ highlight.field("bcc", create_highlight_field("plain", 1))+ }}pub(crate) struct EmailQueryBuilder {diff --git a/rust/cloud-storage/opensearch_client/src/search/emails/test.rs b/rust/cloud-storage/opensearch_client/src/search/emails/test.rsindex 5e265ae022..e6d8cf5a06 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails/test.rs@@ -26,8 +26,8 @@ fn test_build_search_request() -> anyhow::Result<()> {"field": "entity_id"},"sort": EmailSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),- "highlight": EmailSearchConfig::default_highlight().to_json(),- "query": {+ "highlight": EmailSearchConfig::append_owner_highlights(EmailSearchConfig::default_highlight()).to_json(),+ "query": {"bool": {"minimum_should_match": 1,"must": [@@ -35,19 +35,13 @@ fn test_build_search_request() -> anyhow::Result<()> {"bool": {"minimum_should_match": 1,"should": [- {- "wildcard": {- "user_id": {- "case_insensitive": true,- "value": "*test*"- }- }- },{"wildcard": {"sender": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0+}}},@@ -55,7 +49,8 @@ fn test_build_search_request() -> anyhow::Result<()> {"wildcard": {"cc": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},@@ -63,7 +58,8 @@ fn test_build_search_request() -> anyhow::Result<()> {"wildcard": {"bcc": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},@@ -71,7 +67,8 @@ fn test_build_search_request() -> anyhow::Result<()> {"wildcard": {"recipients": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},diff --git a/rust/cloud-storage/opensearch_client/src/search/model.rs b/rust/cloud-storage/opensearch_client/src/search/model.rsindex 782598cb0f..d579f05d56 100644--- a/rust/cloud-storage/opensearch_client/src/search/model.rs+++ b/rust/cloud-storage/opensearch_client/src/search/model.rs@@ -42,13 +42,47 @@ pub struct Highlight {/// The highlight content matches#[serde(skip_serializing_if = "Vec::is_empty")]pub content: Vec<String>,++ /// The highlight match on the user (owner) of the entity+ #[serde(skip_serializing_if = "Option::is_none")]+ pub user_id: Option<String>,+ /// The highlight match on the sender (email only)+ #[serde(skip_serializing_if = "Option::is_none")]+ pub sender: Option<String>,+ /// The highlight match on the recipients (email only)+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub recipients: Vec<String>,+ /// The highlight match on the cc (email only)+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub cc: Vec<String>,+ /// The highlight match on the bcc (email only)+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub bcc: Vec<String>,}pub(crate) fn parse_highlight_hit(highlight: HashMap<String, Vec<String>>,keys: Keys,) -> Highlight {+ // The highlight on the user id+ let user_id = highlight+ .get("user_id")+ .and_then(|v| v.first())+ .map(|v| v.to_string());++ // If the user id is not present we should try the owner_id which is the+ // user field in documents index+ let user_id = if user_id.is_none() {+ highlight+ .get("owner_id")+ .and_then(|v| v.first())+ .map(|v| v.to_string())+ } else {+ user_id+ };+Highlight {+ user_id,name: highlight.get(keys.title_key).and_then(|v| v.first())@@ -57,6 +91,16 @@ pub(crate) fn parse_highlight_hit(.get(keys.content_key).map(|v| v.to_vec()).unwrap_or_default(),+ sender: highlight+ .get("sender")+ .and_then(|v| v.first())+ .map(|v| v.to_string()),+ recipients: highlight+ .get("recipients")+ .map(|v| v.to_vec())+ .unwrap_or_default(),+ cc: highlight.get("cc").map(|v| v.to_vec()).unwrap_or_default(),+ bcc: highlight.get("bcc").map(|v| v.to_vec()).unwrap_or_default(),}}diff --git a/rust/cloud-storage/opensearch_client/src/search/projects/test.rs b/rust/cloud-storage/opensearch_client/src/search/projects/test.rsindex 0b8273a80d..577d11f5d2 100644--- a/rust/cloud-storage/opensearch_client/src/search/projects/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/projects/test.rs@@ -21,7 +21,7 @@ fn test_build_search_request() -> anyhow::Result<()> {"field": "entity_id"},"sort": ProjectSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),- "highlight": ProjectSearchConfig::default_highlight().to_json(),+ "highlight": ProjectSearchConfig::append_owner_highlights(ProjectSearchConfig::default_highlight()).to_json(),"query": {"bool": {"must": [diff --git a/rust/cloud-storage/opensearch_client/src/search/query.rs b/rust/cloud-storage/opensearch_client/src/search/query.rsindex 8f5e6f8064..53ab391f7b 100644--- a/rust/cloud-storage/opensearch_client/src/search/query.rs+++ b/rust/cloud-storage/opensearch_client/src/search/query.rs@@ -117,6 +117,7 @@ pub(crate) fn create_query<'a>(params: CreateQueryParams<'a>) -> QueryType<'a> {field.to_string(),wildcard_pattern,true,+ None,));let mut bool_query = QueryType::bool_query();diff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rsindex 6a523b683f..bba3c00d4e 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs@@ -4,7 +4,7 @@ use crate::{Result,error::{OpensearchClientError, ResponseExt},search::{- builder::SearchQueryConfig,+ builder::{SearchQueryConfig, create_highlight_field},channels::{ChannelMessageIndex, ChannelMessageQueryBuilder, ChannelMessageSearchArgs,ChannelMessageSearchConfig,@@ -468,7 +468,7 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchReques}// Build highlight- let highlight = match args.search_on {+ let mut highlight = match args.search_on {SearchOn::Content => Highlight::new().require_field_match(true).field("content",HighlightField::new()@@ -523,6 +523,20 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchReques}};+ // For content and name content search, we need to add in highlights for the owner+ // fields+ match args.search_on {+ SearchOn::Content | SearchOn::NameContent => {+ highlight = highlight.field("user_id", create_highlight_field("plain", 1));+ highlight = highlight.field("owner_id", create_highlight_field("plain", 1));+ highlight = highlight.field("sender", create_highlight_field("plain", 1));+ highlight = highlight.field("recipients", create_highlight_field("plain", 1));+ highlight = highlight.field("cc", create_highlight_field("plain", 1));+ highlight = highlight.field("bcc", create_highlight_field("plain", 1));+ }+ SearchOn::Name => {}+ }+search_request_builder.highlight(highlight);let query_object = bool_query.build();diff --git a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs b/rust/cloud-storage/opensearch_client/src/search/unified/test.rsindex 113f877081..36a17fd6c9 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs@@ -462,6 +462,42 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"post_tags": ["</macro_em>"],"pre_tags": ["<macro_em>"],"type": "plain"+ },+ "user_id": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "owner_id": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "sender": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "recipients": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "cc": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "bcc": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"}},"require_field_match": true@@ -482,7 +518,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"wildcard": {"owner_id": {"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*",+ "boost": 5000.0}}},@@ -522,19 +559,12 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"bool": {"minimum_should_match": 1,"should": [- {- "wildcard": {- "user_id": {- "case_insensitive": true,- "value": "*test*"- }- }- },{"wildcard": {"sender": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},@@ -542,7 +572,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"wildcard": {"cc": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},@@ -550,7 +581,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"wildcard": {"bcc": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},@@ -558,7 +590,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"wildcard": {"recipients": {"case_insensitive": true,- "value": "*test*"+ "value": "test*",+ "boost": 5000.0}}},@@ -699,7 +732,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"wildcard": {"sender_id": {"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*",+ "boost": 5000.0}}},@@ -753,7 +787,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {"wildcard": {"user_id": {"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*",+ "boost": 5000.0}}},@@ -1126,8 +1161,70 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {let result = build_unified_search_request(&unified_search_args)?;- let expected = serde_json::json!(- {+ let expected = serde_json::json!({+ "collapse": {+ "field": "entity_id"+ },+ "from": 20,+ "highlight": {+ "fields": {+ "bcc": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "cc": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "content": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "name": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "owner_id": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "project_name": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "recipients": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "sender": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "user_id": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ }+ },+ "require_field_match": false+ },"query": {"bool": {"minimum_should_match": 1,@@ -1147,8 +1244,9 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {{"wildcard": {"owner_id": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*"}}},@@ -1169,10 +1267,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1206,10 +1301,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1235,43 +1327,39 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"bool": {"minimum_should_match": 1,"should": [- {- "wildcard": {- "user_id": {- "case_insensitive": true,- "value": "*test*"- }- }- },{"wildcard": {"sender": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "test*"}}},{"wildcard": {"cc": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "test*"}}},{"wildcard": {"bcc": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "test*"}}},{"wildcard": {"recipients": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "test*"}}},@@ -1290,10 +1378,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {},{"terms": {- "link_id": [- "id1",- "id2"- ]+ "link_id": ["id1", "id2"]}},{@@ -1392,10 +1477,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1429,10 +1511,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1461,8 +1540,9 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {{"wildcard": {"sender_id": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*"}}},@@ -1481,36 +1561,24 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {},{"terms": {- "thread_id": [- "id1",- "id2"- ]+ "thread_id": ["id1", "id2"]}},{"terms": {- "mentions": [- "id1",- "id2"- ]+ "mentions": ["id1", "id2"]}},{"terms": {- "sender_id": [- "id1",- "id2"- ]+ "sender_id": ["id1", "id2"]}}],"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}}]@@ -1539,10 +1607,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}}]@@ -1566,8 +1631,9 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {{"wildcard": {"user_id": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*"}}},@@ -1611,10 +1677,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1648,10 +1711,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1680,8 +1740,9 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {{"wildcard": {"user_id": {+ "boost": 5000.0,"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*"}}},@@ -1702,10 +1763,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1734,10 +1792,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"should": [{"terms": {- "entity_id": [- "id1",- "id2"- ]+ "entity_id": ["id1", "id2"]}},{@@ -1754,7 +1809,6 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {]}},- "from": 20,"size": 20,"sort": [{@@ -1763,47 +1817,8 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {{"entity_id": "desc"}- ],- "highlight": {- "require_field_match": false,- "fields": {- "content": {- "type": "plain",- "number_of_fragments": 1,- "pre_tags": [- "<macro_em>"- ],- "post_tags": [- "</macro_em>"- ]- },- "name": {- "type": "plain",- "number_of_fragments": 1,- "pre_tags": [- "<macro_em>"- ],- "post_tags": [- "</macro_em>"- ]- },- "project_name": {- "type": "plain",- "number_of_fragments": 1,- "pre_tags": [- "<macro_em>"- ],- "post_tags": [- "</macro_em>"- ]- }- }- },- "collapse": {- "field": "entity_id"- }- }- );+ ]+ });assert_eq!(result.to_json(), expected);@@ -1848,7 +1863,8 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {"wildcard": {"owner_id": {"case_insensitive": true,- "value": "*test*"+ "value": "macro|test*",+ "boost": 5000.0}}},@@ -1908,6 +1924,42 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {"post_tags": ["</macro_em>"]+ },+ "user_id": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "owner_id": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "sender": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "recipients": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "cc": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"+ },+ "bcc": {+ "number_of_fragments": 1,+ "post_tags": ["</macro_em>"],+ "pre_tags": ["<macro_em>"],+ "type": "plain"}}},diff --git a/rust/cloud-storage/opensearch_client/src/search/utils.rs b/rust/cloud-storage/opensearch_client/src/search/utils.rsindex 711b36bc69..20ee336954 100644--- a/rust/cloud-storage/opensearch_client/src/search/utils.rs+++ b/rust/cloud-storage/opensearch_client/src/search/utils.rs@@ -13,6 +13,7 @@ pub fn should_wildcard_field_query_builder<'a>(field.to_string(),format!("*{}*", value.to_lowercase()),true,+ None,)}).collect();diff --git a/rust/cloud-storage/search_service/src/api/search/channel/test.rs b/rust/cloud-storage/search_service/src/api/search/channel/test.rsindex 143e1ce6d7..38a2957762 100644--- a/rust/cloud-storage/search_service/src/api/search/channel/test.rs+++ b/rust/cloud-storage/search_service/src/api/search/channel/test.rs@@ -31,6 +31,7 @@ fn test_construct_search_result_single_channel() {highlight: Highlight {name: None,content: vec!["Test message content".to_string()],+ ..Default::default()},}];@@ -88,6 +89,7 @@ fn test_construct_search_result_multiple_messages_same_channel() {highlight: Highlight {name: None,content: vec!["First message".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -108,6 +110,7 @@ fn test_construct_search_result_multiple_messages_same_channel() {highlight: Highlight {name: None,content: vec!["Second message".to_string()],+ ..Default::default()},},];@@ -166,6 +169,7 @@ fn test_construct_search_result_filters_messages_without_content() {highlight: Highlight {name: None,content: vec!["Message with content".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -186,6 +190,7 @@ fn test_construct_search_result_filters_messages_without_content() {highlight: Highlight {name: None,content: vec![],+ ..Default::default()},},];@@ -234,6 +239,7 @@ fn create_test_channel_response(highlight: Highlight {name: None,content: content.unwrap_or_default(),+ ..Default::default()},}}@@ -399,6 +405,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["third".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -419,6 +426,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["first".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -439,6 +447,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["fifth".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -459,6 +468,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["second".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -479,6 +489,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["fourth".to_string()],+ ..Default::default()},},];diff --git a/rust/cloud-storage/search_service/src/api/search/chat/test.rs b/rust/cloud-storage/search_service/src/api/search/chat/test.rsindex 3b1be76b29..5ac69b9eed 100644--- a/rust/cloud-storage/search_service/src/api/search/chat/test.rs+++ b/rust/cloud-storage/search_service/src/api/search/chat/test.rs@@ -22,6 +22,7 @@ fn create_test_response(highlight: Highlight {name: None,content: content.unwrap_or_default(),+ ..Default::default()},}}diff --git a/rust/cloud-storage/search_service/src/api/search/document/test.rs b/rust/cloud-storage/search_service/src/api/search/document/test.rsindex 4a3a992a24..f0a7339a42 100644--- a/rust/cloud-storage/search_service/src/api/search/document/test.rs+++ b/rust/cloud-storage/search_service/src/api/search/document/test.rs@@ -27,6 +27,7 @@ fn test_construct_search_result_single_document() {highlight: Highlight {name: None,content: vec!["Test content".to_string()],+ ..Default::default()},}];@@ -95,6 +96,7 @@ fn test_construct_search_result_multiple_nodes_same_document() {highlight: Highlight {name: None,content: vec!["First content".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -112,6 +114,7 @@ fn test_construct_search_result_multiple_nodes_same_document() {highlight: Highlight {name: None,content: vec!["Second content".to_string()],+ ..Default::default()},},];@@ -179,6 +182,7 @@ fn create_test_document_response(highlight: Highlight {name: None,content: content.unwrap_or_default(),+ ..Default::default()},}}@@ -486,6 +490,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["third".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -503,6 +508,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["first".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -520,6 +526,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["fifth".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -537,6 +544,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["second".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -554,6 +562,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["fourth".to_string()],+ ..Default::default()},},];diff --git a/rust/cloud-storage/search_service/src/api/search/email/test.rs b/rust/cloud-storage/search_service/src/api/search/email/test.rsindex b359056f52..abc91ba7f4 100644--- a/rust/cloud-storage/search_service/src/api/search/email/test.rs+++ b/rust/cloud-storage/search_service/src/api/search/email/test.rs@@ -47,6 +47,7 @@ fn test_construct_search_result_single_thread() {highlight: Highlight {name: None,content: vec!["Test content".to_string()],+ ..Default::default()},}];@@ -102,6 +103,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["third".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -122,6 +124,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["first".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -142,6 +145,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["fifth".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -162,6 +166,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["second".to_string()],+ ..Default::default()},},opensearch_client::search::model::SearchHit {@@ -182,6 +187,7 @@ fn test_sort_stability() {highlight: Highlight {name: None,content: vec!["fourth".to_string()],+ ..Default::default()},},];