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 separate highlighting result for name vs content match (#60)
Will Hutchinsonbde1605836e0
diff --git a/rust/cloud-storage/models_search/src/channel.rs b/rust/cloud-storage/models_search/src/channel.rsindex f83d51aba8..ec4aeb4a70 100644--- a/rust/cloud-storage/models_search/src/channel.rs+++ b/rust/cloud-storage/models_search/src/channel.rs@@ -1,4 +1,4 @@-use crate::{MatchType, SearchOn, SearchResponseItem};+use crate::{MatchType, SearchHighlight, SearchOn, SearchResponseItem};use item_filters::ChannelFilters;use schemars::JsonSchema;use serde::{Deserialize, Serialize};@@ -13,8 +13,8 @@ pub struct ChannelSearchResult {pub thread_id: Option<String>,/// The sender idpub sender_id: String,- /// The array of content matches for the channel message- pub content: Vec<String>,+ /// The highlights for the channel message+ pub highlight: SearchHighlight,/// When the channel message was createdpub created_at: i64,/// When the channel message was last updated@@ -134,8 +134,8 @@ pub struct SimpleChannelSearchReponseBaseItem<T> {#[schema(inline)]/// The time the channel message was last updatedpub updated_at: T,- /// The opensearch matches on the channel message- pub content: Option<Vec<String>>,+ /// The highlights on the channel message+ pub highlight: SearchHighlight,}pub type SimpleChannelSearchReponseItem =@@ -156,7 +156,7 @@ impl From<opensearch_client::search::channels::ChannelMessageSearchResponse>mentions: response.mentions,created_at: response.created_at.into(),updated_at: response.updated_at.into(),- content: response.content,+ highlight: response.highlight.into(),}}}@@ -169,264 +169,4 @@ pub struct SimpleChannelSearchResponse {}#[cfg(test)]-mod tests {- use super::*;- use crate::MatchType;-- #[test]- fn test_channel_search_request_json_serialization() {- let request = ChannelSearchRequest {- query: Some("test query".to_string()),- terms: Some(vec!["term1".to_string(), "term2".to_string()]),- match_type: MatchType::Exact,- filters: Some(ChannelFilters {- org_id: Some(12345),- thread_ids: vec!["thread1".to_string(), "thread2".to_string()],- mentions: vec!["@user1".to_string(), "@user2".to_string()],- ..Default::default()- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");- let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","thread_ids":["thread1","thread2"],"mentions":["@user1","@user2"],"org_id":12345,"search_on":"content"}"#;-- assert_eq!(json, expected);- }-- #[test]- fn test_channel_search_request_json_deserialization() {- let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","org_id":12345,"thread_ids":["thread1","thread2"],"mentions":["@user1","@user2"]}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize from JSON");-- assert_eq!(request.query, Some("test query".to_string()));- assert_eq!(- request.terms,- Some(vec!["term1".to_string(), "term2".to_string()])- );- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(request.filters.as_ref().unwrap().org_id, Some(12345));- assert_eq!(- request.filters.as_ref().unwrap().thread_ids,- vec!["thread1".to_string(), "thread2".to_string()]- );- assert_eq!(- request.filters.as_ref().unwrap().mentions,- vec!["@user1".to_string(), "@user2".to_string()]- );- }-- #[test]- fn test_channel_search_request_minimal_json() {- let json = r#"{"match_type":"partial"}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize minimal JSON");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- // With #[serde(flatten)], filters will be Some(ChannelFilters::default()) even when no filter fields are present- assert_eq!(request.filters, Some(ChannelFilters::default()));- }-- #[test]- fn test_channel_search_request_all_match_types() {- let test_cases = vec![- ("exact", MatchType::Exact),- ("partial", MatchType::Partial),- ("query", MatchType::Query),- ];-- for (json_value, expected_match_type) in test_cases {- let json = format!(r#"{{"match_type":"{}"}}"#, json_value);- let request: ChannelSearchRequest = serde_json::from_str(&json)- .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));-- assert_eq!(request.match_type, expected_match_type);- }- }-- #[test]- fn test_channel_search_request_round_trip() {- let original = ChannelSearchRequest {- query: Some("search term".to_string()),- terms: None,- match_type: MatchType::Query,- filters: Some(ChannelFilters {- org_id: Some(99999),- thread_ids: vec!["thread-abc".to_string()],- mentions: vec!["@admin".to_string()],- ..Default::default()- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&original).expect("Failed to serialize");- let deserialized: ChannelSearchRequest =- serde_json::from_str(&json).expect("Failed to deserialize");-- assert_eq!(original.query, deserialized.query);- assert_eq!(original.terms, deserialized.terms);- assert_eq!(original.match_type, deserialized.match_type);- assert_eq!(original.filters, deserialized.filters);- }-- #[test]- fn test_channel_search_request_empty_arrays() {- let json = r#"{"query":"test","terms":[],"match_type":"exact","org_id":0,"thread_ids":[],"mentions":[]}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize empty arrays");-- assert_eq!(request.query, Some("test".to_string()));- assert_eq!(request.terms, Some(vec![]));- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(request.filters.as_ref().unwrap().org_id, Some(0));- assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());- assert!(request.filters.as_ref().unwrap().mentions.is_empty());- }-- #[test]- fn test_channel_search_request_with_org_id_only() {- let json = r#"{"match_type":"partial","org_id":42}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with org_id only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- assert_eq!(request.filters.as_ref().unwrap().org_id, Some(42));- assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());- assert!(request.filters.as_ref().unwrap().mentions.is_empty());- }-- #[test]- fn test_channel_search_request_with_thread_ids_only() {- let json = r#"{"match_type":"exact","thread_ids":["thread-1","thread-2","thread-3"]}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with thread_ids only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(request.filters.as_ref().unwrap().org_id, None);- assert_eq!(- request.filters.as_ref().unwrap().thread_ids,- vec![- "thread-1".to_string(),- "thread-2".to_string(),- "thread-3".to_string()- ]- );- assert!(request.filters.as_ref().unwrap().mentions.is_empty());- }-- #[test]- fn test_channel_search_request_with_mentions_only() {- let json = r#"{"match_type":"query","mentions":["@alice","@bob","@charlie"]}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with mentions only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Query);- assert_eq!(request.filters.as_ref().unwrap().org_id, None);- assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());- assert_eq!(- request.filters.as_ref().unwrap().mentions,- vec![- "@alice".to_string(),- "@bob".to_string(),- "@charlie".to_string()- ]- );- }-- #[test]- fn test_channel_search_request_with_query_and_terms() {- let json =- r#"{"query":"main query","terms":["term1","term2","term3"],"match_type":"query"}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with query and terms");-- assert_eq!(request.query, Some("main query".to_string()));- assert_eq!(- request.terms,- Some(vec![- "term1".to_string(),- "term2".to_string(),- "term3".to_string()- ])- );- assert_eq!(request.match_type, MatchType::Query);- assert_eq!(request.filters, Some(ChannelFilters::default()));- }-- #[test]- fn test_channel_search_request_negative_org_id() {- let json = r#"{"match_type":"exact","org_id":-1}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize negative org_id");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(request.filters.as_ref().unwrap().org_id, Some(-1));- assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());- assert!(request.filters.as_ref().unwrap().mentions.is_empty());- }-- #[test]- fn test_channel_search_request_invalid_match_type() {- let json = r#"{"match_type":"invalid"}"#;-- let result = serde_json::from_str::<ChannelSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize invalid match_type"- );- }-- #[test]- fn test_channel_search_request_missing_required_field() {- let json = r#"{"query":"test"}"#;-- let result = serde_json::from_str::<ChannelSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize without required match_type field"- );- }-- #[test]- fn test_channel_search_request_filters_only() {- let json =- r#"{"match_type":"exact","org_id":123,"thread_ids":["thread1"],"mentions":["@user1"]}"#;-- let request: ChannelSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize filters only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(request.filters.as_ref().unwrap().org_id, Some(123));- assert_eq!(- request.filters.as_ref().unwrap().thread_ids,- vec!["thread1".to_string()]- );- assert_eq!(- request.filters.as_ref().unwrap().mentions,- vec!["@user1".to_string()]- );- }-}+mod test;diff --git a/rust/cloud-storage/models_search/src/channel/test.rs b/rust/cloud-storage/models_search/src/channel/test.rsnew file mode 100644index 0000000000..8ee94174ee--- /dev/null+++ b/rust/cloud-storage/models_search/src/channel/test.rs@@ -0,0 +1,258 @@+use super::*;+use crate::MatchType;++#[test]+fn test_channel_search_request_json_serialization() {+ let request = ChannelSearchRequest {+ query: Some("test query".to_string()),+ terms: Some(vec!["term1".to_string(), "term2".to_string()]),+ match_type: MatchType::Exact,+ filters: Some(ChannelFilters {+ org_id: Some(12345),+ thread_ids: vec!["thread1".to_string(), "thread2".to_string()],+ mentions: vec!["@user1".to_string(), "@user2".to_string()],+ ..Default::default()+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");+ let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","thread_ids":["thread1","thread2"],"mentions":["@user1","@user2"],"org_id":12345,"search_on":"content"}"#;++ assert_eq!(json, expected);+}++#[test]+fn test_channel_search_request_json_deserialization() {+ let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","org_id":12345,"thread_ids":["thread1","thread2"],"mentions":["@user1","@user2"]}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize from JSON");++ assert_eq!(request.query, Some("test query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec!["term1".to_string(), "term2".to_string()])+ );+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(request.filters.as_ref().unwrap().org_id, Some(12345));+ assert_eq!(+ request.filters.as_ref().unwrap().thread_ids,+ vec!["thread1".to_string(), "thread2".to_string()]+ );+ assert_eq!(+ request.filters.as_ref().unwrap().mentions,+ vec!["@user1".to_string(), "@user2".to_string()]+ );+}++#[test]+fn test_channel_search_request_minimal_json() {+ let json = r#"{"match_type":"partial"}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize minimal JSON");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ // With #[serde(flatten)], filters will be Some(ChannelFilters::default()) even when no filter fields are present+ assert_eq!(request.filters, Some(ChannelFilters::default()));+}++#[test]+fn test_channel_search_request_all_match_types() {+ let test_cases = vec![+ ("exact", MatchType::Exact),+ ("partial", MatchType::Partial),+ ("query", MatchType::Query),+ ];++ for (json_value, expected_match_type) in test_cases {+ let json = format!(r#"{{"match_type":"{}"}}"#, json_value);+ let request: ChannelSearchRequest = serde_json::from_str(&json)+ .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));++ assert_eq!(request.match_type, expected_match_type);+ }+}++#[test]+fn test_channel_search_request_round_trip() {+ let original = ChannelSearchRequest {+ query: Some("search term".to_string()),+ terms: None,+ match_type: MatchType::Query,+ filters: Some(ChannelFilters {+ org_id: Some(99999),+ thread_ids: vec!["thread-abc".to_string()],+ mentions: vec!["@admin".to_string()],+ ..Default::default()+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&original).expect("Failed to serialize");+ let deserialized: ChannelSearchRequest =+ serde_json::from_str(&json).expect("Failed to deserialize");++ assert_eq!(original.query, deserialized.query);+ assert_eq!(original.terms, deserialized.terms);+ assert_eq!(original.match_type, deserialized.match_type);+ assert_eq!(original.filters, deserialized.filters);+}++#[test]+fn test_channel_search_request_empty_arrays() {+ let json = r#"{"query":"test","terms":[],"match_type":"exact","org_id":0,"thread_ids":[],"mentions":[]}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize empty arrays");++ assert_eq!(request.query, Some("test".to_string()));+ assert_eq!(request.terms, Some(vec![]));+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(request.filters.as_ref().unwrap().org_id, Some(0));+ assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());+ assert!(request.filters.as_ref().unwrap().mentions.is_empty());+}++#[test]+fn test_channel_search_request_with_org_id_only() {+ let json = r#"{"match_type":"partial","org_id":42}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with org_id only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ assert_eq!(request.filters.as_ref().unwrap().org_id, Some(42));+ assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());+ assert!(request.filters.as_ref().unwrap().mentions.is_empty());+}++#[test]+fn test_channel_search_request_with_thread_ids_only() {+ let json = r#"{"match_type":"exact","thread_ids":["thread-1","thread-2","thread-3"]}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with thread_ids only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(request.filters.as_ref().unwrap().org_id, None);+ assert_eq!(+ request.filters.as_ref().unwrap().thread_ids,+ vec![+ "thread-1".to_string(),+ "thread-2".to_string(),+ "thread-3".to_string()+ ]+ );+ assert!(request.filters.as_ref().unwrap().mentions.is_empty());+}++#[test]+fn test_channel_search_request_with_mentions_only() {+ let json = r#"{"match_type":"query","mentions":["@alice","@bob","@charlie"]}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with mentions only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Query);+ assert_eq!(request.filters.as_ref().unwrap().org_id, None);+ assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());+ assert_eq!(+ request.filters.as_ref().unwrap().mentions,+ vec![+ "@alice".to_string(),+ "@bob".to_string(),+ "@charlie".to_string()+ ]+ );+}++#[test]+fn test_channel_search_request_with_query_and_terms() {+ let json = r#"{"query":"main query","terms":["term1","term2","term3"],"match_type":"query"}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with query and terms");++ assert_eq!(request.query, Some("main query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec![+ "term1".to_string(),+ "term2".to_string(),+ "term3".to_string()+ ])+ );+ assert_eq!(request.match_type, MatchType::Query);+ assert_eq!(request.filters, Some(ChannelFilters::default()));+}++#[test]+fn test_channel_search_request_negative_org_id() {+ let json = r#"{"match_type":"exact","org_id":-1}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize negative org_id");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(request.filters.as_ref().unwrap().org_id, Some(-1));+ assert!(request.filters.as_ref().unwrap().thread_ids.is_empty());+ assert!(request.filters.as_ref().unwrap().mentions.is_empty());+}++#[test]+fn test_channel_search_request_invalid_match_type() {+ let json = r#"{"match_type":"invalid"}"#;++ let result = serde_json::from_str::<ChannelSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize invalid match_type"+ );+}++#[test]+fn test_channel_search_request_missing_required_field() {+ let json = r#"{"query":"test"}"#;++ let result = serde_json::from_str::<ChannelSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize without required match_type field"+ );+}++#[test]+fn test_channel_search_request_filters_only() {+ let json =+ r#"{"match_type":"exact","org_id":123,"thread_ids":["thread1"],"mentions":["@user1"]}"#;++ let request: ChannelSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize filters only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(request.filters.as_ref().unwrap().org_id, Some(123));+ assert_eq!(+ request.filters.as_ref().unwrap().thread_ids,+ vec!["thread1".to_string()]+ );+ assert_eq!(+ request.filters.as_ref().unwrap().mentions,+ vec!["@user1".to_string()]+ );+}diff --git a/rust/cloud-storage/models_search/src/chat.rs b/rust/cloud-storage/models_search/src/chat.rsindex e89fa0e7c5..9f8e9f087e 100644--- a/rust/cloud-storage/models_search/src/chat.rs+++ b/rust/cloud-storage/models_search/src/chat.rs@@ -3,7 +3,7 @@ use schemars::JsonSchema;use serde::{Deserialize, Serialize};use utoipa::ToSchema;-use crate::{MatchType, SearchOn, SearchResponseItem};+use crate::{MatchType, SearchHighlight, SearchOn, SearchResponseItem};/// A chat match for a given message id#[derive(Debug, Serialize, Deserialize, ToSchema)]@@ -12,8 +12,8 @@ pub struct ChatMessageSearchResult {pub chat_message_id: String,/// The role of the chat messagepub role: String,- /// The array of content matches for the message- pub content: Vec<String>,+ /// The highlights for the chat message+ pub highlight: SearchHighlight,/// When the search chat was last updatedpub updated_at: i64,/// The title of the chat@@ -119,8 +119,8 @@ pub struct SimpleChatSearchResponseBaseItem<T> {pub updated_at: T,/// The titlepub title: String,- /// The opensearch matches on the chat- pub content: Option<Vec<String>>,+ /// The highlights on the chat+ pub highlight: SearchHighlight,}pub type SimpleChatSearchResponseItem = SimpleChatSearchResponseBaseItem<crate::TimestampSeconds>;@@ -134,7 +134,7 @@ impl From<opensearch_client::search::chats::ChatSearchResponse> for SimpleChatSerole: response.role,updated_at: response.updated_at.into(),title: response.title,- content: response.content,+ highlight: response.highlight.into(),}}}@@ -147,319 +147,4 @@ pub struct SimpleChatSearchResponse {}#[cfg(test)]-mod tests {- use super::*;- use crate::MatchType;-- #[test]- fn test_chat_search_request_json_serialization() {- let request = ChatSearchRequest {- query: Some("test query".to_string()),- terms: Some(vec!["term1".to_string(), "term2".to_string()]),- match_type: MatchType::Exact,- filters: Some(ChatFilters {- role: vec!["user".to_string(), "system".to_string()],- chat_ids: vec![],- project_ids: vec![],- owners: vec![],- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");- let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","role":["user","system"],"search_on":"content"}"#;-- assert_eq!(json, expected);- }-- #[test]- fn test_chat_search_request_json_deserialization() {- let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","role":["user","system"]}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize from JSON");-- assert_eq!(request.query, Some("test query".to_string()));- assert_eq!(- request.terms,- Some(vec!["term1".to_string(), "term2".to_string()])- );- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().role,- vec!["user".to_string(), "system".to_string()]- );- }-- #[test]- fn test_chat_search_request_minimal_json() {- let json = r#"{"match_type":"partial"}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize minimal JSON");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- // With #[serde(flatten)], filters will be Some(ChatFilters::default()) even when no filter fields are present- assert_eq!(request.filters, Some(ChatFilters::default()));- }-- #[test]- fn test_chat_search_request_all_match_types() {- let test_cases = vec![- ("exact", MatchType::Exact),- ("partial", MatchType::Partial),- ("query", MatchType::Query),- ];-- for (json_value, expected_match_type) in test_cases {- let json = format!(r#"{{"match_type":"{}"}}"#, json_value);- let request: ChatSearchRequest = serde_json::from_str(&json)- .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));-- assert_eq!(request.match_type, expected_match_type);- }- }-- #[test]- fn test_chat_search_request_round_trip() {- let original = ChatSearchRequest {- query: Some("search term".to_string()),- terms: None,- match_type: MatchType::Query,- filters: Some(ChatFilters {- role: vec!["user".to_string()],- chat_ids: vec![],- project_ids: vec![],- owners: vec![],- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&original).expect("Failed to serialize");- let deserialized: ChatSearchRequest =- serde_json::from_str(&json).expect("Failed to deserialize");-- assert_eq!(original.query, deserialized.query);- assert_eq!(original.terms, deserialized.terms);- assert_eq!(original.match_type, deserialized.match_type);- assert_eq!(original.filters, deserialized.filters);- }-- #[test]- fn test_chat_search_request_empty_arrays() {- let json = r#"{"query":"test","terms":[],"match_type":"exact","role":[]}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize empty arrays");-- assert_eq!(request.query, Some("test".to_string()));- assert_eq!(request.terms, Some(vec![]));- assert_eq!(request.match_type, MatchType::Exact);- assert!(request.filters.as_ref().unwrap().role.is_empty());- }-- #[test]- fn test_chat_search_request_with_role_only() {- let json = r#"{"match_type":"partial","role":["user","assistant","system"]}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with role only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- assert_eq!(- request.filters.as_ref().unwrap().role,- vec![- "user".to_string(),- "assistant".to_string(),- "system".to_string()- ]- );- }-- #[test]- fn test_chat_search_request_with_query_and_terms() {- let json =- r#"{"query":"main query","terms":["term1","term2","term3"],"match_type":"query"}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with query and terms");-- assert_eq!(request.query, Some("main query".to_string()));- assert_eq!(- request.terms,- Some(vec![- "term1".to_string(),- "term2".to_string(),- "term3".to_string()- ])- );- assert_eq!(request.match_type, MatchType::Query);- assert_eq!(request.filters, Some(ChatFilters::default()));- }-- #[test]- fn test_chat_search_request_user_role_only() {- let json = r#"{"match_type":"exact","role":["user"]}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize user role only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().role,- vec!["user".to_string()]- );- }-- #[test]- fn test_chat_search_request_invalid_match_type() {- let json = r#"{"match_type":"invalid"}"#;-- let result = serde_json::from_str::<ChatSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize invalid match_type"- );- }-- #[test]- fn test_chat_search_request_missing_required_field() {- let json = r#"{"query":"test"}"#;-- let result = serde_json::from_str::<ChatSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize without required match_type field"- );- }-- #[test]- fn test_chat_search_request_filters_only() {- let json = r#"{"match_type":"exact","role":["user","assistant"]}"#;-- let request: ChatSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize filters only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().role,- vec!["user".to_string(), "assistant".to_string()]- );- }-- #[test]- fn test_search_response_item_to_chat_response_item_with_metadata() {- let search_item = SearchResponseItem {- results: vec![- ChatMessageSearchResult {- chat_message_id: "msg_1".to_string(),- role: "user".to_string(),- content: vec!["hello".to_string()],- updated_at: 1234567890,- title: "Test".to_string(),- },- ChatMessageSearchResult {- chat_message_id: "msg_2".to_string(),- role: "assistant".to_string(),- content: vec!["world".to_string()],- updated_at: 1234567891,- title: "Test".to_string(),- },- ],- metadata: ChatSearchMetadata {- chat_id: "chat_123".to_string(),- user_id: "user_456".to_string(),- title: "hello".to_string(),- },- };-- let chat_response: ChatSearchResponseItem = search_item.into();-- assert_eq!(chat_response.chat_id, "chat_123");- assert_eq!(chat_response.id, "chat_123");- assert_eq!(chat_response.user_id, "user_456");- assert_eq!(chat_response.owner_id, "user_456");- assert_eq!(chat_response.name, "hello");- assert_eq!(chat_response.chat_search_results.len(), 2);- assert_eq!(- chat_response.chat_search_results[0].chat_message_id,- "msg_1"- );- assert_eq!(- chat_response.chat_search_results[1].chat_message_id,- "msg_2"- );- }-- #[test]- fn test_serialization_equivalence() {- // Create a ChatSearchResponseItem directly- let direct_response = ChatSearchResponseItem {- id: "chat_123".to_string(),- name: "hello".to_string(),- owner_id: "user_456".to_string(),- chat_id: "chat_123".to_string(),- user_id: "user_456".to_string(),- chat_search_results: vec![ChatMessageSearchResult {- chat_message_id: "msg_1".to_string(),- role: "user".to_string(),- content: vec!["test content".to_string()],- updated_at: 1234567890,- title: "Test Chat".to_string(),- }],- };-- // Create the same thing via SearchResponseItem conversion- let search_item = SearchResponseItem {- results: vec![ChatMessageSearchResult {- chat_message_id: "msg_1".to_string(),- role: "user".to_string(),- content: vec!["test content".to_string()],- updated_at: 1234567890,- title: "Test Chat".to_string(),- }],- metadata: ChatSearchMetadata {- chat_id: "chat_123".to_string(),- user_id: "user_456".to_string(),- title: "hello".to_string(),- },- };- let converted_response: ChatSearchResponseItem = search_item.into();-- // Serialize both- let direct_json = serde_json::to_string(&direct_response).unwrap();- let converted_json = serde_json::to_string(&converted_response).unwrap();-- // They should be identical- assert_eq!(direct_json, converted_json);-- // Also test that we can deserialize both back to the same thing- let direct_deserialized: ChatSearchResponseItem =- serde_json::from_str(&direct_json).unwrap();- let converted_deserialized: ChatSearchResponseItem =- serde_json::from_str(&converted_json).unwrap();-- assert_eq!(direct_deserialized.chat_id, converted_deserialized.chat_id);- assert_eq!(direct_deserialized.id, converted_deserialized.id);- assert_eq!(direct_deserialized.name, converted_deserialized.name);- assert_eq!(direct_deserialized.user_id, converted_deserialized.user_id);- assert_eq!(- direct_deserialized.owner_id,- converted_deserialized.owner_id- );- assert_eq!(- direct_deserialized.chat_search_results.len(),- converted_deserialized.chat_search_results.len()- );- }-}+mod test;diff --git a/rust/cloud-storage/models_search/src/chat/test.rs b/rust/cloud-storage/models_search/src/chat/test.rsnew file mode 100644index 0000000000..623393a7a1--- /dev/null+++ b/rust/cloud-storage/models_search/src/chat/test.rs@@ -0,0 +1,312 @@+use super::*;+use crate::MatchType;++#[test]+fn test_chat_search_request_json_serialization() {+ let request = ChatSearchRequest {+ query: Some("test query".to_string()),+ terms: Some(vec!["term1".to_string(), "term2".to_string()]),+ match_type: MatchType::Exact,+ filters: Some(ChatFilters {+ role: vec!["user".to_string(), "system".to_string()],+ chat_ids: vec![],+ project_ids: vec![],+ owners: vec![],+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");+ let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","role":["user","system"],"search_on":"content"}"#;++ assert_eq!(json, expected);+}++#[test]+fn test_chat_search_request_json_deserialization() {+ let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","role":["user","system"]}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize from JSON");++ assert_eq!(request.query, Some("test query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec!["term1".to_string(), "term2".to_string()])+ );+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().role,+ vec!["user".to_string(), "system".to_string()]+ );+}++#[test]+fn test_chat_search_request_minimal_json() {+ let json = r#"{"match_type":"partial"}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize minimal JSON");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ // With #[serde(flatten)], filters will be Some(ChatFilters::default()) even when no filter fields are present+ assert_eq!(request.filters, Some(ChatFilters::default()));+}++#[test]+fn test_chat_search_request_all_match_types() {+ let test_cases = vec![+ ("exact", MatchType::Exact),+ ("partial", MatchType::Partial),+ ("query", MatchType::Query),+ ];++ for (json_value, expected_match_type) in test_cases {+ let json = format!(r#"{{"match_type":"{}"}}"#, json_value);+ let request: ChatSearchRequest = serde_json::from_str(&json)+ .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));++ assert_eq!(request.match_type, expected_match_type);+ }+}++#[test]+fn test_chat_search_request_round_trip() {+ let original = ChatSearchRequest {+ query: Some("search term".to_string()),+ terms: None,+ match_type: MatchType::Query,+ filters: Some(ChatFilters {+ role: vec!["user".to_string()],+ chat_ids: vec![],+ project_ids: vec![],+ owners: vec![],+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&original).expect("Failed to serialize");+ let deserialized: ChatSearchRequest =+ serde_json::from_str(&json).expect("Failed to deserialize");++ assert_eq!(original.query, deserialized.query);+ assert_eq!(original.terms, deserialized.terms);+ assert_eq!(original.match_type, deserialized.match_type);+ assert_eq!(original.filters, deserialized.filters);+}++#[test]+fn test_chat_search_request_empty_arrays() {+ let json = r#"{"query":"test","terms":[],"match_type":"exact","role":[]}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize empty arrays");++ assert_eq!(request.query, Some("test".to_string()));+ assert_eq!(request.terms, Some(vec![]));+ assert_eq!(request.match_type, MatchType::Exact);+ assert!(request.filters.as_ref().unwrap().role.is_empty());+}++#[test]+fn test_chat_search_request_with_role_only() {+ let json = r#"{"match_type":"partial","role":["user","assistant","system"]}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with role only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ assert_eq!(+ request.filters.as_ref().unwrap().role,+ vec![+ "user".to_string(),+ "assistant".to_string(),+ "system".to_string()+ ]+ );+}++#[test]+fn test_chat_search_request_with_query_and_terms() {+ let json = r#"{"query":"main query","terms":["term1","term2","term3"],"match_type":"query"}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with query and terms");++ assert_eq!(request.query, Some("main query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec![+ "term1".to_string(),+ "term2".to_string(),+ "term3".to_string()+ ])+ );+ assert_eq!(request.match_type, MatchType::Query);+ assert_eq!(request.filters, Some(ChatFilters::default()));+}++#[test]+fn test_chat_search_request_user_role_only() {+ let json = r#"{"match_type":"exact","role":["user"]}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize user role only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().role,+ vec!["user".to_string()]+ );+}++#[test]+fn test_chat_search_request_invalid_match_type() {+ let json = r#"{"match_type":"invalid"}"#;++ let result = serde_json::from_str::<ChatSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize invalid match_type"+ );+}++#[test]+fn test_chat_search_request_missing_required_field() {+ let json = r#"{"query":"test"}"#;++ let result = serde_json::from_str::<ChatSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize without required match_type field"+ );+}++#[test]+fn test_chat_search_request_filters_only() {+ let json = r#"{"match_type":"exact","role":["user","assistant"]}"#;++ let request: ChatSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize filters only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().role,+ vec!["user".to_string(), "assistant".to_string()]+ );+}++#[test]+fn test_search_response_item_to_chat_response_item_with_metadata() {+ let search_item = SearchResponseItem {+ results: vec![+ ChatMessageSearchResult {+ chat_message_id: "msg_1".to_string(),+ role: "user".to_string(),+ highlight: SearchHighlight::default(),+ updated_at: 1234567890,+ title: "Test".to_string(),+ },+ ChatMessageSearchResult {+ chat_message_id: "msg_2".to_string(),+ role: "assistant".to_string(),+ highlight: SearchHighlight::default(),+ updated_at: 1234567891,+ title: "Test".to_string(),+ },+ ],+ metadata: ChatSearchMetadata {+ chat_id: "chat_123".to_string(),+ user_id: "user_456".to_string(),+ title: "hello".to_string(),+ },+ };++ let chat_response: ChatSearchResponseItem = search_item.into();++ assert_eq!(chat_response.chat_id, "chat_123");+ assert_eq!(chat_response.id, "chat_123");+ assert_eq!(chat_response.user_id, "user_456");+ assert_eq!(chat_response.owner_id, "user_456");+ assert_eq!(chat_response.name, "hello");+ assert_eq!(chat_response.chat_search_results.len(), 2);+ assert_eq!(+ chat_response.chat_search_results[0].chat_message_id,+ "msg_1"+ );+ assert_eq!(+ chat_response.chat_search_results[1].chat_message_id,+ "msg_2"+ );+}++#[test]+fn test_serialization_equivalence() {+ // Create a ChatSearchResponseItem directly+ let direct_response = ChatSearchResponseItem {+ id: "chat_123".to_string(),+ name: "hello".to_string(),+ owner_id: "user_456".to_string(),+ chat_id: "chat_123".to_string(),+ user_id: "user_456".to_string(),+ chat_search_results: vec![ChatMessageSearchResult {+ chat_message_id: "msg_1".to_string(),+ role: "user".to_string(),+ highlight: SearchHighlight::default(),+ updated_at: 1234567890,+ title: "Test Chat".to_string(),+ }],+ };++ // Create the same thing via SearchResponseItem conversion+ let search_item = SearchResponseItem {+ results: vec![ChatMessageSearchResult {+ chat_message_id: "msg_1".to_string(),+ role: "user".to_string(),+ highlight: SearchHighlight::default(),+ updated_at: 1234567890,+ title: "Test Chat".to_string(),+ }],+ metadata: ChatSearchMetadata {+ chat_id: "chat_123".to_string(),+ user_id: "user_456".to_string(),+ title: "hello".to_string(),+ },+ };+ let converted_response: ChatSearchResponseItem = search_item.into();++ // Serialize both+ let direct_json = serde_json::to_string(&direct_response).unwrap();+ let converted_json = serde_json::to_string(&converted_response).unwrap();++ // They should be identical+ assert_eq!(direct_json, converted_json);++ // Also test that we can deserialize both back to the same thing+ let direct_deserialized: ChatSearchResponseItem = serde_json::from_str(&direct_json).unwrap();+ let converted_deserialized: ChatSearchResponseItem =+ serde_json::from_str(&converted_json).unwrap();++ assert_eq!(direct_deserialized.chat_id, converted_deserialized.chat_id);+ assert_eq!(direct_deserialized.id, converted_deserialized.id);+ assert_eq!(direct_deserialized.name, converted_deserialized.name);+ assert_eq!(direct_deserialized.user_id, converted_deserialized.user_id);+ assert_eq!(+ direct_deserialized.owner_id,+ converted_deserialized.owner_id+ );+ assert_eq!(+ direct_deserialized.chat_search_results.len(),+ converted_deserialized.chat_search_results.len()+ );+}diff --git a/rust/cloud-storage/models_search/src/document.rs b/rust/cloud-storage/models_search/src/document.rsindex c2c2bc2768..fb61ae74b7 100644--- a/rust/cloud-storage/models_search/src/document.rs+++ b/rust/cloud-storage/models_search/src/document.rs@@ -3,7 +3,7 @@ use schemars::JsonSchema;use serde::{Deserialize, Serialize};use utoipa::ToSchema;-use crate::{MatchType, SearchOn, SearchResponseItem};+use crate::{MatchType, SearchHighlight, SearchOn, SearchResponseItem};/// A document match for a given node#[derive(Debug, Serialize, Deserialize, ToSchema)]@@ -11,8 +11,8 @@ pub struct DocumentSearchResult {/// The node id for the document./// This is only useful for markdown at the momentpub node_id: String,- /// The array of content matches for the document- pub content: Vec<String>,+ /// The highlights for the document+ pub highlight: SearchHighlight,/// The raw content of the document./// This is only included for markdown files and will be the raw json node of the matchpub raw_content: Option<String>,@@ -104,8 +104,8 @@ pub struct SimpleDocumentSearchResponseBaseItem<T> {#[schema(inline)]/// The time the document was last updatedpub updated_at: T,- /// The opensearch matches on the document- pub content: Option<Vec<String>>,+ /// The highlights on the document+ pub highlight: SearchHighlight,/// The raw content of the documentpub raw_content: Option<String>,}@@ -124,7 +124,7 @@ impl From<opensearch_client::search::documents::DocumentSearchResponse>owner_id: response.owner_id,file_type: response.file_type,updated_at: response.updated_at.into(),- content: response.content,+ highlight: response.highlight.into(),raw_content: response.raw_content,}}@@ -166,193 +166,4 @@ pub struct MarkdownParseResult {}#[cfg(test)]-mod tests {- use super::*;- use crate::MatchType;-- #[test]- fn test_document_search_request_json_serialization() {- let request = DocumentSearchRequest {- query: Some("test query".to_string()),- terms: Some(vec!["term1".to_string(), "term2".to_string()]),- match_type: MatchType::Exact,- filters: Some(DocumentFilters {- file_types: vec!["pdf".to_string(), "docx".to_string()],- document_ids: vec![],- project_ids: vec![],- owners: vec![],- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");- let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","file_types":["pdf","docx"],"search_on":"content"}"#;-- assert_eq!(json, expected);- }-- #[test]- fn test_document_search_request_json_deserialization() {- let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","file_types":["pdf","docx"]}"#;-- let request: DocumentSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize from JSON");-- assert_eq!(request.query, Some("test query".to_string()));- assert_eq!(- request.terms,- Some(vec!["term1".to_string(), "term2".to_string()])- );- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().file_types,- vec!["pdf".to_string(), "docx".to_string()]- );- }-- #[test]- fn test_document_search_request_minimal_json() {- let json = r#"{"match_type":"partial"}"#;-- let request: DocumentSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize minimal JSON");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- // With #[serde(flatten)], filters will be Some(DocumentFilters::default()) even when no filter fields are present- assert_eq!(request.filters, Some(DocumentFilters::default()));- }-- #[test]- fn test_document_search_request_all_match_types() {- let test_cases = vec![- ("exact", MatchType::Exact),- ("partial", MatchType::Partial),- ("query", MatchType::Query),- ];-- for (json_value, expected_match_type) in test_cases {- let json = format!(r#"{{"match_type":"{}"}}"#, json_value);- let request: DocumentSearchRequest = serde_json::from_str(&json)- .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));-- assert_eq!(request.match_type, expected_match_type);- }- }-- #[test]- fn test_document_search_request_round_trip() {- let original = DocumentSearchRequest {- query: Some("search term".to_string()),- terms: None,- match_type: MatchType::Query,- filters: Some(DocumentFilters {- file_types: vec!["txt".to_string(), "md".to_string()],- document_ids: vec![],- project_ids: vec![],- owners: vec![],- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&original).expect("Failed to serialize");- let deserialized: DocumentSearchRequest =- serde_json::from_str(&json).expect("Failed to deserialize");-- assert_eq!(original.query, deserialized.query);- assert_eq!(original.terms, deserialized.terms);- assert_eq!(original.match_type, deserialized.match_type);- assert_eq!(original.filters, deserialized.filters);- }-- #[test]- fn test_document_search_request_empty_arrays() {- let json = r#"{"query":"test","terms":[],"match_type":"exact","file_types":[]}"#;-- let request: DocumentSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize empty arrays");-- assert_eq!(request.query, Some("test".to_string()));- assert_eq!(request.terms, Some(vec![]));- assert_eq!(request.match_type, MatchType::Exact);- assert!(request.filters.as_ref().unwrap().file_types.is_empty());- }-- #[test]- fn test_document_search_request_with_file_types_only() {- let json = r#"{"match_type":"partial","file_types":["pdf","docx","txt"]}"#;-- let request: DocumentSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with file_types only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- assert_eq!(- request.filters.as_ref().unwrap().file_types,- vec!["pdf".to_string(), "docx".to_string(), "txt".to_string()]- );- }-- #[test]- fn test_document_search_request_with_query_and_terms() {- let json =- r#"{"query":"main query","terms":["term1","term2","term3"],"match_type":"query"}"#;-- let request: DocumentSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize with query and terms");-- assert_eq!(request.query, Some("main query".to_string()));- assert_eq!(- request.terms,- Some(vec![- "term1".to_string(),- "term2".to_string(),- "term3".to_string()- ])- );- assert_eq!(request.match_type, MatchType::Query);- assert_eq!(request.filters, Some(DocumentFilters::default()));- }-- #[test]- fn test_document_search_request_invalid_match_type() {- let json = r#"{"match_type":"invalid"}"#;-- let result = serde_json::from_str::<DocumentSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize invalid match_type"- );- }-- #[test]- fn test_document_search_request_missing_required_field() {- let json = r#"{"query":"test"}"#;-- let result = serde_json::from_str::<DocumentSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize without required match_type field"- );- }-- #[test]- fn test_document_search_request_filters_only() {- let json = r#"{"match_type":"exact","file_types":["pdf"]}"#;-- let request: DocumentSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize filters only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().file_types,- vec!["pdf".to_string()]- );- }-}+mod test;diff --git a/rust/cloud-storage/models_search/src/document/test.rs b/rust/cloud-storage/models_search/src/document/test.rsnew file mode 100644index 0000000000..a513f34cad--- /dev/null+++ b/rust/cloud-storage/models_search/src/document/test.rs@@ -0,0 +1,187 @@+use super::*;+use crate::MatchType;++#[test]+fn test_document_search_request_json_serialization() {+ let request = DocumentSearchRequest {+ query: Some("test query".to_string()),+ terms: Some(vec!["term1".to_string(), "term2".to_string()]),+ match_type: MatchType::Exact,+ filters: Some(DocumentFilters {+ file_types: vec!["pdf".to_string(), "docx".to_string()],+ document_ids: vec![],+ project_ids: vec![],+ owners: vec![],+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");+ let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","file_types":["pdf","docx"],"search_on":"content"}"#;++ assert_eq!(json, expected);+}++#[test]+fn test_document_search_request_json_deserialization() {+ let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","file_types":["pdf","docx"]}"#;++ let request: DocumentSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize from JSON");++ assert_eq!(request.query, Some("test query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec!["term1".to_string(), "term2".to_string()])+ );+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().file_types,+ vec!["pdf".to_string(), "docx".to_string()]+ );+}++#[test]+fn test_document_search_request_minimal_json() {+ let json = r#"{"match_type":"partial"}"#;++ let request: DocumentSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize minimal JSON");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ // With #[serde(flatten)], filters will be Some(DocumentFilters::default()) even when no filter fields are present+ assert_eq!(request.filters, Some(DocumentFilters::default()));+}++#[test]+fn test_document_search_request_all_match_types() {+ let test_cases = vec![+ ("exact", MatchType::Exact),+ ("partial", MatchType::Partial),+ ("query", MatchType::Query),+ ];++ for (json_value, expected_match_type) in test_cases {+ let json = format!(r#"{{"match_type":"{}"}}"#, json_value);+ let request: DocumentSearchRequest = serde_json::from_str(&json)+ .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));++ assert_eq!(request.match_type, expected_match_type);+ }+}++#[test]+fn test_document_search_request_round_trip() {+ let original = DocumentSearchRequest {+ query: Some("search term".to_string()),+ terms: None,+ match_type: MatchType::Query,+ filters: Some(DocumentFilters {+ file_types: vec!["txt".to_string(), "md".to_string()],+ document_ids: vec![],+ project_ids: vec![],+ owners: vec![],+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&original).expect("Failed to serialize");+ let deserialized: DocumentSearchRequest =+ serde_json::from_str(&json).expect("Failed to deserialize");++ assert_eq!(original.query, deserialized.query);+ assert_eq!(original.terms, deserialized.terms);+ assert_eq!(original.match_type, deserialized.match_type);+ assert_eq!(original.filters, deserialized.filters);+}++#[test]+fn test_document_search_request_empty_arrays() {+ let json = r#"{"query":"test","terms":[],"match_type":"exact","file_types":[]}"#;++ let request: DocumentSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize empty arrays");++ assert_eq!(request.query, Some("test".to_string()));+ assert_eq!(request.terms, Some(vec![]));+ assert_eq!(request.match_type, MatchType::Exact);+ assert!(request.filters.as_ref().unwrap().file_types.is_empty());+}++#[test]+fn test_document_search_request_with_file_types_only() {+ let json = r#"{"match_type":"partial","file_types":["pdf","docx","txt"]}"#;++ let request: DocumentSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with file_types only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ assert_eq!(+ request.filters.as_ref().unwrap().file_types,+ vec!["pdf".to_string(), "docx".to_string(), "txt".to_string()]+ );+}++#[test]+fn test_document_search_request_with_query_and_terms() {+ let json = r#"{"query":"main query","terms":["term1","term2","term3"],"match_type":"query"}"#;++ let request: DocumentSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize with query and terms");++ assert_eq!(request.query, Some("main query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec![+ "term1".to_string(),+ "term2".to_string(),+ "term3".to_string()+ ])+ );+ assert_eq!(request.match_type, MatchType::Query);+ assert_eq!(request.filters, Some(DocumentFilters::default()));+}++#[test]+fn test_document_search_request_invalid_match_type() {+ let json = r#"{"match_type":"invalid"}"#;++ let result = serde_json::from_str::<DocumentSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize invalid match_type"+ );+}++#[test]+fn test_document_search_request_missing_required_field() {+ let json = r#"{"query":"test"}"#;++ let result = serde_json::from_str::<DocumentSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize without required match_type field"+ );+}++#[test]+fn test_document_search_request_filters_only() {+ let json = r#"{"match_type":"exact","file_types":["pdf"]}"#;++ let request: DocumentSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize filters only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().file_types,+ vec!["pdf".to_string()]+ );+}diff --git a/rust/cloud-storage/models_search/src/email.rs b/rust/cloud-storage/models_search/src/email.rsindex eca668b7b8..84549f5bf8 100644--- a/rust/cloud-storage/models_search/src/email.rs+++ b/rust/cloud-storage/models_search/src/email.rs@@ -1,4 +1,4 @@-use crate::{MatchType, SearchOn, SearchResponseItem};+use crate::{MatchType, SearchHighlight, SearchOn, SearchResponseItem};use item_filters::EmailFilters;use schemars::JsonSchema;use serde::{Deserialize, Serialize};@@ -15,8 +15,8 @@ pub struct EmailSearchResult {pub cc: Vec<String>,pub bcc: Vec<String>,pub labels: Vec<String>,- /// The array of content matches for the email message- pub content: Vec<String>,+ /// The highlights for the email message+ pub highlight: SearchHighlight,/// When the search email message was last updatedpub updated_at: i64,/// When the email message was sent@@ -131,8 +131,8 @@ pub struct SimpleEmailSearchResponseBaseItem<T> {pub sent_at: Option<T>,/// The subjectpub subject: Option<String>,- /// The opensearch matches on the email- pub content: Option<Vec<String>>,+ /// The highlights on the email+ pub highlight: SearchHighlight,}pub type SimpleEmailSearchResponseItem = SimpleEmailSearchResponseBaseItem<crate::TimestampSeconds>;@@ -154,7 +154,7 @@ impl From<opensearch_client::search::emails::EmailSearchResponse>updated_at: response.updated_at.into(),sent_at: response.sent_at.map(|t| t.into()),subject: response.subject,- content: response.content,+ highlight: response.highlight.into(),}}}@@ -167,172 +167,4 @@ pub struct SimpleEmailSearchResponse {}#[cfg(test)]-mod tests {- use super::*;- use crate::MatchType;-- #[test]- fn test_email_search_request_json_serialization() {- let request = EmailSearchRequest {- query: Some("test query".to_string()),- terms: Some(vec!["term1".to_string(), "term2".to_string()]),- match_type: MatchType::Exact,- filters: Some(EmailFilters {- senders: vec!["[email protected]".to_string()],- cc: vec!["[email protected]".to_string()],- bcc: vec!["[email protected]".to_string()],- recipients: vec![],- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");- let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","senders":["[email protected]"],"cc":["[email protected]"],"bcc":["[email protected]"],"search_on":"content"}"#;-- assert_eq!(json, expected);- }-- #[test]- fn test_email_search_request_json_deserialization() {- let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","senders":["[email protected]"],"cc":["[email protected]"],"bcc":["[email protected]"]}"#;-- let request: EmailSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize from JSON");-- assert_eq!(request.query, Some("test query".to_string()));- assert_eq!(- request.terms,- Some(vec!["term1".to_string(), "term2".to_string()])- );- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().senders,- vec!["[email protected]".to_string()]- );- assert_eq!(- request.filters.as_ref().unwrap().cc,- vec!["[email protected]".to_string()]- );- assert_eq!(- request.filters.as_ref().unwrap().bcc,- vec!["[email protected]".to_string()]- );- }-- #[test]- fn test_email_search_request_minimal_json() {- let json = r#"{"match_type":"partial"}"#;-- let request: EmailSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize minimal JSON");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Partial);- // With #[serde(flatten)], filters will be Some(EmailFilters::default()) even when no filter fields are present- assert_eq!(request.filters, Some(EmailFilters::default()));- }-- #[test]- fn test_email_search_request_all_match_types() {- let test_cases = vec![- ("exact", MatchType::Exact),- ("partial", MatchType::Partial),- ("query", MatchType::Query),- ];-- for (json_value, expected_match_type) in test_cases {- let json = format!(r#"{{"match_type":"{}"}}"#, json_value);- let request: EmailSearchRequest = serde_json::from_str(&json)- .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));-- assert_eq!(request.match_type, expected_match_type);- }- }-- #[test]- fn test_email_search_request_round_trip() {- let original = EmailSearchRequest {- query: Some("search term".to_string()),- terms: None,- match_type: MatchType::Query,- filters: Some(EmailFilters {- senders: vec![- "[email protected]".to_string(),- "[email protected]".to_string(),- ],- cc: vec![],- bcc: vec!["[email protected]".to_string()],- recipients: vec![],- }),- search_on: SearchOn::Content,- collapse: None,- };-- let json = serde_json::to_string(&original).expect("Failed to serialize");- let deserialized: EmailSearchRequest =- serde_json::from_str(&json).expect("Failed to deserialize");-- assert_eq!(original.query, deserialized.query);- assert_eq!(original.terms, deserialized.terms);- assert_eq!(original.match_type, deserialized.match_type);- assert_eq!(original.filters, deserialized.filters);- }-- #[test]- fn test_email_search_request_empty_arrays() {- let json =- r#"{"query":"test","terms":[],"match_type":"exact","senders":[],"cc":[],"bcc":[]}"#;-- let request: EmailSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize empty arrays");-- assert_eq!(request.query, Some("test".to_string()));- assert_eq!(request.terms, Some(vec![]));- assert_eq!(request.match_type, MatchType::Exact);- assert!(request.filters.as_ref().unwrap().senders.is_empty());- assert!(request.filters.as_ref().unwrap().bcc.is_empty());- assert!(request.filters.as_ref().unwrap().cc.is_empty());- }-- #[test]- fn test_email_search_request_invalid_match_type() {- let json = r#"{"match_type":"invalid"}"#;-- let result = serde_json::from_str::<EmailSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize invalid match_type"- );- }-- #[test]- fn test_email_search_request_missing_required_field() {- let json = r#"{"query":"test"}"#;-- let result = serde_json::from_str::<EmailSearchRequest>(json);- assert!(- result.is_err(),- "Should fail to deserialize without required match_type field"- );- }-- #[test]- fn test_email_search_request_filters_only() {- let json = r#"{"match_type":"exact","senders":["[email protected]"]}"#;-- let request: EmailSearchRequest =- serde_json::from_str(json).expect("Failed to deserialize filters only");-- assert_eq!(request.query, None);- assert_eq!(request.terms, None);- assert_eq!(request.match_type, MatchType::Exact);- assert_eq!(- request.filters.as_ref().unwrap().senders,- vec!["[email protected]".to_string()]- );- assert!(request.filters.as_ref().unwrap().cc.is_empty());- assert!(request.filters.as_ref().unwrap().bcc.is_empty());- }-}+mod test;diff --git a/rust/cloud-storage/models_search/src/email/test.rs b/rust/cloud-storage/models_search/src/email/test.rsnew file mode 100644index 0000000000..cc353de786--- /dev/null+++ b/rust/cloud-storage/models_search/src/email/test.rs@@ -0,0 +1,166 @@+use super::*;+use crate::MatchType;++#[test]+fn test_email_search_request_json_serialization() {+ let request = EmailSearchRequest {+ query: Some("test query".to_string()),+ terms: Some(vec!["term1".to_string(), "term2".to_string()]),+ match_type: MatchType::Exact,+ filters: Some(EmailFilters {+ senders: vec!["[email protected]".to_string()],+ cc: vec!["[email protected]".to_string()],+ bcc: vec!["[email protected]".to_string()],+ recipients: vec![],+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&request).expect("Failed to serialize to JSON");+ let expected = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","senders":["[email protected]"],"cc":["[email protected]"],"bcc":["[email protected]"],"search_on":"content"}"#;++ assert_eq!(json, expected);+}++#[test]+fn test_email_search_request_json_deserialization() {+ let json = r#"{"query":"test query","terms":["term1","term2"],"match_type":"exact","senders":["[email protected]"],"cc":["[email protected]"],"bcc":["[email protected]"]}"#;++ let request: EmailSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize from JSON");++ assert_eq!(request.query, Some("test query".to_string()));+ assert_eq!(+ request.terms,+ Some(vec!["term1".to_string(), "term2".to_string()])+ );+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().senders,+ vec!["[email protected]".to_string()]+ );+ assert_eq!(+ request.filters.as_ref().unwrap().cc,+ vec!["[email protected]".to_string()]+ );+ assert_eq!(+ request.filters.as_ref().unwrap().bcc,+ vec!["[email protected]".to_string()]+ );+}++#[test]+fn test_email_search_request_minimal_json() {+ let json = r#"{"match_type":"partial"}"#;++ let request: EmailSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize minimal JSON");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Partial);+ // With #[serde(flatten)], filters will be Some(EmailFilters::default()) even when no filter fields are present+ assert_eq!(request.filters, Some(EmailFilters::default()));+}++#[test]+fn test_email_search_request_all_match_types() {+ let test_cases = vec![+ ("exact", MatchType::Exact),+ ("partial", MatchType::Partial),+ ("query", MatchType::Query),+ ];++ for (json_value, expected_match_type) in test_cases {+ let json = format!(r#"{{"match_type":"{}"}}"#, json_value);+ let request: EmailSearchRequest = serde_json::from_str(&json)+ .unwrap_or_else(|_| panic!("Failed to deserialize match_type: {}", json_value));++ assert_eq!(request.match_type, expected_match_type);+ }+}++#[test]+fn test_email_search_request_round_trip() {+ let original = EmailSearchRequest {+ query: Some("search term".to_string()),+ terms: None,+ match_type: MatchType::Query,+ filters: Some(EmailFilters {+ senders: vec![+ "[email protected]".to_string(),+ "[email protected]".to_string(),+ ],+ cc: vec![],+ bcc: vec!["[email protected]".to_string()],+ recipients: vec![],+ }),+ search_on: SearchOn::Content,+ collapse: None,+ };++ let json = serde_json::to_string(&original).expect("Failed to serialize");+ let deserialized: EmailSearchRequest =+ serde_json::from_str(&json).expect("Failed to deserialize");++ assert_eq!(original.query, deserialized.query);+ assert_eq!(original.terms, deserialized.terms);+ assert_eq!(original.match_type, deserialized.match_type);+ assert_eq!(original.filters, deserialized.filters);+}++#[test]+fn test_email_search_request_empty_arrays() {+ let json = r#"{"query":"test","terms":[],"match_type":"exact","senders":[],"cc":[],"bcc":[]}"#;++ let request: EmailSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize empty arrays");++ assert_eq!(request.query, Some("test".to_string()));+ assert_eq!(request.terms, Some(vec![]));+ assert_eq!(request.match_type, MatchType::Exact);+ assert!(request.filters.as_ref().unwrap().senders.is_empty());+ assert!(request.filters.as_ref().unwrap().bcc.is_empty());+ assert!(request.filters.as_ref().unwrap().cc.is_empty());+}++#[test]+fn test_email_search_request_invalid_match_type() {+ let json = r#"{"match_type":"invalid"}"#;++ let result = serde_json::from_str::<EmailSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize invalid match_type"+ );+}++#[test]+fn test_email_search_request_missing_required_field() {+ let json = r#"{"query":"test"}"#;++ let result = serde_json::from_str::<EmailSearchRequest>(json);+ assert!(+ result.is_err(),+ "Should fail to deserialize without required match_type field"+ );+}++#[test]+fn test_email_search_request_filters_only() {+ let json = r#"{"match_type":"exact","senders":["[email protected]"]}"#;++ let request: EmailSearchRequest =+ serde_json::from_str(json).expect("Failed to deserialize filters only");++ assert_eq!(request.query, None);+ assert_eq!(request.terms, None);+ assert_eq!(request.match_type, MatchType::Exact);+ assert_eq!(+ request.filters.as_ref().unwrap().senders,+ vec!["[email protected]".to_string()]+ );+ assert!(request.filters.as_ref().unwrap().cc.is_empty());+ assert!(request.filters.as_ref().unwrap().bcc.is_empty());+}diff --git a/rust/cloud-storage/models_search/src/lib.rs b/rust/cloud-storage/models_search/src/lib.rsindex 5b47924182..b4b8ae8757 100644--- a/rust/cloud-storage/models_search/src/lib.rs+++ b/rust/cloud-storage/models_search/src/lib.rs@@ -90,8 +90,21 @@ pub trait Metadata<T> {fn metadata(&self, id: &str) -> T;}-// TODO: SearchReponse needs two generics, must be SearchResponseItem-// pub struct SearchResponse<T, S> {-// /// List containing results from a request-// pub results: Vec<SearchResponseItem<T, S>>,-// }+#[derive(Debug, Serialize, Deserialize, ToSchema, JsonSchema, Default)]+pub struct SearchHighlight {+ /// The highlight match on the name field+ #[serde(skip_serializing_if = "Option::is_none")]+ pub name: Option<String>,+ /// The highlight match on the content field+ #[serde(default, skip_serializing_if = "Vec::is_empty")]+ pub content: Vec<String>,+}++impl From<opensearch_client::search::model::Highlight> for SearchHighlight {+ fn from(highlight: opensearch_client::search::model::Highlight) -> Self {+ Self {+ name: highlight.name,+ content: highlight.content,+ }+ }+}diff --git a/rust/cloud-storage/models_search/src/project.rs b/rust/cloud-storage/models_search/src/project.rsindex 2838c58212..54fb2f39e2 100644--- a/rust/cloud-storage/models_search/src/project.rs+++ b/rust/cloud-storage/models_search/src/project.rs@@ -1,4 +1,4 @@-use crate::{MatchType, SearchOn, SearchResponse, SearchResponseItem};+use crate::{MatchType, SearchHighlight, SearchOn, SearchResponse, SearchResponseItem};use item_filters::ProjectFilters;use schemars::JsonSchema;use serde::{Deserialize, Serialize};@@ -6,8 +6,7 @@ use utoipa::ToSchema;#[derive(Debug, Serialize, Deserialize, ToSchema)]pub struct ProjectSearchResult {- /// array of content matches for a project- pub content: Vec<String>,+ pub highlight: SearchHighlight,}/// Metadata associated with Project Search, to be used with SearchResponseItem@@ -98,8 +97,8 @@ pub struct SimpleProjectSearchResponseBaseItem<T> {pub project_name: String,/// The id of the user who created the projectpub user_id: String,- /// The opensearch matches on the project- pub content: Option<Vec<String>>,+ /// The highlights on the project+ pub highlight: SearchHighlight,}pub type SimpleProjectSearchResponseItem =@@ -115,7 +114,7 @@ impl From<opensearch_client::search::projects::ProjectSearchResponse>created_at: response.created_at.into(),project_name: response.project_name,user_id: response.user_id,- content: response.content,+ highlight: response.highlight.into(),}}}diff --git a/rust/cloud-storage/opensearch_client/examples/query_document.rs b/rust/cloud-storage/opensearch_client/examples/query_document.rsindex c992883e7d..2ed9a687ae 100644--- a/rust/cloud-storage/opensearch_client/examples/query_document.rs+++ b/rust/cloud-storage/opensearch_client/examples/query_document.rs@@ -26,7 +26,7 @@ async fn main() -> anyhow::Result<()> {for document in result {println!("{:?}", document.document_id);- println!("{:?}", document.content);+ println!("{:?}", document.highlight);}Ok(())diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 108ccfd4bf..ac9a990ea9 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -3,7 +3,7 @@ use crate::{error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},- model::{DefaultSearchResponse, parse_highlight_hit},+ model::{DefaultSearchResponse, Highlight, parse_highlight_hit},query::Keys,},};@@ -41,7 +41,8 @@ pub struct ChannelMessageSearchResponse {pub mentions: Vec<String>,pub created_at: i64,pub updated_at: i64,- pub content: Option<Vec<String>>,+ /// Contains the highlight matches for the channel name and content+ pub highlight: Highlight,}#[derive(Default)]@@ -200,7 +201,6 @@ pub(crate) async fn search_channel_messages(client: &opensearch::OpenSearch,args: ChannelMessageSearchArgs,) -> Result<Vec<ChannelMessageSearchResponse>> {- let search_on = args.search_on;let query_body = args.build()?;let response = client@@ -234,16 +234,18 @@ pub(crate) async fn search_channel_messages(mentions: hit._source.mentions,created_at: hit._source.created_at_seconds,updated_at: hit._source.updated_at_seconds,- content: hit.highlight.map(|h| {- parse_highlight_hit(- h,- Keys {- title_key: ChannelMessageSearchConfig::TITLE_KEY,- content_key: ChannelMessageSearchConfig::CONTENT_KEY,- },- search_on,- )- }),+ highlight: hit+ .highlight+ .map(|h| {+ parse_highlight_hit(+ h,+ Keys {+ title_key: ChannelMessageSearchConfig::TITLE_KEY,+ content_key: ChannelMessageSearchConfig::CONTENT_KEY,+ },+ )+ })+ .unwrap_or_default(),}).collect())}diff --git a/rust/cloud-storage/opensearch_client/src/search/chats.rs b/rust/cloud-storage/opensearch_client/src/search/chats.rsindex 36a2141218..11763dbfce 100644--- a/rust/cloud-storage/opensearch_client/src/search/chats.rs+++ b/rust/cloud-storage/opensearch_client/src/search/chats.rs@@ -3,7 +3,7 @@ use crate::{error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},- model::{DefaultSearchResponse, parse_highlight_hit},+ model::{DefaultSearchResponse, Highlight, parse_highlight_hit},query::Keys,utils::should_wildcard_field_query_builder,},@@ -34,7 +34,7 @@ pub struct ChatSearchResponse {pub role: String,pub updated_at: i64,pub title: String,- pub content: Option<Vec<String>>,+ pub highlight: Highlight,}struct ChatSearchConfig;@@ -144,7 +144,6 @@ pub(crate) async fn search_chats(client: &opensearch::OpenSearch,args: ChatSearchArgs,) -> Result<Vec<ChatSearchResponse>> {- let search_on = args.search_on;let query_body = args.build()?;let response = client@@ -173,16 +172,18 @@ pub(crate) async fn search_chats(user_id: hit._source.user_id,role: hit._source.role,title: hit._source.title,- content: hit.highlight.map(|h| {- parse_highlight_hit(- h,- Keys {- title_key: ChatSearchConfig::TITLE_KEY,- content_key: ChatSearchConfig::CONTENT_KEY,- },- search_on,- )- }),+ highlight: hit+ .highlight+ .map(|h| {+ parse_highlight_hit(+ h,+ Keys {+ title_key: ChatSearchConfig::TITLE_KEY,+ content_key: ChatSearchConfig::CONTENT_KEY,+ },+ )+ })+ .unwrap_or_default(),updated_at: hit._source.updated_at_seconds,}).collect())diff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rsindex d47bb77ebe..05f7d771a0 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs@@ -3,7 +3,7 @@ use crate::{error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},- model::{DefaultSearchResponse, parse_highlight_hit},+ model::{DefaultSearchResponse, Highlight, parse_highlight_hit},query::Keys,},};@@ -87,7 +87,8 @@ pub struct DocumentSearchResponse {pub owner_id: String,pub file_type: String,pub updated_at: i64,- pub content: Option<Vec<String>>,+ /// Contains the highlight matches for the document name and content+ pub highlight: Highlight,pub raw_content: Option<String>,}@@ -125,7 +126,6 @@ pub(crate) async fn search_documents(client: &opensearch::OpenSearch,args: DocumentSearchArgs,) -> Result<Vec<DocumentSearchResponse>> {- let search_on = args.search_on;let query_body = args.build()?;tracing::trace!("query: {}", query_body);@@ -158,16 +158,18 @@ pub(crate) async fn search_documents(file_type: hit._source.file_type,updated_at: hit._source.updated_at_seconds,raw_content: hit._source.raw_content,- content: hit.highlight.map(|h| {- parse_highlight_hit(- h,- Keys {- title_key: DocumentSearchConfig::TITLE_KEY,- content_key: DocumentSearchConfig::CONTENT_KEY,- },- search_on,- )- }),+ highlight: hit+ .highlight+ .map(|h| {+ parse_highlight_hit(+ h,+ Keys {+ title_key: DocumentSearchConfig::TITLE_KEY,+ content_key: DocumentSearchConfig::CONTENT_KEY,+ },+ )+ })+ .unwrap_or_default(),}).collect())}diff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex 9fff5037c4..28bda88930 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -3,7 +3,7 @@ use crate::{error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},- model::parse_highlight_hit,+ model::{Highlight, parse_highlight_hit},query::Keys,utils::should_wildcard_field_query_builder,},@@ -200,7 +200,7 @@ pub struct EmailSearchResponse {pub updated_at: i64,pub sent_at: Option<i64>,pub subject: Option<String>,- pub content: Option<Vec<String>>,+ pub highlight: Highlight,}pub struct EmailSearchArgs {@@ -248,7 +248,6 @@ pub(crate) async fn search_emails(client: &opensearch::OpenSearch,args: EmailSearchArgs,) -> Result<Vec<EmailSearchResponse>> {- let search_on = args.search_on;let query_body = args.build()?;let response = client@@ -284,16 +283,18 @@ pub(crate) async fn search_emails(user_id: hit._source.user_id,updated_at: hit._source.updated_at_seconds,sent_at: hit._source.sent_at_seconds,- content: hit.highlight.map(|h| {- parse_highlight_hit(- h,- Keys {- title_key: EmailSearchConfig::TITLE_KEY,- content_key: EmailSearchConfig::CONTENT_KEY,- },- search_on,- )- }),+ highlight: hit+ .highlight+ .map(|h| {+ parse_highlight_hit(+ h,+ Keys {+ title_key: EmailSearchConfig::TITLE_KEY,+ content_key: EmailSearchConfig::CONTENT_KEY,+ },+ )+ })+ .unwrap_or_default(),}).collect())}diff --git a/rust/cloud-storage/opensearch_client/src/search/mod.rs b/rust/cloud-storage/opensearch_client/src/search/mod.rsindex 5ce7fc66d0..3f026de423 100644--- a/rust/cloud-storage/opensearch_client/src/search/mod.rs+++ b/rust/cloud-storage/opensearch_client/src/search/mod.rs@@ -3,7 +3,7 @@ pub mod channels;pub mod chats;pub mod documents;pub mod emails;-mod model;+pub mod model;pub mod projects;mod query;mod utils;diff --git a/rust/cloud-storage/opensearch_client/src/search/model.rs b/rust/cloud-storage/opensearch_client/src/search/model.rsindex 46269778d0..c595965284 100644--- a/rust/cloud-storage/opensearch_client/src/search/model.rs+++ b/rust/cloud-storage/opensearch_client/src/search/model.rs@@ -1,10 +1,10 @@use std::{collections::HashMap, fmt::Display};-use crate::{SearchOn, search::query::Keys};+use crate::search::query::Keys;/// macro open/close tags for highlight matches#[derive(Debug, PartialEq)]-pub enum MacroEm {+pub(crate) enum MacroEm {/// Open tag <macro_em>Open,/// Close tag </macro_em>@@ -21,7 +21,7 @@ impl Display for MacroEm {}#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct Hit<T> {+pub(crate) struct Hit<T> {pub _score: Option<f64>,pub _source: T,/// Highlights may or may not be present since we could match@@ -29,61 +29,60 @@ pub struct Hit<T> {pub highlight: Option<HashMap<String, Vec<String>>>,}+#[derive(Debug, serde::Serialize, serde::Deserialize, Default, Clone)]+pub struct Highlight {+ /// The highlight name match if present+ #[serde(skip_serializing_if = "Option::is_none")]+ pub name: Option<String>,++ /// The highlight content matches+ #[serde(skip_serializing_if = "Vec::is_empty")]+ pub content: Vec<String>,+}+pub(crate) fn parse_highlight_hit(highlight: HashMap<String, Vec<String>>,keys: Keys,- search_on: SearchOn,-) -> Vec<String> {- match search_on {- SearchOn::Name => highlight- .get(keys.title_key)- .map(|v| v.to_vec())- .unwrap_or_default(),- SearchOn::Content => highlight+) -> Highlight {+ let name = highlight+ .get(keys.title_key)+ .and_then(|v| v.first())+ .map(|v| v.to_string());++ Highlight {+ name,+ content: highlight.get(keys.content_key).map(|v| v.to_vec()).unwrap_or_default(),- SearchOn::NameContent => {- let mut result = Vec::new();-- if let Some(highlight) = highlight.get(keys.title_key) {- result.extend(highlight.to_vec());- }-- if let Some(highlight) = highlight.get(keys.content_key) {- result.extend(highlight.to_vec());- }-- result- }}}#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct Total {+pub(crate) struct Total {pub value: i64,pub relation: String,}#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct Hits<T> {+pub(crate) struct Hits<T> {pub total: Total,pub max_score: Option<f64>,pub hits: Vec<Hit<T>>,}#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct Shards {+pub(crate) struct Shards {pub total: i32,pub successful: i32,pub skipped: i32,pub failed: i32,}-pub type DefaultSearchResponse<T> = SearchResponse<T>;+pub(crate) type DefaultSearchResponse<T> = SearchResponse<T>;#[derive(Debug, serde::Serialize, serde::Deserialize)]-pub struct SearchResponse<T> {+pub(crate) struct SearchResponse<T> {pub hits: Hits<T>,pub took: i32,pub timed_out: bool,diff --git a/rust/cloud-storage/opensearch_client/src/search/projects.rs b/rust/cloud-storage/opensearch_client/src/search/projects.rsindex b7f4835b86..2b7c92dca1 100644--- a/rust/cloud-storage/opensearch_client/src/search/projects.rs+++ b/rust/cloud-storage/opensearch_client/src/search/projects.rs@@ -3,13 +3,13 @@ use crate::{error::{OpensearchClientError, ResponseExt},search::{builder::{SearchQueryBuilder, SearchQueryConfig},- model::{MacroEm, SearchResponse, parse_highlight_hit},+ model::{Highlight, MacroEm, SearchResponse, parse_highlight_hit},query::Keys,},};use crate::SearchOn;-use opensearch_query_builder::{Highlight, HighlightField, SearchRequest, ToOpenSearchJson};+use opensearch_query_builder::{HighlightField, SearchRequest, ToOpenSearchJson};use serde::{Deserialize, Serialize};use serde_json::Value;@@ -23,15 +23,17 @@ impl SearchQueryConfig for ProjectSearchConfig {const TITLE_KEY: &'static str = "project_name";// Projects have no "content" to highlight match on, so match on the TITLE_KEY instead- fn default_highlight() -> Highlight {- Highlight::new().require_field_match(true).field(- Self::TITLE_KEY,- HighlightField::new()- .highlight_type("unified")- .number_of_fragments(1)- .pre_tags(vec![MacroEm::Open.to_string()])- .post_tags(vec![MacroEm::Close.to_string()]),- )+ fn default_highlight() -> opensearch_query_builder::Highlight {+ opensearch_query_builder::Highlight::new()+ .require_field_match(true)+ .field(+ Self::TITLE_KEY,+ HighlightField::new()+ .highlight_type("unified")+ .number_of_fragments(1)+ .pre_tags(vec![MacroEm::Open.to_string()])+ .post_tags(vec![MacroEm::Close.to_string()]),+ )}}@@ -118,7 +120,7 @@ pub struct ProjectSearchResponse {pub project_name: String,pub created_at: i64,pub updated_at: i64,- pub content: Option<Vec<String>>,+ pub highlight: Highlight,}#[tracing::instrument(skip(client, args), err)]@@ -126,7 +128,6 @@ pub(crate) async fn search_projects(client: &opensearch::OpenSearch,args: ProjectSearchArgs,) -> Result<Vec<ProjectSearchResponse>> {- let search_on = args.search_on;let query_body = args.build()?;let response = client@@ -163,16 +164,18 @@ pub(crate) async fn search_projects(project_name: hit._source.project_name,created_at: hit._source.created_at_seconds,updated_at: hit._source.updated_at_seconds,- content: hit.highlight.map(|h| {- parse_highlight_hit(- h,- Keys {- title_key: ProjectSearchConfig::TITLE_KEY,- content_key: ProjectSearchConfig::CONTENT_KEY,- },- search_on,- )- }),+ highlight: hit+ .highlight+ .map(|h| {+ parse_highlight_hit(+ h,+ Keys {+ title_key: ProjectSearchConfig::TITLE_KEY,+ content_key: ProjectSearchConfig::CONTENT_KEY,+ },+ )+ })+ .unwrap_or_default(),}).collect())}diff --git a/rust/cloud-storage/search_service/src/api/search/channel.rs b/rust/cloud-storage/search_service/src/api/search/channel.rsindex 805eb6847e..08b7ef73e0 100644--- a/rust/cloud-storage/search_service/src/api/search/channel.rs+++ b/rust/cloud-storage/search_service/src/api/search/channel.rs@@ -140,314 +140,4 @@ pub fn construct_search_result(}#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn test_construct_search_result_empty_input() {- let result = construct_search_result(vec![], HashMap::new());- assert!(result.is_ok());- assert_eq!(result.unwrap().len(), 0);- }-- #[test]- fn test_construct_search_result_single_channel() {- let search_results = vec![- opensearch_client::search::channels::ChannelMessageSearchResponse {- channel_id: "channel1".to_string(),- channel_name: Some("Test Channel".to_string()),- channel_type: "public".to_string(),- org_id: Some(123),- message_id: "msg1".to_string(),- thread_id: Some("thread1".to_string()),- sender_id: "user1".to_string(),- mentions: vec!["@user2".to_string()],- created_at: 1234567890,- updated_at: 1234567891,- content: Some(vec!["Test message content".to_string()]),- },- ];-- let result = construct_search_result(search_results, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.channel_id, "channel1");- assert_eq!(result[0].extra.id, "channel1");- assert_eq!(- result[0].extra.channel_name,- Some("Test Channel".to_string())- );- assert_eq!(result[0].extra.name, Some("Test Channel".to_string()));- assert_eq!(result[0].extra.channel_message_search_results.len(), 1);- assert_eq!(- result[0].extra.channel_message_search_results[0].message_id,- "msg1"- );- assert_eq!(- result[0].extra.channel_message_search_results[0].sender_id,- "user1"- );- assert_eq!(- result[0].extra.channel_message_search_results[0].thread_id,- Some("thread1".to_string())- );- }-- #[test]- fn test_construct_search_result_multiple_messages_same_channel() {- let search_results = vec![- opensearch_client::search::channels::ChannelMessageSearchResponse {- channel_id: "channel1".to_string(),- channel_name: Some("Test Channel".to_string()),- channel_type: "public".to_string(),- org_id: Some(123),- message_id: "msg1".to_string(),- thread_id: Some("thread1".to_string()),- sender_id: "user1".to_string(),- mentions: vec![],- created_at: 1234567890,- updated_at: 1234567891,- content: Some(vec!["First message".to_string()]),- },- opensearch_client::search::channels::ChannelMessageSearchResponse {- channel_id: "channel1".to_string(),- channel_name: Some("Test Channel".to_string()),- channel_type: "public".to_string(),- org_id: Some(123),- message_id: "msg2".to_string(),- thread_id: Some("thread2".to_string()),- sender_id: "user2".to_string(),- mentions: vec!["@user1".to_string()],- created_at: 1234567892,- updated_at: 1234567893,- content: Some(vec!["Second message".to_string()]),- },- ];-- let result = construct_search_result(search_results, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.channel_id, "channel1");- assert_eq!(result[0].extra.id, "channel1");- assert_eq!(result[0].extra.name, Some("Test Channel".to_string()));- assert_eq!(result[0].extra.channel_message_search_results.len(), 2);-- let message_ids: Vec<String> = result[0]- .extra- .channel_message_search_results- .iter()- .map(|r| r.message_id.clone())- .collect();- assert!(message_ids.contains(&"msg1".to_string()));- assert!(message_ids.contains(&"msg2".to_string()));-- let sender_ids: Vec<String> = result[0]- .extra- .channel_message_search_results- .iter()- .map(|r| r.sender_id.clone())- .collect();- assert!(sender_ids.contains(&"user1".to_string()));- assert!(sender_ids.contains(&"user2".to_string()));- }-- #[test]- fn test_construct_search_result_filters_messages_without_content() {- let search_results = vec![- opensearch_client::search::channels::ChannelMessageSearchResponse {- channel_id: "channel1".to_string(),- channel_name: Some("Test Channel".to_string()),- channel_type: "public".to_string(),- org_id: Some(123),- message_id: "msg1".to_string(),- thread_id: Some("thread1".to_string()),- sender_id: "user1".to_string(),- mentions: vec![],- created_at: 1234567890,- updated_at: 1234567891,- content: Some(vec!["Message with content".to_string()]),- },- opensearch_client::search::channels::ChannelMessageSearchResponse {- channel_id: "channel1".to_string(),- channel_name: Some("Test Channel".to_string()),- channel_type: "public".to_string(),- org_id: Some(123),- message_id: "msg2".to_string(),- thread_id: Some("thread2".to_string()),- sender_id: "user2".to_string(),- mentions: vec![],- created_at: 1234567892,- updated_at: 1234567893,- content: None,- },- ];-- let result = construct_search_result(search_results, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.channel_message_search_results.len(), 1);- assert_eq!(- result[0].extra.channel_message_search_results[0].message_id,- "msg1"- );- }-- fn create_test_channel_response(- channel_id: &str,- message_id: &str,- sender_id: &str,- content: Option<Vec<String>>,- ) -> opensearch_client::search::channels::ChannelMessageSearchResponse {- opensearch_client::search::channels::ChannelMessageSearchResponse {- channel_id: channel_id.to_string(),- channel_name: Some("Test Channel".to_string()),- channel_type: "public".to_string(),- org_id: Some(123),- message_id: message_id.to_string(),- thread_id: Some("thread1".to_string()),- sender_id: sender_id.to_string(),- mentions: vec![],- created_at: 1234567890,- updated_at: 1234567891,- content,- }- }-- #[test]- fn test_channel_history_timestamps() {- // Create a mock channel history with known timestamps- let mut channel_histories = HashMap::new();- let now = chrono::Utc::now();- let channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440001").unwrap();-- let history = ChannelHistoryInfo {- item_id: channel_uuid,- created_at: now,- updated_at: now,- viewed_at: Some(now),- interacted_at: Some(now),- };-- channel_histories.insert(channel_uuid, history);-- // Create a test response with the UUID- let input = vec![create_test_channel_response(- &channel_uuid.to_string(),- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Call the function under test- let result = construct_search_result(input, channel_histories).unwrap();-- // Verify that timestamps were copied from the channel history- assert_eq!(result.len(), 1);- assert_eq!(result[0].created_at, now.timestamp());- assert_eq!(result[0].updated_at, now.timestamp());- assert_eq!(result[0].viewed_at, Some(now.timestamp()));- assert_eq!(result[0].interacted_at, Some(now.timestamp()));- }-- #[test]- fn test_channel_history_missing_entry() {- // Create a test response for a channel that doesn't have history- let missing_channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440002").unwrap();- let input = vec![create_test_channel_response(- &missing_channel_uuid.to_string(),- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock channel history that doesn't contain the channel_id- let mut channel_histories = HashMap::new();- let now = chrono::Utc::now();- let different_channel_uuid =- Uuid::parse_str("550e8400-e29b-41d4-a716-446655440003").unwrap();-- let history = ChannelHistoryInfo {- item_id: different_channel_uuid,- created_at: now,- updated_at: now,- viewed_at: None,- interacted_at: None,- };-- channel_histories.insert(different_channel_uuid, history);-- // Call the function under test- let result = construct_search_result(input, channel_histories).unwrap();-- // Verify that default timestamps were used- assert_eq!(result.len(), 1);-- // Default values from ChannelHistoryInfo::default()- let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();- assert_eq!(result[0].created_at, default_time);- assert_eq!(result[0].updated_at, default_time);- assert_eq!(result[0].viewed_at, None);- assert_eq!(result[0].interacted_at, None);- }-- #[test]- fn test_channel_history_null_viewed_at() {- // Create a test response- let channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440004").unwrap();- let input = vec![create_test_channel_response(- &channel_uuid.to_string(),- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock channel history with null viewed_at- let mut channel_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = ChannelHistoryInfo {- item_id: channel_uuid,- created_at: now,- updated_at: now,- viewed_at: None, // This user has never viewed this channel- interacted_at: None, // This user has never interacted with this channel- };-- channel_histories.insert(channel_uuid, history);-- // Call the function under test- let result = construct_search_result(input, channel_histories).unwrap();-- // Verify that timestamps were copied correctly and viewed_at is None- assert_eq!(result.len(), 1);- assert_eq!(result[0].created_at, now.timestamp());- assert_eq!(result[0].updated_at, now.timestamp());- assert_eq!(result[0].viewed_at, None);- assert_eq!(result[0].interacted_at, None);- }-- #[test]- fn test_channel_history_invalid_uuid() {- // Create a test response with an invalid UUID- let input = vec![create_test_channel_response(- "invalid-uuid",- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock channel history- let channel_histories = HashMap::new();-- // Call the function under test- let result = construct_search_result(input, channel_histories).unwrap();-- // Verify that default timestamps were used since UUID parsing failed- assert_eq!(result.len(), 1);- let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();- assert_eq!(result[0].created_at, default_time);- assert_eq!(result[0].updated_at, default_time);- assert_eq!(result[0].viewed_at, None);- assert_eq!(result[0].interacted_at, None);- }-}+mod test;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.rsnew file mode 100644index 0000000000..c80a2bb953--- /dev/null+++ b/rust/cloud-storage/search_service/src/api/search/channel/test.rs@@ -0,0 +1,325 @@+use opensearch_client::search::model::Highlight;++use super::*;++#[test]+fn test_construct_search_result_empty_input() {+ let result = construct_search_result(vec![], HashMap::new());+ assert!(result.is_ok());+ assert_eq!(result.unwrap().len(), 0);+}++#[test]+fn test_construct_search_result_single_channel() {+ let search_results = vec![+ opensearch_client::search::channels::ChannelMessageSearchResponse {+ channel_id: "channel1".to_string(),+ channel_name: Some("Test Channel".to_string()),+ channel_type: "public".to_string(),+ org_id: Some(123),+ message_id: "msg1".to_string(),+ thread_id: Some("thread1".to_string()),+ sender_id: "user1".to_string(),+ mentions: vec!["@user2".to_string()],+ created_at: 1234567890,+ updated_at: 1234567891,+ highlight: Highlight {+ name: None,+ content: vec!["Test message content".to_string()],+ },+ },+ ];++ let result = construct_search_result(search_results, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.channel_id, "channel1");+ assert_eq!(result[0].extra.id, "channel1");+ assert_eq!(+ result[0].extra.channel_name,+ Some("Test Channel".to_string())+ );+ assert_eq!(result[0].extra.name, Some("Test Channel".to_string()));+ assert_eq!(result[0].extra.channel_message_search_results.len(), 1);+ assert_eq!(+ result[0].extra.channel_message_search_results[0].message_id,+ "msg1"+ );+ assert_eq!(+ result[0].extra.channel_message_search_results[0].sender_id,+ "user1"+ );+ assert_eq!(+ result[0].extra.channel_message_search_results[0].thread_id,+ Some("thread1".to_string())+ );+}++#[test]+fn test_construct_search_result_multiple_messages_same_channel() {+ let search_results = vec![+ opensearch_client::search::channels::ChannelMessageSearchResponse {+ channel_id: "channel1".to_string(),+ channel_name: Some("Test Channel".to_string()),+ channel_type: "public".to_string(),+ org_id: Some(123),+ message_id: "msg1".to_string(),+ thread_id: Some("thread1".to_string()),+ sender_id: "user1".to_string(),+ mentions: vec![],+ created_at: 1234567890,+ updated_at: 1234567891,+ highlight: Highlight {+ name: None,+ content: vec!["First message".to_string()],+ },+ },+ opensearch_client::search::channels::ChannelMessageSearchResponse {+ channel_id: "channel1".to_string(),+ channel_name: Some("Test Channel".to_string()),+ channel_type: "public".to_string(),+ org_id: Some(123),+ message_id: "msg2".to_string(),+ thread_id: Some("thread2".to_string()),+ sender_id: "user2".to_string(),+ mentions: vec!["@user1".to_string()],+ created_at: 1234567892,+ updated_at: 1234567893,+ highlight: Highlight {+ name: None,+ content: vec!["Second message".to_string()],+ },+ },+ ];++ let result = construct_search_result(search_results, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.channel_id, "channel1");+ assert_eq!(result[0].extra.id, "channel1");+ assert_eq!(result[0].extra.name, Some("Test Channel".to_string()));+ assert_eq!(result[0].extra.channel_message_search_results.len(), 2);++ let message_ids: Vec<String> = result[0]+ .extra+ .channel_message_search_results+ .iter()+ .map(|r| r.message_id.clone())+ .collect();+ assert!(message_ids.contains(&"msg1".to_string()));+ assert!(message_ids.contains(&"msg2".to_string()));++ let sender_ids: Vec<String> = result[0]+ .extra+ .channel_message_search_results+ .iter()+ .map(|r| r.sender_id.clone())+ .collect();+ assert!(sender_ids.contains(&"user1".to_string()));+ assert!(sender_ids.contains(&"user2".to_string()));+}++#[test]+fn test_construct_search_result_filters_messages_without_content() {+ let search_results = vec![+ opensearch_client::search::channels::ChannelMessageSearchResponse {+ channel_id: "channel1".to_string(),+ channel_name: Some("Test Channel".to_string()),+ channel_type: "public".to_string(),+ org_id: Some(123),+ message_id: "msg1".to_string(),+ thread_id: Some("thread1".to_string()),+ sender_id: "user1".to_string(),+ mentions: vec![],+ created_at: 1234567890,+ updated_at: 1234567891,+ highlight: Highlight {+ name: None,+ content: vec!["Message with content".to_string()],+ },+ },+ opensearch_client::search::channels::ChannelMessageSearchResponse {+ channel_id: "channel1".to_string(),+ channel_name: Some("Test Channel".to_string()),+ channel_type: "public".to_string(),+ org_id: Some(123),+ message_id: "msg2".to_string(),+ thread_id: Some("thread2".to_string()),+ sender_id: "user2".to_string(),+ mentions: vec![],+ created_at: 1234567892,+ updated_at: 1234567893,+ highlight: Highlight::default(),+ },+ ];++ let result = construct_search_result(search_results, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.channel_message_search_results.len(), 2);+ assert_eq!(+ result[0].extra.channel_message_search_results[0].message_id,+ "msg1"+ );+}++fn create_test_channel_response(+ channel_id: &str,+ message_id: &str,+ sender_id: &str,+ content: Option<Vec<String>>,+) -> opensearch_client::search::channels::ChannelMessageSearchResponse {+ opensearch_client::search::channels::ChannelMessageSearchResponse {+ channel_id: channel_id.to_string(),+ channel_name: Some("Test Channel".to_string()),+ channel_type: "public".to_string(),+ org_id: Some(123),+ message_id: message_id.to_string(),+ thread_id: Some("thread1".to_string()),+ sender_id: sender_id.to_string(),+ mentions: vec![],+ created_at: 1234567890,+ updated_at: 1234567891,+ highlight: Highlight {+ name: None,+ content: content.unwrap_or_default(),+ },+ }+}++#[test]+fn test_channel_history_timestamps() {+ // Create a mock channel history with known timestamps+ let mut channel_histories = HashMap::new();+ let now = chrono::Utc::now();+ let channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440001").unwrap();++ let history = ChannelHistoryInfo {+ item_id: channel_uuid,+ created_at: now,+ updated_at: now,+ viewed_at: Some(now),+ interacted_at: Some(now),+ };++ channel_histories.insert(channel_uuid, history);++ // Create a test response with the UUID+ let input = vec![create_test_channel_response(+ &channel_uuid.to_string(),+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Call the function under test+ let result = construct_search_result(input, channel_histories).unwrap();++ // Verify that timestamps were copied from the channel history+ assert_eq!(result.len(), 1);+ assert_eq!(result[0].created_at, now.timestamp());+ assert_eq!(result[0].updated_at, now.timestamp());+ assert_eq!(result[0].viewed_at, Some(now.timestamp()));+ assert_eq!(result[0].interacted_at, Some(now.timestamp()));+}++#[test]+fn test_channel_history_missing_entry() {+ // Create a test response for a channel that doesn't have history+ let missing_channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440002").unwrap();+ let input = vec![create_test_channel_response(+ &missing_channel_uuid.to_string(),+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock channel history that doesn't contain the channel_id+ let mut channel_histories = HashMap::new();+ let now = chrono::Utc::now();+ let different_channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440003").unwrap();++ let history = ChannelHistoryInfo {+ item_id: different_channel_uuid,+ created_at: now,+ updated_at: now,+ viewed_at: None,+ interacted_at: None,+ };++ channel_histories.insert(different_channel_uuid, history);++ // Call the function under test+ let result = construct_search_result(input, channel_histories).unwrap();++ // Verify that default timestamps were used+ assert_eq!(result.len(), 1);++ // Default values from ChannelHistoryInfo::default()+ let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();+ assert_eq!(result[0].created_at, default_time);+ assert_eq!(result[0].updated_at, default_time);+ assert_eq!(result[0].viewed_at, None);+ assert_eq!(result[0].interacted_at, None);+}++#[test]+fn test_channel_history_null_viewed_at() {+ // Create a test response+ let channel_uuid = Uuid::parse_str("550e8400-e29b-41d4-a716-446655440004").unwrap();+ let input = vec![create_test_channel_response(+ &channel_uuid.to_string(),+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock channel history with null viewed_at+ let mut channel_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = ChannelHistoryInfo {+ item_id: channel_uuid,+ created_at: now,+ updated_at: now,+ viewed_at: None, // This user has never viewed this channel+ interacted_at: None, // This user has never interacted with this channel+ };++ channel_histories.insert(channel_uuid, history);++ // Call the function under test+ let result = construct_search_result(input, channel_histories).unwrap();++ // Verify that timestamps were copied correctly and viewed_at is None+ assert_eq!(result.len(), 1);+ assert_eq!(result[0].created_at, now.timestamp());+ assert_eq!(result[0].updated_at, now.timestamp());+ assert_eq!(result[0].viewed_at, None);+ assert_eq!(result[0].interacted_at, None);+}++#[test]+fn test_channel_history_invalid_uuid() {+ // Create a test response with an invalid UUID+ let input = vec![create_test_channel_response(+ "invalid-uuid",+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock channel history+ let channel_histories = HashMap::new();++ // Call the function under test+ let result = construct_search_result(input, channel_histories).unwrap();++ // Verify that default timestamps were used since UUID parsing failed+ assert_eq!(result.len(), 1);+ let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();+ assert_eq!(result[0].created_at, default_time);+ assert_eq!(result[0].updated_at, default_time);+ assert_eq!(result[0].viewed_at, None);+ assert_eq!(result[0].interacted_at, None);+}diff --git a/rust/cloud-storage/search_service/src/api/search/chat.rs b/rust/cloud-storage/search_service/src/api/search/chat.rsindex db8701f605..a5bf92897a 100644--- a/rust/cloud-storage/search_service/src/api/search/chat.rs+++ b/rust/cloud-storage/search_service/src/api/search/chat.rs@@ -117,280 +117,4 @@ pub fn construct_search_result(}#[cfg(test)]-mod tests {- use super::*;- use sqlx::types::chrono;-- fn create_test_response(- chat_id: &str,- chat_message_id: &str,- user_id: &str,- content: Option<Vec<String>>,- ) -> opensearch_client::search::chats::ChatSearchResponse {- opensearch_client::search::chats::ChatSearchResponse {- chat_id: chat_id.to_string(),- chat_message_id: chat_message_id.to_string(),- user_id: user_id.to_string(),- role: "user".to_string(),- updated_at: 1234567890,- title: "Test Chat".to_string(),- content,- }- }-- #[test]- fn test_empty_input() {- let input = vec![];- let result = construct_search_result(input, HashMap::new()).unwrap();- assert_eq!(result.len(), 0);- }-- #[test]- fn test_single_chat_with_content() {- let input = vec![create_test_response(- "chat_1",- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];- let result = construct_search_result(input, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.chat_id, "chat_1");- assert_eq!(result[0].extra.id, "chat_1");- assert_eq!(result[0].extra.user_id, "user_1");- assert_eq!(result[0].extra.owner_id, "user_1");- assert_eq!(result[0].extra.name, "Test Chat");- assert_eq!(result[0].extra.chat_search_results.len(), 1);- assert_eq!(- result[0].extra.chat_search_results[0].chat_message_id,- "msg_1"- );- assert_eq!(- result[0].extra.chat_search_results[0].content,- vec!["hello world"]- );- }-- #[test]- fn test_single_chat_without_content() {- let input = vec![create_test_response("chat_1", "msg_1", "user_1", None)];- let result = construct_search_result(input, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.chat_id, "chat_1");- assert_eq!(result[0].extra.id, "chat_1");- assert_eq!(result[0].extra.user_id, "user_1");- assert_eq!(result[0].extra.owner_id, "user_1");- assert_eq!(result[0].extra.name, "Test Chat");- assert_eq!(result[0].extra.chat_search_results.len(), 0); // Filtered out by From trait- }-- #[test]- fn test_single_chat_multiple_messages() {- let input = vec![- create_test_response("chat_1", "msg_1", "user_1", Some(vec!["hello".to_string()])),- create_test_response("chat_1", "msg_2", "user_1", Some(vec!["world".to_string()])),- ];- let result = construct_search_result(input, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.chat_id, "chat_1");- assert_eq!(result[0].extra.id, "chat_1");- assert_eq!(result[0].extra.chat_search_results.len(), 2);-- // Check both messages are present- let message_ids: Vec<&String> = result[0]- .extra- .chat_search_results- .iter()- .map(|r| &r.chat_message_id)- .collect();- assert!(message_ids.contains(&&"msg_1".to_string()));- assert!(message_ids.contains(&&"msg_2".to_string()));- }-- #[test]- fn test_multiple_chats() {- let input = vec![- create_test_response("chat_1", "msg_1", "user_1", Some(vec!["hello".to_string()])),- create_test_response("chat_2", "msg_2", "user_2", Some(vec!["world".to_string()])),- ];- let result = construct_search_result(input, HashMap::new()).unwrap();-- assert_eq!(result.len(), 2);-- // Check both chats are present- let chat_ids: Vec<&String> = result.iter().map(|r| &r.extra.id).collect();- assert!(chat_ids.contains(&&"chat_1".to_string()));- assert!(chat_ids.contains(&&"chat_2".to_string()));-- // Each chat should have one message- for chat in &result {- assert_eq!(chat.extra.chat_search_results.len(), 1);- }- }-- #[test]- fn test_mixed_content_presence() {- let input = vec![- create_test_response(- "chat_1",- "msg_1",- "user_1",- Some(vec!["visible".to_string()]),- ),- create_test_response("chat_1", "msg_2", "user_1", None), // No content- create_test_response(- "chat_1",- "msg_3",- "user_1",- Some(vec!["also visible".to_string()]),- ),- ];- let result = construct_search_result(input, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.chat_id, "chat_1");- assert_eq!(result[0].extra.id, "chat_1");- assert_eq!(result[0].extra.chat_search_results.len(), 2); // Only messages with content-- let contents: Vec<&Vec<String>> = result[0]- .extra- .chat_search_results- .iter()- .map(|r| &r.content)- .collect();- assert!(contents.contains(&&vec!["visible".to_string()]));- assert!(contents.contains(&&vec!["also visible".to_string()]));- }-- #[test]- fn test_user_id_taken_from_first_result() {- let input = vec![- create_test_response(- "chat_1",- "msg_1",- "user_first",- Some(vec!["content1".to_string()]),- ),- create_test_response(- "chat_1",- "msg_2",- "user_second",- Some(vec!["content2".to_string()]),- ),- ];- let result = construct_search_result(input, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- // user_id should come from the first result (base_search_result)- assert_eq!(result[0].extra.user_id, "user_first");- assert_eq!(result[0].extra.chat_search_results.len(), 2);- }-- #[test]- fn test_chat_history_timestamps() {- // Create a test response- let input = vec![create_test_response(- "chat_1",- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock chat history with known timestamps- let mut chat_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = ChatHistoryInfo {- item_id: "chat_1".to_string(),- created_at: now,- updated_at: now,- viewed_at: Some(now),- project_id: Some("project_1".to_string()),- };-- chat_histories.insert("chat_1".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, chat_histories).unwrap();-- // Verify that timestamps were copied from the chat history- assert_eq!(result.len(), 1);- assert_eq!(result[0].created_at, now.timestamp());- assert_eq!(result[0].updated_at, now.timestamp());- assert_eq!(result[0].viewed_at, Some(now.timestamp()));- }-- #[test]- fn test_chat_history_missing_entry() {- // Create a test response for a chat that doesn't have history- let input = vec![create_test_response(- "chat_missing",- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock chat history that doesn't contain the chat_id- let mut chat_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = ChatHistoryInfo {- item_id: "different_chat".to_string(),- created_at: now,- updated_at: now,- viewed_at: None,- project_id: Some("project_1".to_string()),- };-- chat_histories.insert("different_chat".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, chat_histories).unwrap();-- // Verify that default timestamps were used- assert_eq!(result.len(), 1);-- // Default values from ChatHistoryInfo::default()- let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();- assert_eq!(result[0].created_at, default_time);- assert_eq!(result[0].updated_at, default_time);- assert_eq!(result[0].viewed_at, None);- }-- #[test]- fn test_chat_history_null_viewed_at() {- // Create a test response- let input = vec![create_test_response(- "chat_1",- "msg_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock chat history with null viewed_at- let mut chat_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = ChatHistoryInfo {- item_id: "chat_1".to_string(),- created_at: now,- updated_at: now,- viewed_at: None, // This user has never viewed this chat- project_id: Some("project_1".to_string()),- };-- chat_histories.insert("chat_1".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, chat_histories).unwrap();-- // Verify that timestamps were copied correctly and viewed_at is None- assert_eq!(result.len(), 1);- assert_eq!(result[0].created_at, now.timestamp());- assert_eq!(result[0].updated_at, now.timestamp());- assert_eq!(result[0].viewed_at, None);- }-}+mod test;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.rsnew file mode 100644index 0000000000..eddf6979af--- /dev/null+++ b/rust/cloud-storage/search_service/src/api/search/chat/test.rs@@ -0,0 +1,279 @@+use super::*;+use opensearch_client::search::model::Highlight;+use sqlx::types::chrono;++fn create_test_response(+ chat_id: &str,+ chat_message_id: &str,+ user_id: &str,+ content: Option<Vec<String>>,+) -> opensearch_client::search::chats::ChatSearchResponse {+ opensearch_client::search::chats::ChatSearchResponse {+ chat_id: chat_id.to_string(),+ chat_message_id: chat_message_id.to_string(),+ user_id: user_id.to_string(),+ role: "user".to_string(),+ updated_at: 1234567890,+ title: "Test Chat".to_string(),+ highlight: Highlight {+ name: None,+ content: content.unwrap_or_default(),+ },+ }+}++#[test]+fn test_empty_input() {+ let input = vec![];+ let result = construct_search_result(input, HashMap::new()).unwrap();+ assert_eq!(result.len(), 0);+}++#[test]+fn test_single_chat_with_content() {+ let input = vec![create_test_response(+ "chat_1",+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];+ let result = construct_search_result(input, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.chat_id, "chat_1");+ assert_eq!(result[0].extra.id, "chat_1");+ assert_eq!(result[0].extra.user_id, "user_1");+ assert_eq!(result[0].extra.owner_id, "user_1");+ assert_eq!(result[0].extra.name, "Test Chat");+ assert_eq!(result[0].extra.chat_search_results.len(), 1);+ assert_eq!(+ result[0].extra.chat_search_results[0].chat_message_id,+ "msg_1"+ );+ assert_eq!(+ result[0].extra.chat_search_results[0].highlight.content,+ vec!["hello world"]+ );+}++#[test]+fn test_single_chat_without_content() {+ let input = vec![create_test_response("chat_1", "msg_1", "user_1", None)];+ let result = construct_search_result(input, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.chat_id, "chat_1");+ assert_eq!(result[0].extra.id, "chat_1");+ assert_eq!(result[0].extra.user_id, "user_1");+ assert_eq!(result[0].extra.owner_id, "user_1");+ assert_eq!(result[0].extra.name, "Test Chat");+ assert_eq!(result[0].extra.chat_search_results.len(), 1);+}++#[test]+fn test_single_chat_multiple_messages() {+ let input = vec![+ create_test_response("chat_1", "msg_1", "user_1", Some(vec!["hello".to_string()])),+ create_test_response("chat_1", "msg_2", "user_1", Some(vec!["world".to_string()])),+ ];+ let result = construct_search_result(input, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.chat_id, "chat_1");+ assert_eq!(result[0].extra.id, "chat_1");+ assert_eq!(result[0].extra.chat_search_results.len(), 2);++ // Check both messages are present+ let message_ids: Vec<&String> = result[0]+ .extra+ .chat_search_results+ .iter()+ .map(|r| &r.chat_message_id)+ .collect();+ assert!(message_ids.contains(&&"msg_1".to_string()));+ assert!(message_ids.contains(&&"msg_2".to_string()));+}++#[test]+fn test_multiple_chats() {+ let input = vec![+ create_test_response("chat_1", "msg_1", "user_1", Some(vec!["hello".to_string()])),+ create_test_response("chat_2", "msg_2", "user_2", Some(vec!["world".to_string()])),+ ];+ let result = construct_search_result(input, HashMap::new()).unwrap();++ assert_eq!(result.len(), 2);++ // Check both chats are present+ let chat_ids: Vec<&String> = result.iter().map(|r| &r.extra.id).collect();+ assert!(chat_ids.contains(&&"chat_1".to_string()));+ assert!(chat_ids.contains(&&"chat_2".to_string()));++ // Each chat should have one message+ for chat in &result {+ assert_eq!(chat.extra.chat_search_results.len(), 1);+ }+}++#[test]+fn test_mixed_content_presence() {+ let input = vec![+ create_test_response(+ "chat_1",+ "msg_1",+ "user_1",+ Some(vec!["visible".to_string()]),+ ),+ create_test_response("chat_1", "msg_2", "user_1", None), // No content+ create_test_response(+ "chat_1",+ "msg_3",+ "user_1",+ Some(vec!["also visible".to_string()]),+ ),+ ];+ let result = construct_search_result(input, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.chat_id, "chat_1");+ assert_eq!(result[0].extra.id, "chat_1");+ assert_eq!(result[0].extra.chat_search_results.len(), 3); // Only messages with content++ let contents: Vec<&Vec<String>> = result[0]+ .extra+ .chat_search_results+ .iter()+ .map(|r| &r.highlight.content)+ .collect();+ assert!(contents.contains(&&vec!["visible".to_string()]));+ assert!(contents.contains(&&vec!["also visible".to_string()]));+}++#[test]+fn test_user_id_taken_from_first_result() {+ let input = vec![+ create_test_response(+ "chat_1",+ "msg_1",+ "user_first",+ Some(vec!["content1".to_string()]),+ ),+ create_test_response(+ "chat_1",+ "msg_2",+ "user_second",+ Some(vec!["content2".to_string()]),+ ),+ ];+ let result = construct_search_result(input, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ // user_id should come from the first result (base_search_result)+ assert_eq!(result[0].extra.user_id, "user_first");+ assert_eq!(result[0].extra.chat_search_results.len(), 2);+}++#[test]+fn test_chat_history_timestamps() {+ // Create a test response+ let input = vec![create_test_response(+ "chat_1",+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock chat history with known timestamps+ let mut chat_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = ChatHistoryInfo {+ item_id: "chat_1".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: Some(now),+ project_id: Some("project_1".to_string()),+ };++ chat_histories.insert("chat_1".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, chat_histories).unwrap();++ // Verify that timestamps were copied from the chat history+ assert_eq!(result.len(), 1);+ assert_eq!(result[0].created_at, now.timestamp());+ assert_eq!(result[0].updated_at, now.timestamp());+ assert_eq!(result[0].viewed_at, Some(now.timestamp()));+}++#[test]+fn test_chat_history_missing_entry() {+ // Create a test response for a chat that doesn't have history+ let input = vec![create_test_response(+ "chat_missing",+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock chat history that doesn't contain the chat_id+ let mut chat_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = ChatHistoryInfo {+ item_id: "different_chat".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: None,+ project_id: Some("project_1".to_string()),+ };++ chat_histories.insert("different_chat".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, chat_histories).unwrap();++ // Verify that default timestamps were used+ assert_eq!(result.len(), 1);++ // Default values from ChatHistoryInfo::default()+ let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();+ assert_eq!(result[0].created_at, default_time);+ assert_eq!(result[0].updated_at, default_time);+ assert_eq!(result[0].viewed_at, None);+}++#[test]+fn test_chat_history_null_viewed_at() {+ // Create a test response+ let input = vec![create_test_response(+ "chat_1",+ "msg_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock chat history with null viewed_at+ let mut chat_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = ChatHistoryInfo {+ item_id: "chat_1".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: None, // This user has never viewed this chat+ project_id: Some("project_1".to_string()),+ };++ chat_histories.insert("chat_1".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, chat_histories).unwrap();++ // Verify that timestamps were copied correctly and viewed_at is None+ assert_eq!(result.len(), 1);+ assert_eq!(result[0].created_at, now.timestamp());+ assert_eq!(result[0].updated_at, now.timestamp());+ assert_eq!(result[0].viewed_at, None);+}diff --git a/rust/cloud-storage/search_service/src/api/search/document.rs b/rust/cloud-storage/search_service/src/api/search/document.rsindex 6308dc2ce9..7c961dea8d 100644--- a/rust/cloud-storage/search_service/src/api/search/document.rs+++ b/rust/cloud-storage/search_service/src/api/search/document.rs@@ -123,339 +123,4 @@ pub fn construct_search_result(}#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn test_construct_search_result_empty_input() {- let result = construct_search_result(vec![], HashMap::new());- assert!(result.is_ok());- assert_eq!(result.unwrap().len(), 0);- }-- #[test]- fn test_construct_search_result_single_document() {- let search_results = vec![- opensearch_client::search::documents::DocumentSearchResponse {- document_id: "doc1".to_string(),- document_name: "Test Document".to_string(),- node_id: "node1".to_string(),- owner_id: "user1".to_string(),- file_type: "pdf".to_string(),- updated_at: 1234567890,- content: Some(vec!["Test content".to_string()]),- raw_content: Some("Raw test content".to_string()),- },- ];-- let result = construct_search_result(search_results, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.document_id, "doc1");- assert_eq!(result[0].extra.id, "doc1");- assert_eq!(result[0].extra.document_name, "Test Document");- assert_eq!(result[0].extra.name, "Test Document");- assert_eq!(result[0].extra.owner_id, "user1");- assert_eq!(result[0].extra.file_type, "pdf");- assert_eq!(result[0].extra.document_search_results.len(), 1);- assert_eq!(result[0].extra.document_search_results[0].node_id, "node1");- assert_eq!(- result[0].extra.document_search_results[0].raw_content,- Some("Raw test content".to_string())- );- }-- #[test]- fn test_construct_search_result_multiple_nodes_same_document() {- let search_results = vec![- opensearch_client::search::documents::DocumentSearchResponse {- document_id: "doc1".to_string(),- document_name: "Test Document".to_string(),- node_id: "node1".to_string(),- owner_id: "user1".to_string(),- file_type: "pdf".to_string(),- updated_at: 1234567890,- content: Some(vec!["First content".to_string()]),- raw_content: Some("First raw content".to_string()),- },- opensearch_client::search::documents::DocumentSearchResponse {- document_id: "doc1".to_string(),- document_name: "Test Document".to_string(),- node_id: "node2".to_string(),- owner_id: "user1".to_string(),- file_type: "pdf".to_string(),- updated_at: 1234567891,- content: Some(vec!["Second content".to_string()]),- raw_content: Some("Second raw content".to_string()),- },- ];-- let result = construct_search_result(search_results, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.document_id, "doc1");- assert_eq!(result[0].extra.id, "doc1");- assert_eq!(result[0].extra.name, "Test Document");- assert_eq!(result[0].extra.document_search_results.len(), 2);-- let node_ids: Vec<String> = result[0]- .extra- .document_search_results- .iter()- .map(|r| r.node_id.clone())- .collect();- assert!(node_ids.contains(&"node1".to_string()));- assert!(node_ids.contains(&"node2".to_string()));- }-- // Helper function to create a test document search response- fn create_test_document_response(- document_id: &str,- node_id: &str,- owner_id: &str,- content: Option<Vec<String>>,- ) -> opensearch_client::search::documents::DocumentSearchResponse {- opensearch_client::search::documents::DocumentSearchResponse {- document_id: document_id.to_string(),- document_name: "Test Document".to_string(),- node_id: node_id.to_string(),- owner_id: owner_id.to_string(),- file_type: "pdf".to_string(),- updated_at: 1234567890,- content,- raw_content: Some("Raw test content".to_string()),- }- }-- #[test]- fn test_document_history_timestamps() {- // Create a test response- let input = vec![create_test_document_response(- "doc_1",- "node_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock document history with known timestamps- let mut document_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = DocumentHistoryInfo {- item_id: "doc_1".to_string(),- created_at: now,- updated_at: now,- viewed_at: Some(now),- project_id: Some("project_1".to_string()),- };-- document_histories.insert("doc_1".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, document_histories).unwrap();-- // Verify that timestamps were copied from the document history- assert_eq!(result.len(), 1);- assert_eq!(result[0].created_at, now.timestamp());- assert_eq!(result[0].updated_at, now.timestamp());- assert_eq!(result[0].viewed_at, Some(now.timestamp()));- }-- #[test]- fn test_document_history_missing_entry() {- // Create a test response for a document that doesn't have history- let input = vec![create_test_document_response(- "doc_missing",- "node_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock document history that doesn't contain the document_id- let mut document_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = DocumentHistoryInfo {- item_id: "different_doc".to_string(),- created_at: now,- updated_at: now,- viewed_at: None,- project_id: Some("project_1".to_string()),- };-- document_histories.insert("different_doc".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, document_histories).unwrap();-- // Verify that default timestamps were used- assert_eq!(result.len(), 1);-- // Default values from DocumentHistoryInfo::default()- let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();- assert_eq!(result[0].created_at, default_time);- assert_eq!(result[0].updated_at, default_time);- assert_eq!(result[0].viewed_at, None);- }-- #[test]- fn test_document_history_null_viewed_at() {- // Create a test response- let input = vec![create_test_document_response(- "doc_1",- "node_1",- "user_1",- Some(vec!["hello world".to_string()]),- )];-- // Create a mock document history with null viewed_at- let mut document_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = DocumentHistoryInfo {- item_id: "doc_1".to_string(),- created_at: now,- updated_at: now,- viewed_at: None, // This user has never viewed this document- project_id: Some("project_1".to_string()),- };-- document_histories.insert("doc_1".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, document_histories).unwrap();-- // Verify that timestamps were copied correctly and viewed_at is None- assert_eq!(result.len(), 1);- assert_eq!(result[0].created_at, now.timestamp());- assert_eq!(result[0].updated_at, now.timestamp());- assert_eq!(result[0].viewed_at, None);- }-- #[test]- fn test_document_history_multiple_documents() {- // Create test responses for multiple documents- let input = vec![- create_test_document_response(- "doc_1",- "node_1",- "user_1",- Some(vec!["first document".to_string()]),- ),- create_test_document_response(- "doc_2",- "node_2",- "user_2",- Some(vec!["second document".to_string()]),- ),- ];-- // Create mock document histories- let mut document_histories = HashMap::new();- let now = chrono::Utc::now();- let earlier = now - chrono::Duration::hours(1);-- let history1 = DocumentHistoryInfo {- item_id: "doc_1".to_string(),- created_at: now,- updated_at: now,- viewed_at: Some(now),- project_id: Some("project_1".to_string()),- };-- let history2 = DocumentHistoryInfo {- item_id: "doc_2".to_string(),- created_at: earlier,- updated_at: earlier,- viewed_at: None,- project_id: Some("project_2".to_string()),- };-- document_histories.insert("doc_1".to_string(), history1);- document_histories.insert("doc_2".to_string(), history2);-- // Call the function under test- let result = construct_search_result(input, document_histories).unwrap();-- // Verify that timestamps were copied correctly for both documents- assert_eq!(result.len(), 2);-- // Find each document in results (order might not be preserved)- let doc1_result = result- .iter()- .find(|r| r.extra.document_id == "doc_1")- .unwrap();- let doc2_result = result- .iter()- .find(|r| r.extra.document_id == "doc_2")- .unwrap();-- assert_eq!(doc1_result.created_at, now.timestamp());- assert_eq!(doc1_result.updated_at, now.timestamp());- assert_eq!(doc1_result.viewed_at, Some(now.timestamp()));-- assert_eq!(doc2_result.created_at, earlier.timestamp());- assert_eq!(doc2_result.updated_at, earlier.timestamp());- assert_eq!(doc2_result.viewed_at, None);- }-- #[test]- fn test_document_history_partial_missing_entries() {- // Create test responses for multiple documents- let input = vec![- create_test_document_response(- "doc_exists",- "node_1",- "user_1",- Some(vec!["existing document".to_string()]),- ),- create_test_document_response(- "doc_missing",- "node_2",- "user_2",- Some(vec!["missing document".to_string()]),- ),- ];-- // Create document history for only one document- let mut document_histories = HashMap::new();- let now = chrono::Utc::now();-- let history = DocumentHistoryInfo {- item_id: "doc_exists".to_string(),- created_at: now,- updated_at: now,- viewed_at: Some(now),- project_id: Some("project_1".to_string()),- };-- document_histories.insert("doc_exists".to_string(), history);-- // Call the function under test- let result = construct_search_result(input, document_histories).unwrap();-- // Verify results- assert_eq!(result.len(), 2);-- // Find each document in results- let existing_doc = result- .iter()- .find(|r| r.extra.document_id == "doc_exists")- .unwrap();- let missing_doc = result- .iter()- .find(|r| r.extra.document_id == "doc_missing")- .unwrap();-- // Existing document should have real timestamps- assert_eq!(existing_doc.created_at, now.timestamp());- assert_eq!(existing_doc.updated_at, now.timestamp());- assert_eq!(existing_doc.viewed_at, Some(now.timestamp()));-- // Missing document should have default timestamps- let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();- assert_eq!(missing_doc.created_at, default_time);- assert_eq!(missing_doc.updated_at, default_time);- assert_eq!(missing_doc.viewed_at, None);- }-}+mod test;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.rsnew file mode 100644index 0000000000..893a00a35e--- /dev/null+++ b/rust/cloud-storage/search_service/src/api/search/document/test.rs@@ -0,0 +1,348 @@+use opensearch_client::search::model::Highlight;++use super::*;++#[test]+fn test_construct_search_result_empty_input() {+ let result = construct_search_result(vec![], HashMap::new());+ assert!(result.is_ok());+ assert_eq!(result.unwrap().len(), 0);+}++#[test]+fn test_construct_search_result_single_document() {+ let search_results = vec![+ opensearch_client::search::documents::DocumentSearchResponse {+ document_id: "doc1".to_string(),+ document_name: "Test Document".to_string(),+ node_id: "node1".to_string(),+ owner_id: "user1".to_string(),+ file_type: "pdf".to_string(),+ updated_at: 1234567890,+ highlight: Highlight {+ name: None,+ content: vec!["Test content".to_string()],+ },+ raw_content: Some("Raw test content".to_string()),+ },+ ];++ let result = construct_search_result(search_results, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.document_id, "doc1");+ assert_eq!(result[0].extra.id, "doc1");+ assert_eq!(result[0].extra.document_name, "Test Document");+ assert_eq!(result[0].extra.name, "Test Document");+ assert_eq!(result[0].extra.owner_id, "user1");+ assert_eq!(result[0].extra.file_type, "pdf");+ assert_eq!(result[0].extra.document_search_results.len(), 1);+ assert_eq!(result[0].extra.document_search_results[0].node_id, "node1");+ assert_eq!(+ result[0].extra.document_search_results[0].raw_content,+ Some("Raw test content".to_string())+ );+}++#[test]+fn test_construct_search_result_multiple_nodes_same_document() {+ let search_results = vec![+ opensearch_client::search::documents::DocumentSearchResponse {+ document_id: "doc1".to_string(),+ document_name: "Test Document".to_string(),+ node_id: "node1".to_string(),+ owner_id: "user1".to_string(),+ file_type: "pdf".to_string(),+ updated_at: 1234567890,+ highlight: Highlight {+ name: None,+ content: vec!["First content".to_string()],+ },+ raw_content: Some("First raw content".to_string()),+ },+ opensearch_client::search::documents::DocumentSearchResponse {+ document_id: "doc1".to_string(),+ document_name: "Test Document".to_string(),+ node_id: "node2".to_string(),+ owner_id: "user1".to_string(),+ file_type: "pdf".to_string(),+ updated_at: 1234567891,+ highlight: Highlight {+ name: None,+ content: vec!["Second content".to_string()],+ },+ raw_content: Some("Second raw content".to_string()),+ },+ ];++ let result = construct_search_result(search_results, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.document_id, "doc1");+ assert_eq!(result[0].extra.id, "doc1");+ assert_eq!(result[0].extra.name, "Test Document");+ assert_eq!(result[0].extra.document_search_results.len(), 2);++ let node_ids: Vec<String> = result[0]+ .extra+ .document_search_results+ .iter()+ .map(|r| r.node_id.clone())+ .collect();+ assert!(node_ids.contains(&"node1".to_string()));+ assert!(node_ids.contains(&"node2".to_string()));+}++// Helper function to create a test document search response+fn create_test_document_response(+ document_id: &str,+ node_id: &str,+ owner_id: &str,+ content: Option<Vec<String>>,+) -> opensearch_client::search::documents::DocumentSearchResponse {+ opensearch_client::search::documents::DocumentSearchResponse {+ document_id: document_id.to_string(),+ document_name: "Test Document".to_string(),+ node_id: node_id.to_string(),+ owner_id: owner_id.to_string(),+ file_type: "pdf".to_string(),+ updated_at: 1234567890,+ highlight: Highlight {+ name: None,+ content: content.unwrap_or_default(),+ },+ raw_content: Some("Raw test content".to_string()),+ }+}++#[test]+fn test_document_history_timestamps() {+ // Create a test response+ let input = vec![create_test_document_response(+ "doc_1",+ "node_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock document history with known timestamps+ let mut document_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = DocumentHistoryInfo {+ item_id: "doc_1".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: Some(now),+ project_id: Some("project_1".to_string()),+ };++ document_histories.insert("doc_1".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, document_histories).unwrap();++ // Verify that timestamps were copied from the document history+ assert_eq!(result.len(), 1);+ assert_eq!(result[0].created_at, now.timestamp());+ assert_eq!(result[0].updated_at, now.timestamp());+ assert_eq!(result[0].viewed_at, Some(now.timestamp()));+}++#[test]+fn test_document_history_missing_entry() {+ // Create a test response for a document that doesn't have history+ let input = vec![create_test_document_response(+ "doc_missing",+ "node_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock document history that doesn't contain the document_id+ let mut document_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = DocumentHistoryInfo {+ item_id: "different_doc".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: None,+ project_id: Some("project_1".to_string()),+ };++ document_histories.insert("different_doc".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, document_histories).unwrap();++ // Verify that default timestamps were used+ assert_eq!(result.len(), 1);++ // Default values from DocumentHistoryInfo::default()+ let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();+ assert_eq!(result[0].created_at, default_time);+ assert_eq!(result[0].updated_at, default_time);+ assert_eq!(result[0].viewed_at, None);+}++#[test]+fn test_document_history_null_viewed_at() {+ // Create a test response+ let input = vec![create_test_document_response(+ "doc_1",+ "node_1",+ "user_1",+ Some(vec!["hello world".to_string()]),+ )];++ // Create a mock document history with null viewed_at+ let mut document_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = DocumentHistoryInfo {+ item_id: "doc_1".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: None, // This user has never viewed this document+ project_id: Some("project_1".to_string()),+ };++ document_histories.insert("doc_1".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, document_histories).unwrap();++ // Verify that timestamps were copied correctly and viewed_at is None+ assert_eq!(result.len(), 1);+ assert_eq!(result[0].created_at, now.timestamp());+ assert_eq!(result[0].updated_at, now.timestamp());+ assert_eq!(result[0].viewed_at, None);+}++#[test]+fn test_document_history_multiple_documents() {+ // Create test responses for multiple documents+ let input = vec![+ create_test_document_response(+ "doc_1",+ "node_1",+ "user_1",+ Some(vec!["first document".to_string()]),+ ),+ create_test_document_response(+ "doc_2",+ "node_2",+ "user_2",+ Some(vec!["second document".to_string()]),+ ),+ ];++ // Create mock document histories+ let mut document_histories = HashMap::new();+ let now = chrono::Utc::now();+ let earlier = now - chrono::Duration::hours(1);++ let history1 = DocumentHistoryInfo {+ item_id: "doc_1".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: Some(now),+ project_id: Some("project_1".to_string()),+ };++ let history2 = DocumentHistoryInfo {+ item_id: "doc_2".to_string(),+ created_at: earlier,+ updated_at: earlier,+ viewed_at: None,+ project_id: Some("project_2".to_string()),+ };++ document_histories.insert("doc_1".to_string(), history1);+ document_histories.insert("doc_2".to_string(), history2);++ // Call the function under test+ let result = construct_search_result(input, document_histories).unwrap();++ // Verify that timestamps were copied correctly for both documents+ assert_eq!(result.len(), 2);++ // Find each document in results (order might not be preserved)+ let doc1_result = result+ .iter()+ .find(|r| r.extra.document_id == "doc_1")+ .unwrap();+ let doc2_result = result+ .iter()+ .find(|r| r.extra.document_id == "doc_2")+ .unwrap();++ assert_eq!(doc1_result.created_at, now.timestamp());+ assert_eq!(doc1_result.updated_at, now.timestamp());+ assert_eq!(doc1_result.viewed_at, Some(now.timestamp()));++ assert_eq!(doc2_result.created_at, earlier.timestamp());+ assert_eq!(doc2_result.updated_at, earlier.timestamp());+ assert_eq!(doc2_result.viewed_at, None);+}++#[test]+fn test_document_history_partial_missing_entries() {+ // Create test responses for multiple documents+ let input = vec![+ create_test_document_response(+ "doc_exists",+ "node_1",+ "user_1",+ Some(vec!["existing document".to_string()]),+ ),+ create_test_document_response(+ "doc_missing",+ "node_2",+ "user_2",+ Some(vec!["missing document".to_string()]),+ ),+ ];++ // Create document history for only one document+ let mut document_histories = HashMap::new();+ let now = chrono::Utc::now();++ let history = DocumentHistoryInfo {+ item_id: "doc_exists".to_string(),+ created_at: now,+ updated_at: now,+ viewed_at: Some(now),+ project_id: Some("project_1".to_string()),+ };++ document_histories.insert("doc_exists".to_string(), history);++ // Call the function under test+ let result = construct_search_result(input, document_histories).unwrap();++ // Verify results+ assert_eq!(result.len(), 2);++ // Find each document in results+ let existing_doc = result+ .iter()+ .find(|r| r.extra.document_id == "doc_exists")+ .unwrap();+ let missing_doc = result+ .iter()+ .find(|r| r.extra.document_id == "doc_missing")+ .unwrap();++ // Existing document should have real timestamps+ assert_eq!(existing_doc.created_at, now.timestamp());+ assert_eq!(existing_doc.updated_at, now.timestamp());+ assert_eq!(existing_doc.viewed_at, Some(now.timestamp()));++ // Missing document should have default timestamps+ let default_time = chrono::DateTime::<chrono::Utc>::default().timestamp();+ assert_eq!(missing_doc.created_at, default_time);+ assert_eq!(missing_doc.updated_at, default_time);+ assert_eq!(missing_doc.viewed_at, None);+}diff --git a/rust/cloud-storage/search_service/src/api/search/email.rs b/rust/cloud-storage/search_service/src/api/search/email.rsindex debe5c03fc..59aca2b22e 100644--- a/rust/cloud-storage/search_service/src/api/search/email.rs+++ b/rust/cloud-storage/search_service/src/api/search/email.rs@@ -130,47 +130,4 @@ pub fn construct_search_result(}#[cfg(test)]-mod tests {- use super::*;-- #[test]- fn test_construct_search_result_empty_input() {- let result = construct_search_result(vec![], HashMap::new());- assert!(result.is_ok());- assert_eq!(result.unwrap().len(), 0);- }-- #[test]- fn test_construct_search_result_single_thread() {- let search_results = vec![opensearch_client::search::emails::EmailSearchResponse {- thread_id: "thread1".to_string(),- message_id: "msg1".to_string(),- sender: "[email protected]".to_string(),- recipients: vec!["[email protected]".to_string()],- cc: vec![],- bcc: vec![],- labels: vec!["inbox".to_string()],- link_id: "link1".to_string(),- user_id: "user1".to_string(),- updated_at: 1234567890,- sent_at: Some(1234567800),- subject: Some("Test Subject".to_string()),- content: Some(vec!["Test content".to_string()]),- }];-- let result = construct_search_result(search_results, HashMap::new()).unwrap();-- assert_eq!(result.len(), 1);- assert_eq!(result[0].extra.thread_id, "thread1");- assert_eq!(result[0].extra.user_id, "user1");- assert_eq!(result[0].extra.email_message_search_results.len(), 1);- assert_eq!(- result[0].extra.email_message_search_results[0].message_id,- "msg1"- );- assert_eq!(- result[0].extra.email_message_search_results[0].subject,- Some("Test Subject".to_string())- );- }-}+mod test;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.rsnew file mode 100644index 0000000000..3788a3cd55--- /dev/null+++ b/rust/cloud-storage/search_service/src/api/search/email/test.rs@@ -0,0 +1,47 @@+use opensearch_client::search::model::Highlight;++use super::*;++#[test]+fn test_construct_search_result_empty_input() {+ let result = construct_search_result(vec![], HashMap::new());+ assert!(result.is_ok());+ assert_eq!(result.unwrap().len(), 0);+}++#[test]+fn test_construct_search_result_single_thread() {+ let search_results = vec![opensearch_client::search::emails::EmailSearchResponse {+ thread_id: "thread1".to_string(),+ message_id: "msg1".to_string(),+ sender: "[email protected]".to_string(),+ recipients: vec!["[email protected]".to_string()],+ cc: vec![],+ bcc: vec![],+ labels: vec!["inbox".to_string()],+ link_id: "link1".to_string(),+ user_id: "user1".to_string(),+ updated_at: 1234567890,+ sent_at: Some(1234567800),+ subject: Some("Test Subject".to_string()),+ highlight: Highlight {+ name: None,+ content: vec!["Test content".to_string()],+ },+ }];++ let result = construct_search_result(search_results, HashMap::new()).unwrap();++ assert_eq!(result.len(), 1);+ assert_eq!(result[0].extra.thread_id, "thread1");+ assert_eq!(result[0].extra.user_id, "user1");+ assert_eq!(result[0].extra.email_message_search_results.len(), 1);+ assert_eq!(+ result[0].extra.email_message_search_results[0].message_id,+ "msg1"+ );+ assert_eq!(+ result[0].extra.email_message_search_results[0].subject,+ Some("Test Subject".to_string())+ );+}diff --git a/rust/cloud-storage/search_service/src/api/swagger.rs b/rust/cloud-storage/search_service/src/api/swagger.rsindex aa4f941a2b..16a8f12bde 100644--- a/rust/cloud-storage/search_service/src/api/swagger.rs+++ b/rust/cloud-storage/search_service/src/api/swagger.rs@@ -29,7 +29,7 @@ use models_search::project::{ProjectSearchResult, SimpleProjectSearchResponse, SimpleProjectSearchResponseItem,};-use models_search::MatchType;+use models_search::{MatchType, SearchHighlight};#[derive(OpenApi)]#[openapi(@@ -60,6 +60,7 @@ use models_search::MatchType;schemas(EmptyResponse,MatchType,+ SearchHighlight,// DocumentFileType, DocumentSearchRequest, DocumentSearchResult, DocumentSearchResponseItem, DocumentSearchResponse,diff --git a/rust/cloud-storage/search_service/src/model/mod.rs b/rust/cloud-storage/search_service/src/model/mod.rsindex 876fbebacc..1f4601c48a 100644--- a/rust/cloud-storage/search_service/src/model/mod.rs+++ b/rust/cloud-storage/search_service/src/model/mod.rs@@ -26,17 +26,13 @@ impl ItemId for ChatOpenSearchResponse {impl From<&ChatOpenSearchResponse> for Option<ChatMessageSearchResult> {fn from(response: &ChatOpenSearchResponse) -> Self {- response- .inner- .content- .as_ref()- .map(|content| ChatMessageSearchResult {- chat_message_id: response.inner.chat_message_id.clone(),- role: response.inner.role.clone(),- content: content.clone(),- updated_at: response.inner.updated_at,- title: response.inner.title.clone(),- })+ Some(ChatMessageSearchResult {+ chat_message_id: response.inner.chat_message_id.clone(),+ role: response.inner.role.clone(),+ highlight: response.inner.highlight.clone().into(),+ updated_at: response.inner.updated_at,+ title: response.inner.title.clone(),+ })}}@@ -76,13 +72,9 @@ impl Metadata<ProjectSearchMetadata> for ProjectOpenSearchResponse {impl From<&ProjectOpenSearchResponse> for Option<ProjectSearchResult> {fn from(response: &ProjectOpenSearchResponse) -> Self {- response- .inner- .content- .as_ref()- .map(|content| ProjectSearchResult {- content: content.clone(),- })+ Some(ProjectSearchResult {+ highlight: response.inner.highlight.clone().into(),+ })}}// Document@@ -112,16 +104,12 @@ impl ItemId for DocumentOpenSearchResponse {impl From<&DocumentOpenSearchResponse> for Option<DocumentSearchResult> {fn from(response: &DocumentOpenSearchResponse) -> Self {- response- .inner- .content- .as_ref()- .map(|content| DocumentSearchResult {- node_id: response.inner.node_id.clone(),- raw_content: response.inner.raw_content.clone(),- updated_at: response.inner.updated_at,- content: content.clone(),- })+ Some(DocumentSearchResult {+ node_id: response.inner.node_id.clone(),+ raw_content: response.inner.raw_content.clone(),+ updated_at: response.inner.updated_at,+ highlight: response.inner.highlight.clone().into(),+ })}}@@ -158,7 +146,7 @@ impl From<&EmailOpenSearchResponse> for Option<EmailSearchResult> {cc: response.inner.cc.clone(),bcc: response.inner.bcc.clone(),labels: response.inner.labels.clone(),- content: response.inner.content.clone().unwrap_or_default(),+ highlight: response.inner.highlight.clone().into(),updated_at: response.inner.updated_at,sent_at: response.inner.sent_at,})@@ -191,17 +179,13 @@ impl ItemId for ChannelOpenSearchResponse {impl From<&ChannelOpenSearchResponse> for Option<ChannelSearchResult> {fn from(response: &ChannelOpenSearchResponse) -> Self {- response- .inner- .content- .as_ref()- .map(|content| ChannelSearchResult {- message_id: response.inner.message_id.clone(),- thread_id: response.inner.thread_id.clone(),- sender_id: response.inner.sender_id.clone(),- content: content.clone(),- updated_at: response.inner.updated_at,- created_at: response.inner.created_at,- })+ Some(ChannelSearchResult {+ message_id: response.inner.message_id.clone(),+ thread_id: response.inner.thread_id.clone(),+ sender_id: response.inner.sender_id.clone(),+ highlight: response.inner.highlight.clone().into(),+ updated_at: response.inner.updated_at,+ created_at: response.inner.created_at,+ })}}