Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(search): update search to use the correct uuid type (#579)

Will Hutchinsonb9010db6a931
diff --git a/rust/cloud-storage/models_search/src/channel.rs b/rust/cloud-storage/models_search/src/channel.rs
index c5bc611d7f..97209e98f1 100644
--- a/rust/cloud-storage/models_search/src/channel.rs
+++ b/rust/cloud-storage/models_search/src/channel.rs
@@ -9,9 +9,9 @@ use utoipa::ToSchema;
pub struct ChannelSearchResult {
/// The channel message id
/// This is only prsent if the search result is on the message content
- pub message_id: Option<String>,
+ pub message_id: Option<uuid::Uuid>,
/// The channel message thread id
- pub thread_id: Option<String>,
+ pub thread_id: Option<uuid::Uuid>,
/// The sender id
/// This is only prsent if the search result is on the message content
pub sender_id: Option<String>,
@@ -34,14 +34,14 @@ pub struct ChannelSearchResponseItem {
/// Standardized fields that all item types will share.
/// These field names are being aligned across all item types
/// for consistency in our data model.
- pub id: String,
+ pub id: uuid::Uuid,
/// we don't store this for channels atm but keeping it here for consistency
pub owner_id: Option<String>,
/// The type of channel
pub channel_type: String,
/// The id of the channel
- pub channel_id: String,
+ pub channel_id: uuid::Uuid,
/// The search results for the channel
/// This may be empty if the search result match was not on content
pub channel_message_search_results: Vec<ChannelSearchResult>,
@@ -71,7 +71,7 @@ pub struct ChannelSearchResponseItemWithMetadata {
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct ChannelSearchMetadata {
/// The id of the channel
- pub channel_id: String,
+ pub channel_id: uuid::Uuid,
/// The type of channel
pub channel_type: String,
}
@@ -81,11 +81,11 @@ impl From<SearchResponseItem<ChannelSearchResult, ChannelSearchMetadata>>
{
fn from(response: SearchResponseItem<ChannelSearchResult, ChannelSearchMetadata>) -> Self {
ChannelSearchResponseItem {
- id: response.metadata.channel_id.clone(),
+ id: response.metadata.channel_id,
// we don't store this for channels atm but keeping it here for consistency
owner_id: None,
channel_type: response.metadata.channel_type.clone(),
- channel_id: response.metadata.channel_id.clone(),
+ channel_id: response.metadata.channel_id,
channel_message_search_results: response.results,
}
}
diff --git a/rust/cloud-storage/models_search/src/chat.rs b/rust/cloud-storage/models_search/src/chat.rs
index 3aa7026203..62a74b13ff 100644
--- a/rust/cloud-storage/models_search/src/chat.rs
+++ b/rust/cloud-storage/models_search/src/chat.rs
@@ -10,7 +10,7 @@ use crate::{MatchType, SearchHighlight, SearchOn, SearchResponseItem};
pub struct ChatMessageSearchResult {
/// The chat message id for the chat
/// This is only present if the search match was on the chat message content
- pub chat_message_id: Option<String>,
+ pub chat_message_id: Option<uuid::Uuid>,
/// The role of the chat message
/// This is only present if the search match was on the chat message content
pub role: Option<String>,
@@ -27,12 +27,12 @@ pub struct ChatSearchResponseItem {
/// Standardized fields that all item types will share.
/// These field names are being aligned across all item types
/// for consistency in our data model.
- pub id: String,
+ pub id: uuid::Uuid,
pub name: String,
pub owner_id: String,
/// The id of the chat
- pub chat_id: String,
+ pub chat_id: uuid::Uuid,
/// The id of the creator of the chat
pub user_id: String,
/// The search results for the chat
@@ -95,7 +95,7 @@ pub struct ChatSearchRequest {
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct ChatSearchMetadata {
/// The id of the chat
- pub chat_id: String,
+ pub chat_id: uuid::Uuid,
/// The id of the creator of the chat
pub user_id: String,
/// The name of the chat
@@ -107,10 +107,10 @@ impl From<SearchResponseItem<ChatMessageSearchResult, ChatSearchMetadata>>
{
fn from(response: SearchResponseItem<ChatMessageSearchResult, ChatSearchMetadata>) -> Self {
ChatSearchResponseItem {
- id: response.metadata.chat_id.clone(),
+ id: response.metadata.chat_id,
name: response.metadata.title.clone(),
owner_id: response.metadata.user_id.clone(),
- chat_id: response.metadata.chat_id.clone(),
+ chat_id: response.metadata.chat_id,
user_id: response.metadata.user_id.clone(),
chat_search_results: response.results,
}
diff --git a/rust/cloud-storage/models_search/src/chat/test.rs b/rust/cloud-storage/models_search/src/chat/test.rs
index 112681d9ea..6b09c2291f 100644
--- a/rust/cloud-storage/models_search/src/chat/test.rs
+++ b/rust/cloud-storage/models_search/src/chat/test.rs
@@ -213,20 +213,20 @@ fn test_search_response_item_to_chat_response_item_with_metadata() {
let search_item = SearchResponseItem {
results: vec![
ChatMessageSearchResult {
- chat_message_id: Some("msg_1".to_string()),
+ chat_message_id: Some("11111111-1111-1111-1111-111111111111".parse().unwrap()),
role: Some("user".to_string()),
highlight: SearchHighlight::default(),
score: None,
},
ChatMessageSearchResult {
- chat_message_id: Some("msg_2".to_string()),
+ chat_message_id: Some("22222222-2222-2222-2222-222222222222".parse().unwrap()),
role: Some("assistant".to_string()),
highlight: SearchHighlight::default(),
score: None,
},
],
metadata: ChatSearchMetadata {
- chat_id: "chat_123".to_string(),
+ chat_id: "11111111-1111-1111-1111-111111111123".parse().unwrap(),
user_id: "user_456".to_string(),
title: "hello".to_string(),
},
@@ -234,8 +234,14 @@ fn test_search_response_item_to_chat_response_item_with_metadata() {
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.chat_id.to_string(),
+ "11111111-1111-1111-1111-111111111123"
+ );
+ assert_eq!(
+ chat_response.id.to_string(),
+ "11111111-1111-1111-1111-111111111123"
+ );
assert_eq!(chat_response.user_id, "user_456");
assert_eq!(chat_response.owner_id, "user_456");
assert_eq!(chat_response.name, "hello");
@@ -244,15 +250,17 @@ fn test_search_response_item_to_chat_response_item_with_metadata() {
chat_response.chat_search_results[0]
.chat_message_id
.as_ref()
- .unwrap(),
- "msg_1"
+ .unwrap()
+ .to_string(),
+ "11111111-1111-1111-1111-111111111111"
);
assert_eq!(
chat_response.chat_search_results[1]
.chat_message_id
.as_ref()
- .unwrap(),
- "msg_2"
+ .unwrap()
+ .to_string(),
+ "22222222-2222-2222-2222-222222222222"
);
}
@@ -260,13 +268,13 @@ fn test_search_response_item_to_chat_response_item_with_metadata() {
fn test_serialization_equivalence() {
// Create a ChatSearchResponseItem directly
let direct_response = ChatSearchResponseItem {
- id: "chat_123".to_string(),
+ id: "11111111-1111-1111-1111-111111111123".parse().unwrap(),
name: "hello".to_string(),
owner_id: "user_456".to_string(),
- chat_id: "chat_123".to_string(),
+ chat_id: "11111111-1111-1111-1111-111111111123".parse().unwrap(),
user_id: "user_456".to_string(),
chat_search_results: vec![ChatMessageSearchResult {
- chat_message_id: Some("msg_1".to_string()),
+ chat_message_id: Some("11111111-1111-1111-1111-111111111111".parse().unwrap()),
role: Some("user".to_string()),
highlight: SearchHighlight::default(),
score: None,
@@ -276,13 +284,13 @@ fn test_serialization_equivalence() {
// Create the same thing via SearchResponseItem conversion
let search_item = SearchResponseItem {
results: vec![ChatMessageSearchResult {
- chat_message_id: Some("msg_1".to_string()),
+ chat_message_id: Some("11111111-1111-1111-1111-111111111111".parse().unwrap()),
role: Some("user".to_string()),
highlight: SearchHighlight::default(),
score: None,
}],
metadata: ChatSearchMetadata {
- chat_id: "chat_123".to_string(),
+ chat_id: "11111111-1111-1111-1111-111111111123".parse().unwrap(),
user_id: "user_456".to_string(),
title: "hello".to_string(),
},
diff --git a/rust/cloud-storage/models_search/src/document.rs b/rust/cloud-storage/models_search/src/document.rs
index 5ca1f61f7b..ff2d05626f 100644
--- a/rust/cloud-storage/models_search/src/document.rs
+++ b/rust/cloud-storage/models_search/src/document.rs
@@ -29,11 +29,11 @@ pub struct DocumentSearchResponseItem {
/// Standardized fields that all item types will share.
/// These field names are being aligned across all item types
/// for consistency in our data model.
- pub id: String,
+ pub id: uuid::Uuid,
pub name: String,
pub owner_id: String,
/// The id of the document
- pub document_id: String,
+ pub document_id: uuid::Uuid,
/// The name of the document
pub document_name: String,
/// The file type of the document
diff --git a/rust/cloud-storage/models_search/src/email.rs b/rust/cloud-storage/models_search/src/email.rs
index b1a7f5cb50..d9a159ef98 100644
--- a/rust/cloud-storage/models_search/src/email.rs
+++ b/rust/cloud-storage/models_search/src/email.rs
@@ -41,7 +41,7 @@ pub struct EmailSearchResponseItem {
/// Standardized fields that all item types will share.
/// These field names are being aligned across all item types
/// for consistency in our data model.
- pub id: String,
+ pub id: uuid::Uuid,
/// Subject of the email thread
pub name: Option<String>,
pub owner_id: String,
@@ -51,7 +51,7 @@ pub struct EmailSearchResponseItem {
pub subject: Option<String>,
/// The id of the email thread
- pub thread_id: String,
+ pub thread_id: uuid::Uuid,
/// The id of the owner of the email thread
pub user_id: String,
/// The search results for the document
@@ -76,7 +76,7 @@ pub struct EmailSearchResponseItemWithMetadata {
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct EmailSearchMetadata {
/// The id of the email thread
- pub thread_id: String,
+ pub thread_id: uuid::Uuid,
/// The id of the owner of the email thread
pub user_id: String,
}
diff --git a/rust/cloud-storage/models_search/src/project.rs b/rust/cloud-storage/models_search/src/project.rs
index 81ae03c1fa..49b4231dbb 100644
--- a/rust/cloud-storage/models_search/src/project.rs
+++ b/rust/cloud-storage/models_search/src/project.rs
@@ -15,7 +15,7 @@ pub struct ProjectSearchResult {
/// Metadata associated with Project Search, to be used with SearchResponseItem
#[derive(Debug, Serialize, Deserialize, ToSchema)]
pub struct ProjectSearchMetadata {
- pub project_id: String,
+ pub project_id: uuid::Uuid,
pub owner_id: String,
pub updated_at: i64,
pub created_at: i64,
@@ -28,7 +28,7 @@ pub struct ProjectSearchResponseItem {
/// Standardized fields that all item types will share.
/// These field names are being aligned across all item types
/// for consistency in our data model.
- pub id: String,
+ pub id: uuid::Uuid,
pub name: String,
pub owner_id: String,
diff --git a/rust/cloud-storage/models_search/src/simple.rs b/rust/cloud-storage/models_search/src/simple.rs
index c16be23a31..91348986f1 100644
--- a/rust/cloud-storage/models_search/src/simple.rs
+++ b/rust/cloud-storage/models_search/src/simple.rs
@@ -25,7 +25,7 @@ pub struct SearchGotoDocument {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct SearchGotoChat {
/// The chat message id
- pub chat_message_id: String,
+ pub chat_message_id: uuid::Uuid,
/// The role of the chat message
pub role: String,
}
@@ -45,7 +45,7 @@ pub struct SearchGotoEmail {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone, ToSchema)]
pub struct SearchGotoChannel {
/// The channel message id
- pub channel_message_id: String,
+ pub channel_message_id: uuid::Uuid,
}
/// The search service version of a goto
@@ -96,7 +96,7 @@ impl From<opensearch_client::search::model::SearchGotoContent> for SearchGotoCon
/// Simple response item to mimic what we get back from opensearch
#[derive(Debug, serde::Serialize, serde::Deserialize, ToSchema)]
pub struct SimpleSearchResponseItem {
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
pub entity_type: String,
pub score: Option<f64>,
pub highlight: Highlight,
diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rs
index bcde4d7f47..1efd1ccd6b 100644
--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs
@@ -21,11 +21,11 @@ use serde_json::Value;
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub(crate) struct ChannelMessageIndex {
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
pub channel_type: String,
pub org_id: Option<i64>,
- pub message_id: String,
- pub thread_id: Option<String>,
+ pub message_id: uuid::Uuid,
+ pub thread_id: Option<uuid::Uuid>,
pub sender_id: String,
pub mentions: Vec<String>,
pub content: String,
diff --git a/rust/cloud-storage/opensearch_client/src/search/chats.rs b/rust/cloud-storage/opensearch_client/src/search/chats.rs
index 712062efaf..20629c7d85 100644
--- a/rust/cloud-storage/opensearch_client/src/search/chats.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/chats.rs
@@ -22,8 +22,8 @@ use serde_json::Value;
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub(crate) struct ChatIndex {
- pub entity_id: String,
- pub chat_message_id: String,
+ pub entity_id: uuid::Uuid,
+ pub chat_message_id: uuid::Uuid,
pub user_id: String,
pub role: String,
pub updated_at_seconds: i64,
diff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rs
index ace004ebfc..d585a5ef1e 100644
--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs
@@ -79,7 +79,7 @@ impl DocumentQueryBuilder {
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub(crate) struct DocumentIndex {
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
pub document_name: String,
pub node_id: String,
pub raw_content: Option<String>,
diff --git a/rust/cloud-storage/opensearch_client/src/search/documents/test.rs b/rust/cloud-storage/opensearch_client/src/search/documents/test.rs
index 7a6c236743..4cc35a838d 100644
--- a/rust/cloud-storage/opensearch_client/src/search/documents/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/documents/test.rs
@@ -1,5 +1,3 @@
-use crate::search::model::SearchResponse;
-
use super::*;
use opensearch_query_builder::ToOpenSearchJson;
diff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rs
index fc3c195159..7d9f75f94e 100644
--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs
@@ -161,7 +161,7 @@ impl EmailQueryBuilder {
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub(crate) struct EmailIndex {
/// The id of the email thread
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
/// The id of the email message
pub message_id: uuid::Uuid,
/// The sender of the email message
diff --git a/rust/cloud-storage/opensearch_client/src/search/model.rs b/rust/cloud-storage/opensearch_client/src/search/model.rs
index 2c07bd2031..782598cb0f 100644
--- a/rust/cloud-storage/opensearch_client/src/search/model.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/model.rs
@@ -94,7 +94,7 @@ pub(crate) struct SearchResponse<T> {
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct NameIndex {
/// The entity id
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
/// The entity type
pub entity_type: SearchEntityType,
/// The name of the entity
@@ -117,7 +117,7 @@ pub struct SearchGotoDocument {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct SearchGotoChat {
/// The chat message id
- pub chat_message_id: String,
+ pub chat_message_id: uuid::Uuid,
/// The role of the chat message
pub role: String,
}
@@ -143,8 +143,8 @@ pub struct SearchGotoEmail {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct SearchGotoChannel {
/// The channel message id
- pub channel_message_id: String,
- pub thread_id: Option<String>,
+ pub channel_message_id: uuid::Uuid,
+ pub thread_id: Option<uuid::Uuid>,
pub sender_id: String,
pub created_at: i64,
pub updated_at: i64,
@@ -165,7 +165,7 @@ pub enum SearchGotoContent {
#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]
pub struct SearchHit {
/// The id of the entity
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
/// The entity type
pub entity_type: SearchEntityType,
/// The score of the match
diff --git a/rust/cloud-storage/opensearch_client/src/search/projects.rs b/rust/cloud-storage/opensearch_client/src/search/projects.rs
index 5575b857eb..c1efbb10e9 100644
--- a/rust/cloud-storage/opensearch_client/src/search/projects.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/projects.rs
@@ -82,9 +82,9 @@ impl ProjectQueryBuilder {
#[derive(Debug, Serialize, Deserialize)]
pub struct ProjectIndex {
- pub entity_id: String,
+ pub entity_id: uuid::Uuid,
pub user_id: String,
- pub parent_project_id: Option<String>,
+ pub parent_project_id: Option<uuid::Uuid>,
pub project_name: String,
pub created_at_seconds: i64,
pub updated_at_seconds: i64,
diff --git a/rust/cloud-storage/search_service/src/api/search/channel.rs b/rust/cloud-storage/search_service/src/api/search/channel.rs
index 066803104f..ac3bcb0cf7 100644
--- a/rust/cloud-storage/search_service/src/api/search/channel.rs
+++ b/rust/cloud-storage/search_service/src/api/search/channel.rs
@@ -36,10 +36,7 @@ pub(in crate::api::search) async fn enrich_channels(
}
// Extract channel IDs from results
- let channel_ids: Vec<Uuid> = results
- .iter()
- .map(|r| r.entity_id.parse().unwrap())
- .collect();
+ let channel_ids: Vec<Uuid> = results.iter().map(|r| r.entity_id).collect();
// Fetch channel metadata from comms service
let channel_histories = ctx
@@ -143,7 +140,7 @@ pub fn construct_search_result(
updated_at: None,
}
};
- (hit.entity_id.parse().unwrap(), result)
+ (hit.entity_id, result)
})
.fold(IndexMap::new(), |mut map, (entity_id, result)| {
map.entry(entity_id).or_insert_with(Vec::new).push(result);
@@ -165,8 +162,8 @@ pub fn construct_search_result(
Some(ChannelSearchResponseItemWithMetadata {
metadata: Some(metadata),
extra: ChannelSearchResponseItem {
- id: entity_id.to_string(),
- channel_id: entity_id.to_string(),
+ id: entity_id,
+ channel_id: entity_id,
owner_id: Some(info.user_id),
channel_type: info.channel_type,
channel_message_search_results: hits,
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.rs
index ed8c1d14c0..143e1ce6d7 100644
--- a/rust/cloud-storage/search_service/src/api/search/channel/test.rs
+++ b/rust/cloud-storage/search_service/src/api/search/channel/test.rs
@@ -12,17 +12,17 @@ fn test_construct_search_result_empty_input() {
#[test]
fn test_construct_search_result_single_channel() {
- let channel_uuid = "550e8400-e29b-41d4-a716-446655440000";
+ let channel_uuid: Uuid = "550e8400-e29b-41d4-a716-446655440000".parse().unwrap();
let search_results = vec![opensearch_client::search::model::SearchHit {
- entity_id: channel_uuid.to_string(),
+ entity_id: channel_uuid,
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg1".to_string(),
+ channel_message_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread1".to_string()),
+ thread_id: Some("22222222-2222-2222-2222-222222222222".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -36,8 +36,8 @@ fn test_construct_search_result_single_channel() {
let mut channel_histories = HashMap::new();
channel_histories.insert(
- Uuid::parse_str(channel_uuid).unwrap(),
- create_channel_history(channel_uuid),
+ channel_uuid,
+ create_channel_history(channel_uuid.to_string().as_str()),
);
let result = construct_search_result(search_results, channel_histories).unwrap();
@@ -49,8 +49,9 @@ fn test_construct_search_result_single_channel() {
result[0].extra.channel_message_search_results[0]
.message_id
.as_ref()
- .unwrap(),
- "msg1"
+ .unwrap()
+ .to_string(),
+ "11111111-1111-1111-1111-111111111111"
);
assert_eq!(
result[0].extra.channel_message_search_results[0]
@@ -61,24 +62,24 @@ fn test_construct_search_result_single_channel() {
);
assert_eq!(
result[0].extra.channel_message_search_results[0].thread_id,
- Some("thread1".to_string())
+ Some("22222222-2222-2222-2222-222222222222".parse().unwrap())
);
}
#[test]
fn test_construct_search_result_multiple_messages_same_channel() {
- let channel_uuid = "550e8400-e29b-41d4-a716-446655440001";
+ let channel_uuid: Uuid = "550e8400-e29b-41d4-a716-446655440001".parse().unwrap();
let search_results = vec![
opensearch_client::search::model::SearchHit {
- entity_id: channel_uuid.to_string(),
+ entity_id: channel_uuid,
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg1".to_string(),
+ channel_message_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread1".to_string()),
+ thread_id: Some("22222222-2222-2222-2222-222222222222".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -90,15 +91,15 @@ fn test_construct_search_result_multiple_messages_same_channel() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: channel_uuid.to_string(),
+ entity_id: channel_uuid,
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg2".to_string(),
+ channel_message_id: "22222222-2222-2222-2222-222222222222".parse().unwrap(),
created_at: 1234567892,
updated_at: 1234567893,
- thread_id: Some("thread2".to_string()),
+ thread_id: Some("33333333-3333-3333-3333-333333333333".parse().unwrap()),
sender_id: "user2".to_string(),
},
),
@@ -113,8 +114,8 @@ fn test_construct_search_result_multiple_messages_same_channel() {
let mut channel_histories = HashMap::new();
channel_histories.insert(
- Uuid::parse_str(channel_uuid).unwrap(),
- create_channel_history(channel_uuid),
+ channel_uuid,
+ create_channel_history(channel_uuid.to_string().as_str()),
);
let result = construct_search_result(search_results, channel_histories).unwrap();
@@ -128,10 +129,10 @@ fn test_construct_search_result_multiple_messages_same_channel() {
.extra
.channel_message_search_results
.iter()
- .map(|r| r.message_id.clone().unwrap())
+ .map(|r| r.message_id.unwrap().to_string())
.collect();
- assert!(message_ids.contains(&"msg1".to_string()));
- assert!(message_ids.contains(&"msg2".to_string()));
+ assert!(message_ids.contains(&"11111111-1111-1111-1111-111111111111".to_string()));
+ assert!(message_ids.contains(&"22222222-2222-2222-2222-222222222222".to_string()));
let sender_ids: Vec<String> = result[0]
.extra
@@ -145,18 +146,18 @@ fn test_construct_search_result_multiple_messages_same_channel() {
#[test]
fn test_construct_search_result_filters_messages_without_content() {
- let channel_uuid = "550e8400-e29b-41d4-a716-446655440002";
+ let channel_uuid: Uuid = "550e8400-e29b-41d4-a716-446655440002".parse().unwrap();
let search_results = vec![
opensearch_client::search::model::SearchHit {
- entity_id: channel_uuid.to_string(),
+ entity_id: channel_uuid,
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg1".to_string(),
+ channel_message_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread1".to_string()),
+ thread_id: Some("22222222-2222-2222-2222-222222222222".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -168,15 +169,15 @@ fn test_construct_search_result_filters_messages_without_content() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: channel_uuid.to_string(),
+ entity_id: channel_uuid,
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg2".to_string(),
+ channel_message_id: "22222222-2222-2222-2222-222222222222".parse().unwrap(),
created_at: 1234567892,
updated_at: 1234567893,
- thread_id: Some("thread2".to_string()),
+ thread_id: Some("33333333-3333-3333-3333-333333333333".parse().unwrap()),
sender_id: "user2".to_string(),
},
),
@@ -191,8 +192,8 @@ fn test_construct_search_result_filters_messages_without_content() {
let mut channel_histories = HashMap::new();
channel_histories.insert(
- Uuid::parse_str(channel_uuid).unwrap(),
- create_channel_history(channel_uuid),
+ channel_uuid,
+ create_channel_history(channel_uuid.to_string().as_str()),
);
let result = construct_search_result(search_results, channel_histories).unwrap();
@@ -203,8 +204,9 @@ fn test_construct_search_result_filters_messages_without_content() {
result[0].extra.channel_message_search_results[0]
.message_id
.as_ref()
- .unwrap(),
- "msg1"
+ .unwrap()
+ .to_string(),
+ "11111111-1111-1111-1111-111111111111"
);
}
@@ -215,15 +217,15 @@ fn create_test_channel_response(
content: Option<Vec<String>>,
) -> opensearch_client::search::model::SearchHit {
opensearch_client::search::model::SearchHit {
- entity_id: channel_id.to_string(),
+ entity_id: channel_id.parse().unwrap(),
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: message_id.to_string(),
+ channel_message_id: message_id.parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread1".to_string()),
+ thread_id: Some("22222222-2222-2222-2222-222222222222".parse().unwrap()),
sender_id: sender_id.to_string(),
},
),
@@ -272,7 +274,7 @@ fn test_channel_history_timestamps() {
// Create a test response with the UUID
let input = vec![create_test_channel_response(
&channel_uuid.to_string(),
- "msg_1",
+ "11111111-1111-1111-1111-111111111111",
"user_1",
Some(vec!["hello world".to_string()]),
)];
@@ -296,7 +298,7 @@ fn test_channel_history_missing_entry() {
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",
+ "11111111-1111-1111-1111-111111111111",
"user_1",
Some(vec!["hello world".to_string()]),
)];
@@ -331,7 +333,7 @@ fn test_channel_history_null_viewed_at() {
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",
+ "11111111-1111-1111-1111-111111111111",
"user_1",
Some(vec!["hello world".to_string()]),
)];
@@ -367,25 +369,28 @@ fn test_channel_history_null_viewed_at() {
#[test]
fn test_sort_stability() {
- let channel_ids = [
+ let channel_ids: Vec<Uuid> = [
"550e8400-e29b-41d4-a716-446655440003",
"550e8400-e29b-41d4-a716-446655440001",
"550e8400-e29b-41d4-a716-446655440005",
"550e8400-e29b-41d4-a716-446655440002",
"550e8400-e29b-41d4-a716-446655440004",
- ];
+ ]
+ .iter()
+ .map(|s| s.parse().unwrap())
+ .collect::<Vec<_>>();
let input = vec![
opensearch_client::search::model::SearchHit {
- entity_id: channel_ids[0].to_string(),
+ entity_id: channel_ids[0],
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg3".to_string(),
+ channel_message_id: "33333333-3333-3333-3333-333333333333".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread3".to_string()),
+ thread_id: Some("33333333-3333-3333-3333-333333333333".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -397,15 +402,15 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: channel_ids[1].to_string(),
+ entity_id: channel_ids[1],
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg1".to_string(),
+ channel_message_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread1".to_string()),
+ thread_id: Some("11111111-1111-1111-1111-111111111111".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -417,15 +422,15 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: channel_ids[2].to_string(),
+ entity_id: channel_ids[2],
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg5".to_string(),
+ channel_message_id: "55555555-5555-5555-5555-555555555555".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread5".to_string()),
+ thread_id: Some("55555555-5555-5555-5555-555555555555".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -437,15 +442,15 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: channel_ids[3].to_string(),
+ entity_id: channel_ids[3],
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg2".to_string(),
+ channel_message_id: "22222222-2222-2222-2222-222222222222".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread2".to_string()),
+ thread_id: Some("22222222-2222-2222-2222-222222222222".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -457,15 +462,15 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: channel_ids[4].to_string(),
+ entity_id: channel_ids[4],
entity_type: SearchEntityType::Channels,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Channels(
opensearch_client::search::model::SearchGotoChannel {
- channel_message_id: "msg4".to_string(),
+ channel_message_id: "44444444-4444-4444-4444-444444444444".parse().unwrap(),
created_at: 1234567890,
updated_at: 1234567891,
- thread_id: Some("thread4".to_string()),
+ thread_id: Some("44444444-4444-4444-4444-444444444444".parse().unwrap()),
sender_id: "user1".to_string(),
},
),
@@ -481,8 +486,8 @@ fn test_sort_stability() {
let mut channel_histories = HashMap::new();
for channel_id in &channel_ids {
channel_histories.insert(
- Uuid::parse_str(channel_id).unwrap(),
- create_channel_history(channel_id),
+ channel_id.clone(),
+ create_channel_history(channel_id.to_string().as_str()),
);
}
@@ -494,9 +499,9 @@ fn test_sort_stability() {
assert_eq!(result2.len(), 5);
assert_eq!(result3.len(), 5);
- let ids1: Vec<String> = result1.iter().map(|r| r.extra.id.clone()).collect();
- let ids2: Vec<String> = result2.iter().map(|r| r.extra.id.clone()).collect();
- let ids3: Vec<String> = result3.iter().map(|r| r.extra.id.clone()).collect();
+ let ids1: Vec<Uuid> = result1.iter().map(|r| r.extra.id.clone()).collect();
+ let ids2: Vec<Uuid> = result2.iter().map(|r| r.extra.id.clone()).collect();
+ let ids3: Vec<Uuid> = result3.iter().map(|r| r.extra.id.clone()).collect();
assert_eq!(ids1, ids2, "Results should be stable between runs");
assert_eq!(ids2, ids3, "Results should be stable between runs");
diff --git a/rust/cloud-storage/search_service/src/api/search/chat.rs b/rust/cloud-storage/search_service/src/api/search/chat.rs
index e6289f17c0..8ff3ecae9d 100644
--- a/rust/cloud-storage/search_service/src/api/search/chat.rs
+++ b/rust/cloud-storage/search_service/src/api/search/chat.rs
@@ -14,6 +14,7 @@ use models_search::chat::{
ChatSearchResponseItemWithMetadata,
};
use opensearch_client::search::model::SearchGotoContent;
+use sqlx::types::Uuid;
use std::collections::HashMap;
use super::SearchPaginationParams;
@@ -34,7 +35,7 @@ pub(in crate::api::search) async fn enrich_chats(
return Ok(vec![]);
}
// Extract chat IDs from results
- let chat_ids: Vec<String> = results.iter().map(|r| r.entity_id.clone()).collect();
+ let chat_ids: Vec<String> = results.iter().map(|r| r.entity_id.to_string()).collect();
// Fetch chat metadata from database
let chat_histories =
@@ -100,7 +101,7 @@ pub fn construct_search_result(
chat_histories: HashMap<String, macro_db_client::chat::get::ChatHistoryInfo>,
) -> anyhow::Result<Vec<ChatSearchResponseItemWithMetadata>> {
// construct entity hit map of id -> vec<hits> using IndexMap to preserve insertion order
- let entity_id_hit_map: IndexMap<String, Vec<ChatMessageSearchResult>> = search_results
+ let entity_id_hit_map: IndexMap<Uuid, Vec<ChatMessageSearchResult>> = search_results
.into_iter()
.map(|hit| {
let result = if let Some(SearchGotoContent::Chats(goto)) = hit.goto {
@@ -130,7 +131,7 @@ pub fn construct_search_result(
let result: Vec<ChatSearchResponseItemWithMetadata> = entity_id_hit_map
.into_iter()
.filter_map(|(entity_id, hits)| {
- if let Some(info) = chat_histories.get(&entity_id) {
+ if let Some(info) = chat_histories.get(&entity_id.to_string()) {
let info = info.clone();
let metadata = models_search::chat::ChatMetadata {
created_at: info.created_at.timestamp(),
@@ -142,7 +143,7 @@ pub fn construct_search_result(
Some(ChatSearchResponseItemWithMetadata {
metadata: Some(metadata),
extra: ChatSearchResponseItem {
- id: entity_id.clone(),
+ id: entity_id,
chat_id: entity_id,
owner_id: info.user_id.clone(),
user_id: info.user_id,
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.rs
index 87e69686b7..3b1be76b29 100644
--- a/rust/cloud-storage/search_service/src/api/search/chat/test.rs
+++ b/rust/cloud-storage/search_service/src/api/search/chat/test.rs
@@ -10,11 +10,11 @@ fn create_test_response(
content: Option<Vec<String>>,
) -> opensearch_client::search::model::SearchHit {
opensearch_client::search::model::SearchHit {
- entity_id: chat_id.to_string(),
+ entity_id: chat_id.parse().unwrap(),
entity_type: SearchEntityType::Chats,
goto: Some(opensearch_client::search::model::SearchGotoContent::Chats(
opensearch_client::search::model::SearchGotoChat {
- chat_message_id: chat_message_id.to_string(),
+ chat_message_id: chat_message_id.parse().unwrap(),
role: "user".to_string(),
},
)),
@@ -50,17 +50,17 @@ fn test_empty_input() {
#[test]
fn test_single_chat_with_content() {
let input = vec![create_test_response(
- "chat_1",
- "msg_1",
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
Some(vec!["hello world".to_string()]),
)];
let mut chat_histories = HashMap::new();
let now = chrono::Utc::now();
chat_histories.insert(
- "chat_1".to_string(),
+ "11111111-1111-1111-1111-111111111111".to_string(),
macro_db_client::chat::get::ChatHistoryInfo {
- item_id: "chat_1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: None,
@@ -74,8 +74,14 @@ fn test_single_chat_with_content() {
let result = construct_search_result(input, chat_histories).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_id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
+ assert_eq!(
+ result[0].extra.id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
assert_eq!(result[0].extra.user_id, "user_1");
assert_eq!(result[0].extra.owner_id, "user_1");
assert_eq!(result[0].extra.name, "name");
@@ -84,8 +90,9 @@ fn test_single_chat_with_content() {
result[0].extra.chat_search_results[0]
.chat_message_id
.as_ref()
- .unwrap(),
- "msg_1"
+ .unwrap()
+ .to_string(),
+ "11111111-1111-1111-1111-111111111111"
);
assert_eq!(
result[0].extra.chat_search_results[0].highlight.content,
@@ -95,16 +102,29 @@ fn test_single_chat_with_content() {
#[test]
fn test_single_chat_without_content() {
- let input = vec![create_test_response("chat_1", "msg_1", None)];
+ let input = vec![create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
+ None,
+ )];
let mut chat_histories = HashMap::new();
- chat_histories.insert("chat_1".to_string(), create_chat_history("chat_1"));
+ chat_histories.insert(
+ "11111111-1111-1111-1111-111111111111".to_string(),
+ create_chat_history("11111111-1111-1111-1111-111111111111"),
+ );
let result = construct_search_result(input, chat_histories).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_id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
+ assert_eq!(
+ result[0].extra.id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
assert_eq!(result[0].extra.user_id, "user_1");
assert_eq!(result[0].extra.owner_id, "user_1");
assert_eq!(result[0].extra.name, "name");
@@ -114,50 +134,81 @@ fn test_single_chat_without_content() {
#[test]
fn test_single_chat_multiple_messages() {
let input = vec![
- create_test_response("chat_1", "msg_1", Some(vec!["hello".to_string()])),
- create_test_response("chat_1", "msg_2", Some(vec!["world".to_string()])),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
+ Some(vec!["hello".to_string()]),
+ ),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "22222222-2222-2222-2222-222222222222",
+ Some(vec!["world".to_string()]),
+ ),
];
let mut chat_histories = HashMap::new();
- chat_histories.insert("chat_1".to_string(), create_chat_history("chat_1"));
+ chat_histories.insert(
+ "11111111-1111-1111-1111-111111111111".to_string(),
+ create_chat_history("11111111-1111-1111-1111-111111111111"),
+ );
let result = construct_search_result(input, chat_histories).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_id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
+ assert_eq!(
+ result[0].extra.id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
assert_eq!(result[0].extra.chat_search_results.len(), 2);
// Check both messages are present
- let message_ids: Vec<&String> = result[0]
+ let message_ids: Vec<&Uuid> = result[0]
.extra
.chat_search_results
.iter()
.map(|r| r.chat_message_id.as_ref().unwrap())
.collect();
- assert!(message_ids.contains(&&"msg_1".to_string()));
- assert!(message_ids.contains(&&"msg_2".to_string()));
+ assert!(message_ids.contains(&&"11111111-1111-1111-1111-111111111111".parse().unwrap()));
+ assert!(message_ids.contains(&&"22222222-2222-2222-2222-222222222222".parse().unwrap()));
}
#[test]
fn test_multiple_chats() {
let input = vec![
- create_test_response("chat_1", "msg_1", Some(vec!["hello".to_string()])),
- create_test_response("chat_2", "msg_2", Some(vec!["world".to_string()])),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
+ Some(vec!["hello".to_string()]),
+ ),
+ create_test_response(
+ "22222222-2222-2222-2222-222222222222",
+ "22222222-2222-2222-2222-222222222222",
+ Some(vec!["world".to_string()]),
+ ),
];
let mut chat_histories = HashMap::new();
- chat_histories.insert("chat_1".to_string(), create_chat_history("chat_1"));
- chat_histories.insert("chat_2".to_string(), create_chat_history("chat_2"));
+ chat_histories.insert(
+ "11111111-1111-1111-1111-111111111111".to_string(),
+ create_chat_history("11111111-1111-1111-1111-111111111111"),
+ );
+ chat_histories.insert(
+ "22222222-2222-2222-2222-222222222222".to_string(),
+ create_chat_history("22222222-2222-2222-2222-222222222222"),
+ );
let result = construct_search_result(input, chat_histories).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()));
+ let chat_ids: Vec<&Uuid> = result.iter().map(|r| &r.extra.id).collect();
+ assert!(chat_ids.contains(&&"11111111-1111-1111-1111-111111111111".parse().unwrap()));
+ assert!(chat_ids.contains(&&"22222222-2222-2222-2222-222222222222".parse().unwrap()));
// Each chat should have one message
for chat in &result {
@@ -168,19 +219,40 @@ fn test_multiple_chats() {
#[test]
fn test_mixed_content_presence() {
let input = vec![
- create_test_response("chat_1", "msg_1", Some(vec!["visible".to_string()])),
- create_test_response("chat_1", "msg_2", None), // No content
- create_test_response("chat_1", "msg_3", Some(vec!["also visible".to_string()])),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
+ Some(vec!["visible".to_string()]),
+ ),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "22222222-2222-2222-2222-222222222222",
+ None,
+ ), // No content
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "33333333-3333-3333-3333-333333333333",
+ Some(vec!["also visible".to_string()]),
+ ),
];
let mut chat_histories = HashMap::new();
- chat_histories.insert("chat_1".to_string(), create_chat_history("chat_1"));
+ chat_histories.insert(
+ "11111111-1111-1111-1111-111111111111".to_string(),
+ create_chat_history("11111111-1111-1111-1111-111111111111"),
+ );
let result = construct_search_result(input, chat_histories).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_id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
+ assert_eq!(
+ result[0].extra.id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
assert_eq!(result[0].extra.chat_search_results.len(), 3); // Only messages with content
let contents: Vec<&Vec<String>> = result[0]
@@ -196,12 +268,23 @@ fn test_mixed_content_presence() {
#[test]
fn test_user_id_taken_from_first_result() {
let input = vec![
- create_test_response("chat_1", "msg_1", Some(vec!["content1".to_string()])),
- create_test_response("chat_1", "msg_2", Some(vec!["content2".to_string()])),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
+ Some(vec!["content1".to_string()]),
+ ),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "22222222-2222-2222-2222-222222222222",
+ Some(vec!["content2".to_string()]),
+ ),
];
let mut chat_histories = HashMap::new();
- chat_histories.insert("chat_1".to_string(), create_chat_history("chat_1"));
+ chat_histories.insert(
+ "11111111-1111-1111-1111-111111111111".to_string(),
+ create_chat_history("11111111-1111-1111-1111-111111111111"),
+ );
let result = construct_search_result(input, chat_histories).unwrap();
@@ -215,8 +298,8 @@ fn test_user_id_taken_from_first_result() {
fn test_chat_history_timestamps() {
// Create a test response
let input = vec![create_test_response(
- "chat_1",
- "msg_1",
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
Some(vec!["hello world".to_string()]),
)];
@@ -225,7 +308,7 @@ fn test_chat_history_timestamps() {
let now = chrono::Utc::now();
let history = ChatHistoryInfo {
- item_id: "chat_1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: Some(now),
@@ -233,7 +316,7 @@ fn test_chat_history_timestamps() {
..Default::default()
};
- chat_histories.insert("chat_1".to_string(), history);
+ chat_histories.insert("11111111-1111-1111-1111-111111111111".to_string(), history);
// Call the function under test
let result = construct_search_result(input, chat_histories).unwrap();
@@ -258,8 +341,8 @@ fn test_chat_history_timestamps() {
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",
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
Some(vec!["hello world".to_string()]),
)];
@@ -291,16 +374,16 @@ fn test_chat_history_deleted() {
// Test 1: Chat that exists but is soft-deleted
let input_deleted = vec![create_test_response(
- "chat_deleted",
- "msg_1",
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
Some(vec!["hello world".to_string()]),
)];
let mut chat_histories = HashMap::new();
chat_histories.insert(
- "chat_deleted".to_string(),
+ "11111111-1111-1111-1111-111111111111".to_string(),
macro_db_client::chat::get::ChatHistoryInfo {
- item_id: "chat_deleted".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: Some(now),
@@ -322,8 +405,8 @@ fn test_chat_history_deleted() {
// Test 2: Chat that doesn't exist in DB (OpenSearch has stale data)
let input_not_found = vec![create_test_response(
- "chat_not_found",
- "msg_2",
+ "11111111-1111-1111-1111-111111111111",
+ "22222222-2222-2222-2222-222222222222",
Some(vec!["stale data".to_string()]),
)];
@@ -340,8 +423,8 @@ fn test_chat_history_deleted() {
fn test_chat_history_null_viewed_at() {
// Create a test response
let input = vec![create_test_response(
- "chat_1",
- "msg_1",
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
Some(vec!["hello world".to_string()]),
)];
@@ -350,7 +433,7 @@ fn test_chat_history_null_viewed_at() {
let now = chrono::Utc::now();
let history = ChatHistoryInfo {
- item_id: "chat_1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: None, // This user has never viewed this chat
@@ -358,7 +441,7 @@ fn test_chat_history_null_viewed_at() {
..Default::default()
};
- chat_histories.insert("chat_1".to_string(), history);
+ chat_histories.insert("11111111-1111-1111-1111-111111111111".to_string(), history);
// Call the function under test
let result = construct_search_result(input, chat_histories).unwrap();
@@ -379,15 +462,41 @@ fn test_chat_history_null_viewed_at() {
#[test]
fn test_sort_stability() {
let input = vec![
- create_test_response("chat_3", "msg_3", Some(vec!["third".to_string()])),
- create_test_response("chat_1", "msg_1", Some(vec!["first".to_string()])),
- create_test_response("chat_5", "msg_5", Some(vec!["fifth".to_string()])),
- create_test_response("chat_2", "msg_2", Some(vec!["second".to_string()])),
- create_test_response("chat_4", "msg_4", Some(vec!["fourth".to_string()])),
+ create_test_response(
+ "33333333-3333-3333-3333-333333333333",
+ "33333333-3333-3333-3333-333333333333",
+ Some(vec!["third".to_string()]),
+ ),
+ create_test_response(
+ "11111111-1111-1111-1111-111111111111",
+ "11111111-1111-1111-1111-111111111111",
+ Some(vec!["first".to_string()]),
+ ),
+ create_test_response(
+ "55555555-5555-5555-5555-555555555555",
+ "55555555-5555-5555-5555-555555555555",
+ Some(vec!["fifth".to_string()]),
+ ),
+ create_test_response(
+ "22222222-2222-2222-2222-222222222222",
+ "22222222-2222-2222-2222-222222222222",
+ Some(vec!["second".to_string()]),
+ ),
+ create_test_response(
+ "44444444-4444-4444-4444-444444444444",
+ "44444444-4444-4444-4444-444444444444",
+ Some(vec!["fourth".to_string()]),
+ ),
];
let mut chat_histories = HashMap::new();
- for chat_id in ["chat_1", "chat_2", "chat_3", "chat_4", "chat_5"] {
+ for chat_id in [
+ "11111111-1111-1111-1111-111111111111",
+ "22222222-2222-2222-2222-222222222222",
+ "33333333-3333-3333-3333-333333333333",
+ "44444444-4444-4444-4444-444444444444",
+ "55555555-5555-5555-5555-555555555555",
+ ] {
chat_histories.insert(chat_id.to_string(), create_chat_history(chat_id));
}
@@ -399,16 +508,24 @@ fn test_sort_stability() {
assert_eq!(result2.len(), 5);
assert_eq!(result3.len(), 5);
- let ids1: Vec<String> = result1.iter().map(|r| r.extra.id.clone()).collect();
- let ids2: Vec<String> = result2.iter().map(|r| r.extra.id.clone()).collect();
- let ids3: Vec<String> = result3.iter().map(|r| r.extra.id.clone()).collect();
+ let ids1: Vec<Uuid> = result1.iter().map(|r| r.extra.id.clone()).collect();
+ let ids2: Vec<Uuid> = result2.iter().map(|r| r.extra.id.clone()).collect();
+ let ids3: Vec<Uuid> = result3.iter().map(|r| r.extra.id.clone()).collect();
assert_eq!(ids1, ids2, "Results should be stable between runs");
assert_eq!(ids2, ids3, "Results should be stable between runs");
assert_eq!(
ids1,
- vec!["chat_3", "chat_1", "chat_5", "chat_2", "chat_4"],
+ vec![
+ "33333333-3333-3333-3333-333333333333"
+ .parse::<Uuid>()
+ .unwrap(),
+ "11111111-1111-1111-1111-111111111111".parse().unwrap(),
+ "55555555-5555-5555-5555-555555555555".parse().unwrap(),
+ "22222222-2222-2222-2222-222222222222".parse().unwrap(),
+ "44444444-4444-4444-4444-444444444444".parse().unwrap()
+ ],
"Results should preserve original search result order"
);
}
diff --git a/rust/cloud-storage/search_service/src/api/search/document.rs b/rust/cloud-storage/search_service/src/api/search/document.rs
index e19a174205..31cd9dfcf7 100644
--- a/rust/cloud-storage/search_service/src/api/search/document.rs
+++ b/rust/cloud-storage/search_service/src/api/search/document.rs
@@ -13,6 +13,7 @@ use models_search::document::{
DocumentSearchResponseItemWithMetadata, DocumentSearchResult,
};
use opensearch_client::search::model::SearchGotoContent;
+use sqlx::types::Uuid;
use std::collections::HashMap;
use crate::api::ApiContext;
@@ -35,7 +36,7 @@ pub(in crate::api::search) async fn enrich_documents(
return Ok(vec![]);
}
// Extract document IDs from results
- let document_ids: Vec<String> = results.iter().map(|r| r.entity_id.clone()).collect();
+ let document_ids: Vec<String> = results.iter().map(|r| r.entity_id.to_string()).collect();
// Fetch document metadata from database
let document_histories =
@@ -107,7 +108,7 @@ pub fn construct_search_result(
>,
) -> anyhow::Result<Vec<DocumentSearchResponseItemWithMetadata>> {
// construct entity hit map of id -> vec<hits> using IndexMap to preserve insertion order
- let entity_id_hit_map: IndexMap<String, Vec<DocumentSearchResult>> = search_results
+ let entity_id_hit_map: IndexMap<Uuid, Vec<DocumentSearchResult>> = search_results
.into_iter()
.map(|hit| {
let result = if let Some(SearchGotoContent::Documents(goto)) = hit.goto {
@@ -137,7 +138,7 @@ pub fn construct_search_result(
let result: Vec<DocumentSearchResponseItemWithMetadata> = entity_id_hit_map
.into_iter()
.filter_map(|(entity_id, hits)| {
- if let Some(info) = document_histories.get(&entity_id) {
+ if let Some(info) = document_histories.get(&entity_id.to_string()) {
let info = info.clone();
let metadata = models_search::document::DocumentMetadata {
created_at: info.created_at.timestamp(),
@@ -149,7 +150,7 @@ pub fn construct_search_result(
Some(DocumentSearchResponseItemWithMetadata {
metadata: Some(metadata),
extra: DocumentSearchResponseItem {
- id: entity_id.clone(),
+ id: entity_id,
name: info.file_name.clone(),
document_id: entity_id,
document_name: info.file_name,
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.rs
index d42279f6e4..4a3a992a24 100644
--- a/rust/cloud-storage/search_service/src/api/search/document/test.rs
+++ b/rust/cloud-storage/search_service/src/api/search/document/test.rs
@@ -13,7 +13,7 @@ fn test_construct_search_result_empty_input() {
#[test]
fn test_construct_search_result_single_document() {
let search_results = vec![opensearch_client::search::model::SearchHit {
- entity_id: "doc1".to_string(),
+ entity_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -33,9 +33,9 @@ fn test_construct_search_result_single_document() {
let mut document_histories = HashMap::new();
let now = chrono::Utc::now();
document_histories.insert(
- "doc1".to_string(),
+ "11111111-1111-1111-1111-111111111111".to_string(),
DocumentHistoryInfo {
- item_id: "doc1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: None,
@@ -51,8 +51,14 @@ fn test_construct_search_result_single_document() {
let result = construct_search_result(search_results, document_histories).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_id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
+ assert_eq!(
+ result[0].extra.id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
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");
@@ -75,7 +81,7 @@ fn test_construct_search_result_single_document() {
fn test_construct_search_result_multiple_nodes_same_document() {
let search_results = vec![
opensearch_client::search::model::SearchHit {
- entity_id: "doc1".to_string(),
+ entity_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -92,7 +98,7 @@ fn test_construct_search_result_multiple_nodes_same_document() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: "doc1".to_string(),
+ entity_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -113,9 +119,9 @@ fn test_construct_search_result_multiple_nodes_same_document() {
let mut document_histories = HashMap::new();
let now = chrono::Utc::now();
document_histories.insert(
- "doc1".to_string(),
+ "11111111-1111-1111-1111-111111111111".to_string(),
DocumentHistoryInfo {
- item_id: "doc1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: None,
@@ -131,8 +137,14 @@ fn test_construct_search_result_multiple_nodes_same_document() {
let result = construct_search_result(search_results, document_histories).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_id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
+ assert_eq!(
+ result[0].extra.id.to_string(),
+ "11111111-1111-1111-1111-111111111111"
+ );
assert_eq!(result[0].extra.name, "Test Document");
assert_eq!(result[0].extra.document_search_results.len(), 2);
@@ -153,7 +165,7 @@ fn create_test_document_response(
content: Option<Vec<String>>,
) -> opensearch_client::search::model::SearchHit {
opensearch_client::search::model::SearchHit {
- entity_id: document_id.to_string(),
+ entity_id: document_id.parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -175,7 +187,7 @@ fn create_test_document_response(
fn test_document_history_timestamps() {
// Create a test response
let input = vec![create_test_document_response(
- "doc_1",
+ "11111111-1111-1111-1111-111111111111",
"node_1",
Some(vec!["hello world".to_string()]),
)];
@@ -185,7 +197,7 @@ fn test_document_history_timestamps() {
let now = chrono::Utc::now();
let history = DocumentHistoryInfo {
- item_id: "doc_1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: Some(now),
@@ -193,7 +205,7 @@ fn test_document_history_timestamps() {
..Default::default()
};
- document_histories.insert("doc_1".to_string(), history);
+ document_histories.insert("11111111-1111-1111-1111-111111111111".to_string(), history);
// Call the function under test
let result = construct_search_result(input, document_histories).unwrap();
@@ -218,7 +230,7 @@ fn test_document_history_timestamps() {
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",
+ "11111111-1111-1111-1111-111111111111",
"node_1",
Some(vec!["hello world".to_string()]),
)];
@@ -228,7 +240,7 @@ fn test_document_history_missing_entry() {
let now = chrono::Utc::now();
let history = DocumentHistoryInfo {
- item_id: "different_doc".to_string(),
+ item_id: "22222222-2222-2222-2222-222222222222".to_string(),
created_at: now,
updated_at: now,
viewed_at: None,
@@ -236,7 +248,7 @@ fn test_document_history_missing_entry() {
..Default::default()
};
- document_histories.insert("different_doc".to_string(), history);
+ document_histories.insert("22222222-2222-2222-2222-222222222222".to_string(), history);
// Call the function under test
let result = construct_search_result(input, document_histories).unwrap();
@@ -249,7 +261,7 @@ fn test_document_history_missing_entry() {
fn test_document_history_null_viewed_at() {
// Create a test response
let input = vec![create_test_document_response(
- "doc_1",
+ "11111111-1111-1111-1111-111111111111",
"node_1",
Some(vec!["hello world".to_string()]),
)];
@@ -259,7 +271,7 @@ fn test_document_history_null_viewed_at() {
let now = chrono::Utc::now();
let history = DocumentHistoryInfo {
- item_id: "doc_1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: None, // This user has never viewed this document
@@ -267,7 +279,7 @@ fn test_document_history_null_viewed_at() {
..Default::default()
};
- document_histories.insert("doc_1".to_string(), history);
+ document_histories.insert("11111111-1111-1111-1111-111111111111".to_string(), history);
// Call the function under test
let result = construct_search_result(input, document_histories).unwrap();
@@ -289,8 +301,16 @@ fn test_document_history_null_viewed_at() {
fn test_document_history_multiple_documents() {
// Create test responses for multiple documents
let input = vec![
- create_test_document_response("doc_1", "node_1", Some(vec!["first document".to_string()])),
- create_test_document_response("doc_2", "node_2", Some(vec!["second document".to_string()])),
+ create_test_document_response(
+ "11111111-1111-1111-1111-111111111111",
+ "node_1",
+ Some(vec!["first document".to_string()]),
+ ),
+ create_test_document_response(
+ "22222222-2222-2222-2222-222222222222",
+ "node_2",
+ Some(vec!["second document".to_string()]),
+ ),
];
// Create mock document histories
@@ -299,7 +319,7 @@ fn test_document_history_multiple_documents() {
let earlier = now - chrono::Duration::hours(1);
let history1 = DocumentHistoryInfo {
- item_id: "doc_1".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: Some(now),
@@ -308,7 +328,7 @@ fn test_document_history_multiple_documents() {
};
let history2 = DocumentHistoryInfo {
- item_id: "doc_2".to_string(),
+ item_id: "22222222-2222-2222-2222-222222222222".to_string(),
created_at: earlier,
updated_at: earlier,
viewed_at: None,
@@ -316,8 +336,8 @@ fn test_document_history_multiple_documents() {
..Default::default()
};
- document_histories.insert("doc_1".to_string(), history1);
- document_histories.insert("doc_2".to_string(), history2);
+ document_histories.insert("11111111-1111-1111-1111-111111111111".to_string(), history1);
+ document_histories.insert("22222222-2222-2222-2222-222222222222".to_string(), history2);
// Call the function under test
let result = construct_search_result(input, document_histories).unwrap();
@@ -328,11 +348,11 @@ fn test_document_history_multiple_documents() {
// Find each document in results (order might not be preserved)
let doc1_result = result
.iter()
- .find(|r| r.extra.document_id == "doc_1")
+ .find(|r| r.extra.document_id.to_string() == "11111111-1111-1111-1111-111111111111")
.unwrap();
let doc2_result = result
.iter()
- .find(|r| r.extra.document_id == "doc_2")
+ .find(|r| r.extra.document_id.to_string() == "22222222-2222-2222-2222-222222222222")
.unwrap();
let doc1_metadata = doc1_result.metadata.as_ref().unwrap();
@@ -351,12 +371,12 @@ fn test_document_history_partial_missing_entries() {
// Create test responses for multiple documents
let input = vec![
create_test_document_response(
- "doc_exists",
+ "11111111-1111-1111-1111-111111111111",
"node_1",
Some(vec!["existing document".to_string()]),
),
create_test_document_response(
- "doc_missing",
+ "22222222-2222-2222-2222-222222222222",
"node_2",
Some(vec!["missing document".to_string()]),
),
@@ -367,7 +387,7 @@ fn test_document_history_partial_missing_entries() {
let now = chrono::Utc::now();
let history = DocumentHistoryInfo {
- item_id: "doc_exists".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: Some(now),
@@ -375,7 +395,7 @@ fn test_document_history_partial_missing_entries() {
..Default::default()
};
- document_histories.insert("doc_exists".to_string(), history);
+ document_histories.insert("11111111-1111-1111-1111-111111111111".to_string(), history);
// Call the function under test
let result = construct_search_result(input, document_histories).unwrap();
@@ -386,7 +406,7 @@ fn test_document_history_partial_missing_entries() {
// The existing document should have real timestamps in metadata
let existing_doc = result
.iter()
- .find(|r| r.extra.document_id == "doc_exists")
+ .find(|r| r.extra.document_id.to_string() == "11111111-1111-1111-1111-111111111111")
.unwrap();
assert!(existing_doc.metadata.is_some());
let metadata = existing_doc.metadata.as_ref().unwrap();
@@ -401,16 +421,16 @@ fn test_document_history_deleted() {
// Test 1: Document that exists but is soft-deleted
let input_deleted = vec![create_test_document_response(
- "doc_deleted",
+ "11111111-1111-1111-1111-111111111111",
"node_1",
Some(vec!["hello world".to_string()]),
)];
let mut document_histories = HashMap::new();
document_histories.insert(
- "doc_deleted".to_string(),
+ "11111111-1111-1111-1111-111111111111".to_string(),
macro_db_client::document::get_document_history::DocumentHistoryInfo {
- item_id: "doc_deleted".to_string(),
+ item_id: "11111111-1111-1111-1111-111111111111".to_string(),
created_at: now,
updated_at: now,
viewed_at: Some(now),
@@ -434,7 +454,7 @@ fn test_document_history_deleted() {
// Test 2: Document that doesn't exist in DB (OpenSearch has stale data)
let input_not_found = vec![create_test_document_response(
- "doc_not_found",
+ "22222222-2222-2222-2222-222222222222",
"node_2",
Some(vec!["stale data".to_string()]),
)];
@@ -452,7 +472,7 @@ fn test_document_history_deleted() {
fn test_sort_stability() {
let input = vec![
opensearch_client::search::model::SearchHit {
- entity_id: "doc_3".to_string(),
+ entity_id: "33333333-3333-3333-3333-333333333333".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -469,7 +489,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: "doc_1".to_string(),
+ entity_id: "11111111-1111-1111-1111-111111111111".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -486,7 +506,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: "doc_5".to_string(),
+ entity_id: "55555555-5555-5555-5555-555555555555".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -503,7 +523,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: "doc_2".to_string(),
+ entity_id: "22222222-2222-2222-2222-222222222222".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -520,7 +540,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: "doc_4".to_string(),
+ entity_id: "44444444-4444-4444-4444-444444444444".parse().unwrap(),
entity_type: SearchEntityType::Documents,
goto: Some(
opensearch_client::search::model::SearchGotoContent::Documents(
@@ -540,7 +560,13 @@ fn test_sort_stability() {
let mut document_histories = HashMap::new();
let now = chrono::Utc::now();
- for doc_id in ["doc_1", "doc_2", "doc_3", "doc_4", "doc_5"] {
+ for doc_id in [
+ "11111111-1111-1111-1111-111111111111",
+ "22222222-2222-2222-2222-222222222222",
+ "33333333-3333-3333-3333-333333333333",
+ "44444444-4444-4444-4444-444444444444",
+ "55555555-5555-5555-5555-555555555555",
+ ] {
document_histories.insert(
doc_id.to_string(),
DocumentHistoryInfo {
@@ -566,16 +592,22 @@ fn test_sort_stability() {
assert_eq!(result2.len(), 5);
assert_eq!(result3.len(), 5);
- let ids1: Vec<String> = result1.iter().map(|r| r.extra.id.clone()).collect();
- let ids2: Vec<String> = result2.iter().map(|r| r.extra.id.clone()).collect();
- let ids3: Vec<String> = result3.iter().map(|r| r.extra.id.clone()).collect();
+ let ids1: Vec<String> = result1.iter().map(|r| r.extra.id.to_string()).collect();
+ let ids2: Vec<String> = result2.iter().map(|r| r.extra.id.to_string()).collect();
+ let ids3: Vec<String> = result3.iter().map(|r| r.extra.id.to_string()).collect();
assert_eq!(ids1, ids2, "Results should be stable between runs");
assert_eq!(ids2, ids3, "Results should be stable between runs");
assert_eq!(
ids1,
- vec!["doc_3", "doc_1", "doc_5", "doc_2", "doc_4"],
+ vec![
+ "33333333-3333-3333-3333-333333333333",
+ "11111111-1111-1111-1111-111111111111",
+ "55555555-5555-5555-5555-555555555555",
+ "22222222-2222-2222-2222-222222222222",
+ "44444444-4444-4444-4444-444444444444"
+ ],
"Results should preserve original search result order"
);
}
diff --git a/rust/cloud-storage/search_service/src/api/search/email.rs b/rust/cloud-storage/search_service/src/api/search/email.rs
index 0b1940f548..27d44f0a4c 100644
--- a/rust/cloud-storage/search_service/src/api/search/email.rs
+++ b/rust/cloud-storage/search_service/src/api/search/email.rs
@@ -39,18 +39,7 @@ pub(in crate::api::search) async fn enrich_emails(
}
// Extract thread IDs from results
- let thread_ids: Vec<Uuid> = results
- .iter()
- .filter_map(|r| {
- match Uuid::parse_str(&r.entity_id) {
- Ok(uuid) => Some(uuid),
- Err(e) => {
- tracing::warn!(error=?e, thread_id=?r.entity_id, "Failed to parse thread ID as UUID");
- None
- }
- }
- })
- .collect();
+ let thread_ids: Vec<Uuid> = results.iter().map(|r| r.entity_id).collect();
// Fetch email thread metadata from email service
let thread_histories = ctx
@@ -174,7 +163,7 @@ pub fn construct_search_result(
score: hit.score,
})
} else {
- let thread_info = thread_histories.get(&hit.entity_id.parse().unwrap());
+ let thread_info = thread_histories.get(&hit.entity_id);
if let Some(thread_info) = thread_info {
let sender = thread_info.sender.clone();
let pretty_sender = thread_info.pretty_sender.clone();
@@ -197,7 +186,7 @@ pub fn construct_search_result(
}
};
- result.map(|a| (hit.entity_id.parse().unwrap(), a))
+ result.map(|a| (hit.entity_id, a))
})
.fold(IndexMap::new(), |mut map, (entity_id, result)| {
map.entry(entity_id).or_insert_with(Vec::new).push(result);
@@ -216,8 +205,8 @@ pub fn construct_search_result(
viewed_at: info.viewed_at.map(|a| a.timestamp()),
snippet: info.snippet,
extra: EmailSearchResponseItem {
- id: entity_id.to_string(),
- thread_id: entity_id.to_string(),
+ id: entity_id,
+ thread_id: entity_id,
owner_id: info.user_id.clone(),
user_id: info.user_id,
name: info.subject.clone(),
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.rs
index 665bfe83ee..b359056f52 100644
--- a/rust/cloud-storage/search_service/src/api/search/email/test.rs
+++ b/rust/cloud-storage/search_service/src/api/search/email/test.rs
@@ -28,9 +28,9 @@ fn test_construct_search_result_empty_input() {
#[test]
fn test_construct_search_result_single_thread() {
- let thread_uuid = "550e8400-e29b-41d4-a716-446655440000";
+ let thread_uuid: Uuid = "550e8400-e29b-41d4-a716-446655440000".parse().unwrap();
let search_results = vec![opensearch_client::search::model::SearchHit {
- entity_id: thread_uuid.to_string(),
+ entity_id: thread_uuid,
entity_type: SearchEntityType::Emails,
goto: Some(opensearch_client::search::model::SearchGotoContent::Emails(
opensearch_client::search::model::SearchGotoEmail {
@@ -51,10 +51,7 @@ fn test_construct_search_result_single_thread() {
}];
let mut thread_histories = HashMap::new();
- thread_histories.insert(
- Uuid::parse_str(thread_uuid).unwrap(),
- create_email_history(thread_uuid),
- );
+ thread_histories.insert(thread_uuid, create_email_history(&thread_uuid.to_string()));
let result = construct_search_result(search_results, thread_histories, HashMap::new()).unwrap();
@@ -75,17 +72,20 @@ fn test_construct_search_result_single_thread() {
#[test]
fn test_sort_stability() {
- let thread_ids = [
+ let thread_ids: Vec<Uuid> = [
"550e8400-e29b-41d4-a716-446655440003",
"550e8400-e29b-41d4-a716-446655440001",
"550e8400-e29b-41d4-a716-446655440005",
"550e8400-e29b-41d4-a716-446655440002",
"550e8400-e29b-41d4-a716-446655440004",
- ];
+ ]
+ .into_iter()
+ .map(|a| a.parse().unwrap())
+ .collect();
let input = vec![
opensearch_client::search::model::SearchHit {
- entity_id: thread_ids[0].to_string(),
+ entity_id: thread_ids[0],
entity_type: SearchEntityType::Emails,
goto: Some(opensearch_client::search::model::SearchGotoContent::Emails(
opensearch_client::search::model::SearchGotoEmail {
@@ -105,7 +105,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: thread_ids[1].to_string(),
+ entity_id: thread_ids[1],
entity_type: SearchEntityType::Emails,
goto: Some(opensearch_client::search::model::SearchGotoContent::Emails(
opensearch_client::search::model::SearchGotoEmail {
@@ -125,7 +125,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: thread_ids[2].to_string(),
+ entity_id: thread_ids[2],
entity_type: SearchEntityType::Emails,
goto: Some(opensearch_client::search::model::SearchGotoContent::Emails(
opensearch_client::search::model::SearchGotoEmail {
@@ -145,7 +145,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: thread_ids[3].to_string(),
+ entity_id: thread_ids[3],
entity_type: SearchEntityType::Emails,
goto: Some(opensearch_client::search::model::SearchGotoContent::Emails(
opensearch_client::search::model::SearchGotoEmail {
@@ -165,7 +165,7 @@ fn test_sort_stability() {
},
},
opensearch_client::search::model::SearchHit {
- entity_id: thread_ids[4].to_string(),
+ entity_id: thread_ids[4],
entity_type: SearchEntityType::Emails,
goto: Some(opensearch_client::search::model::SearchGotoContent::Emails(
opensearch_client::search::model::SearchGotoEmail {
@@ -189,8 +189,8 @@ fn test_sort_stability() {
let mut thread_histories = HashMap::new();
for thread_id in &thread_ids {
thread_histories.insert(
- Uuid::parse_str(thread_id).unwrap(),
- create_email_history(thread_id),
+ thread_id.clone(),
+ create_email_history(&thread_id.to_string()),
);
}
@@ -205,9 +205,9 @@ fn test_sort_stability() {
assert_eq!(result2.len(), 5);
assert_eq!(result3.len(), 5);
- let ids1: Vec<String> = result1.iter().map(|r| r.extra.id.clone()).collect();
- let ids2: Vec<String> = result2.iter().map(|r| r.extra.id.clone()).collect();
- let ids3: Vec<String> = result3.iter().map(|r| r.extra.id.clone()).collect();
+ let ids1: Vec<Uuid> = result1.iter().map(|r| r.extra.id.clone()).collect();
+ let ids2: Vec<Uuid> = result2.iter().map(|r| r.extra.id.clone()).collect();
+ let ids3: Vec<Uuid> = result3.iter().map(|r| r.extra.id.clone()).collect();
assert_eq!(ids1, ids2, "Results should be stable between runs");
assert_eq!(ids2, ids3, "Results should be stable between runs");
diff --git a/rust/cloud-storage/search_service/src/api/search/project.rs b/rust/cloud-storage/search_service/src/api/search/project.rs
index f02c7fc7d4..7eba96e7ac 100644
--- a/rust/cloud-storage/search_service/src/api/search/project.rs
+++ b/rust/cloud-storage/search_service/src/api/search/project.rs
@@ -11,6 +11,7 @@ use models_search::project::{
ProjectSearchRequest, ProjectSearchResponse, ProjectSearchResponseItem,
ProjectSearchResponseItemWithMetadata, ProjectSearchResult,
};
+use sqlx::types::Uuid;
use std::collections::HashMap;
use crate::api::ApiContext;
@@ -33,7 +34,7 @@ pub(in crate::api::search) async fn enrich_projects(
return Ok(vec![]);
}
// Extract project IDs from results
- let project_ids: Vec<String> = results.iter().map(|r| r.entity_id.clone()).collect();
+ let project_ids: Vec<String> = results.iter().map(|r| r.entity_id.to_string()).collect();
// Fetch project metadata from database
let project_histories =
@@ -107,7 +108,7 @@ pub fn construct_search_result(
>,
) -> anyhow::Result<Vec<ProjectSearchResponseItemWithMetadata>> {
// construct entity hit map of id -> vec<hits> using IndexMap to preserve insertion order
- let entity_id_hit_map: IndexMap<String, Vec<ProjectSearchResult>> = search_results
+ let entity_id_hit_map: IndexMap<Uuid, Vec<ProjectSearchResult>> = search_results
.into_iter()
.map(|hit| {
let result = ProjectSearchResult {
@@ -126,7 +127,7 @@ pub fn construct_search_result(
let result: Vec<ProjectSearchResponseItemWithMetadata> = entity_id_hit_map
.into_iter()
.filter_map(|(entity_id, hits)| {
- if let Some(info) = project_histories.get(&entity_id) {
+ if let Some(info) = project_histories.get(&entity_id.to_string()) {
let info = info.clone();
let metadata = models_search::project::ProjectMetadata {
created_at: info.created_at.timestamp(),
@@ -138,7 +139,7 @@ pub fn construct_search_result(
Some(ProjectSearchResponseItemWithMetadata {
metadata: Some(metadata),
extra: ProjectSearchResponseItem {
- id: entity_id.clone(),
+ id: entity_id,
owner_id: info.user_id.clone(),
name: info.name,
project_search_results: hits,