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
chore(search): drop retired Postgres document name search (#4246)
gbirman31e53acd9c72
diff --git a/rust/cloud-storage/.sqlx/query-4e188b522b313eaf51caac616fe177abfe97c6ce6291ba8f83148ba02eaead73.json b/rust/cloud-storage/.sqlx/query-4e188b522b313eaf51caac616fe177abfe97c6ce6291ba8f83148ba02eaead73.jsondeleted file mode 100644index 6908ba7727..0000000000--- a/rust/cloud-storage/.sqlx/query-4e188b522b313eaf51caac616fe177abfe97c6ce6291ba8f83148ba02eaead73.json+++ /dev/null@@ -1,45 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n d.id as entity_id,\n d.name,\n regexp_replace(\n d.name,\n $6,\n '<macro_em>\\1</macro_em>',\n 'gi'\n ) as name_highlighted,\n d.\"updatedAt\" as updated_at\n FROM \"Document\" d\n WHERE d.id = ANY($1)\n AND d.\"deletedAt\" IS NULL\n AND d.name ILIKE $2\n AND (\n $4::timestamptz IS NULL\n OR (d.\"updatedAt\", d.id) < ($4, $5)\n )\n ORDER BY d.\"updatedAt\" DESC, d.id DESC\n LIMIT $3\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "entity_id",- "type_info": "Text"- },- {- "ordinal": 1,- "name": "name",- "type_info": "Text"- },- {- "ordinal": 2,- "name": "name_highlighted",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "updated_at",- "type_info": "Timestamp"- }- ],- "parameters": {- "Left": [- "TextArray",- "Text",- "Int8",- "Timestamptz",- "Text",- "Text"- ]- },- "nullable": [- false,- false,- null,- false- ]- },- "hash": "4e188b522b313eaf51caac616fe177abfe97c6ce6291ba8f83148ba02eaead73"-}diff --git a/rust/cloud-storage/.sqlx/query-a321d44c7093eba7f5af8adf30827efead8bb987ad26e89f2e12f875ff38e0be.json b/rust/cloud-storage/.sqlx/query-a321d44c7093eba7f5af8adf30827efead8bb987ad26e89f2e12f875ff38e0be.jsondeleted file mode 100644index 9642d18561..0000000000--- a/rust/cloud-storage/.sqlx/query-a321d44c7093eba7f5af8adf30827efead8bb987ad26e89f2e12f875ff38e0be.json+++ /dev/null@@ -1,46 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n d.id as entity_id,\n d.name,\n regexp_replace(\n d.name,\n $7,\n '<macro_em>\\1</macro_em>',\n 'gi'\n ) as name_highlighted,\n d.\"updatedAt\" as updated_at\n FROM \"Document\" d\n WHERE (d.owner = $1 OR d.id = ANY($2))\n AND d.\"deletedAt\" IS NULL\n AND d.name ILIKE $3\n AND (\n $5::timestamptz IS NULL\n OR (d.\"updatedAt\", d.id) < ($5, $6)\n )\n ORDER BY d.\"updatedAt\" DESC, d.id DESC\n LIMIT $4\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "entity_id",- "type_info": "Text"- },- {- "ordinal": 1,- "name": "name",- "type_info": "Text"- },- {- "ordinal": 2,- "name": "name_highlighted",- "type_info": "Text"- },- {- "ordinal": 3,- "name": "updated_at",- "type_info": "Timestamp"- }- ],- "parameters": {- "Left": [- "Text",- "TextArray",- "Text",- "Int8",- "Timestamptz",- "Text",- "Text"- ]- },- "nullable": [- false,- false,- null,- false- ]- },- "hash": "a321d44c7093eba7f5af8adf30827efead8bb987ad26e89f2e12f875ff38e0be"-}diff --git a/rust/cloud-storage/macro_db_client/migrations/20260622181002_drop_idx_document_name_trgm.sql b/rust/cloud-storage/macro_db_client/migrations/20260622181002_drop_idx_document_name_trgm.sqlnew file mode 100644index 0000000000..0b9603cbd1--- /dev/null+++ b/rust/cloud-storage/macro_db_client/migrations/20260622181002_drop_idx_document_name_trgm.sql@@ -0,0 +1,5 @@+-- no-transaction+-- Document name search moved to OpenSearch, so the trigram index that backed+-- the Postgres `name ILIKE '%term%'` path is no longer used. The pg_trgm+-- extension stays — other indexes still rely on it.+DROP INDEX CONCURRENTLY IF EXISTS idx_document_name_trgm;diff --git a/rust/cloud-storage/name_search/fixtures/document.sql b/rust/cloud-storage/name_search/fixtures/document.sqldeleted file mode 100644index 3ccf0be5fe..0000000000--- a/rust/cloud-storage/name_search/fixtures/document.sql+++ /dev/null@@ -1,43 +0,0 @@--- Test macro_users-INSERT INTO "macro_user" (id, username, email, stripe_customer_id)-VALUES- ('a1111111-1111-1111-1111-111111111111', '[email protected]', '[email protected]', 'stripe_user1'),- ('a2222222-2222-2222-2222-222222222222', '[email protected]', '[email protected]', 'stripe_user2'),- ('a3333333-3333-3333-3333-333333333333', '[email protected]', '[email protected]', 'stripe_user3');---- Test users-INSERT INTO "User" (id, email, name, macro_user_id)-VALUES- ('macro|[email protected]', '[email protected]', 'Test User 1', 'a1111111-1111-1111-1111-111111111111'),- ('macro|[email protected]', '[email protected]', 'Test User 2', 'a2222222-2222-2222-2222-222222222222'),- ('macro|[email protected]', '[email protected]', 'Test User 3', 'a3333333-3333-3333-3333-333333333333');---- Test documents for user1 (owner)-INSERT INTO "Document" (id, name, owner, "fileType", "createdAt", "updatedAt", uploaded)-VALUES- -- Documents matching "report"- ('11111111-1111-1111-1111-111111111111', 'Quarterly Report 2024', 'macro|[email protected]', 'pdf', '2024-01-01 10:00:00', '2024-12-01 10:00:00', true),- ('22222222-2222-2222-2222-222222222222', 'Sales Report December', 'macro|[email protected]', 'docx', '2024-02-01 10:00:00', '2024-12-02 10:00:00', true),- ('33333333-3333-3333-3333-333333333333', 'Financial Report Q3', 'macro|[email protected]', 'xlsx', '2024-03-01 10:00:00', '2024-12-03 10:00:00', true),-- -- Documents matching "meeting"- ('44444444-4444-4444-4444-444444444444', 'Team Meeting Notes', 'macro|[email protected]', 'txt', '2024-04-01 10:00:00', '2024-12-04 10:00:00', true),- ('55555555-5555-5555-5555-555555555555', 'Client Meeting Agenda', 'macro|[email protected]', 'pdf', '2024-05-01 10:00:00', '2024-12-05 10:00:00', true),-- -- Documents not matching common search terms- ('66666666-6666-6666-6666-666666666666', 'Budget Analysis', 'macro|[email protected]', 'xlsx', '2024-06-01 10:00:00', '2024-12-06 10:00:00', true),- ('77777777-7777-7777-7777-777777777777', 'Project Proposal', 'macro|[email protected]', 'docx', '2024-07-01 10:00:00', '2024-12-07 10:00:00', true),-- -- Test case sensitivity (should match "REPORT" search)- ('88888888-8888-8888-8888-888888888888', 'ANNUAL REPORT 2024', 'macro|[email protected]', 'pdf', '2024-08-01 10:00:00', '2024-12-08 10:00:00', true);---- Test documents for user2 (not accessible to user1 unless shared)-INSERT INTO "Document" (id, name, owner, "fileType", "createdAt", "updatedAt", uploaded)-VALUES- ('99999999-9999-9999-9999-999999999999', 'User2 Report Private', 'macro|[email protected]', 'pdf', '2024-09-01 10:00:00', '2024-12-09 10:00:00', true),- ('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'User2 Meeting Notes', 'macro|[email protected]', 'txt', '2024-10-01 10:00:00', '2024-12-10 10:00:00', true);---- Test documents for user3-INSERT INTO "Document" (id, name, owner, "fileType", "createdAt", "updatedAt", uploaded)-VALUES- ('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', 'User3 Report Shared', 'macro|[email protected]', 'pdf', '2024-11-01 10:00:00', '2024-12-11 10:00:00', true);diff --git a/rust/cloud-storage/name_search/src/document.rs b/rust/cloud-storage/name_search/src/document.rsdeleted file mode 100644index 878a5930f3..0000000000--- a/rust/cloud-storage/name_search/src/document.rs+++ /dev/null@@ -1,210 +0,0 @@-//! This module contains logic for searching documents by name--#[cfg(not(test))]-use cached::proc_macro::cached;-use chrono::{DateTime, Utc};-use macro_user_id::{lowercased::Lowercase, user_id::MacroUserId};-use models_search_cursor::{SearchCursorOption, SearchMethodCursor};-use sqlx::{Pool, Postgres};-use uuid::Uuid;--use crate::{NameSearchError, NameSearchResult, PaginatedResult, SearchEntityType, escape_regex};--/// Searches documents by IDs only-async fn ids_search(- db: &Pool<Postgres>,- document_ids: &[Uuid],- search_pattern: String,- highlight_pattern: String,- limit: u32,- cursor: Option<SearchMethodCursor>,-) -> Result<PaginatedResult<NameSearchResult>, NameSearchError> {- if document_ids.is_empty() {- return Err(NameSearchError::EmptyIdsWithIdsOnly);- }-- let (cursor_updated_at, cursor_entity_id) = cursor- .as_ref()- .and_then(|c| c.as_updated_at())- .map(|(id, ts)| (Some(ts), Some(id.to_string())))- .unwrap_or((None, None));-- // Fetch limit + 1 to determine if there are more results- let fetch_limit = limit as i64 + 1;-- let rows = sqlx::query!(- r#"- SELECT- d.id as entity_id,- d.name,- regexp_replace(- d.name,- $6,- '<macro_em>\1</macro_em>',- 'gi'- ) as name_highlighted,- d."updatedAt" as updated_at- FROM "Document" d- WHERE d.id = ANY($1)- AND d."deletedAt" IS NULL- AND d.name ILIKE $2- AND (- $4::timestamptz IS NULL- OR (d."updatedAt", d.id) < ($4, $5)- )- ORDER BY d."updatedAt" DESC, d.id DESC- LIMIT $3- "#,- &document_ids- .iter()- .map(|d| d.to_string())- .collect::<Vec<String>>(),- search_pattern,- fetch_limit,- cursor_updated_at,- cursor_entity_id,- highlight_pattern,- )- .fetch_all(db)- .await- .map_err(NameSearchError::DatabaseError)?;-- let results: Vec<NameSearchResult> = rows- .into_iter()- .map(|row| NameSearchResult {- entity_id: row.entity_id.parse().unwrap(),- entity_type: SearchEntityType::Documents,- name: row.name_highlighted.unwrap_or(row.name),- updated_at: DateTime::<Utc>::from_naive_utc_and_offset(row.updated_at, Utc),- })- .collect();-- Ok(SearchCursorOption::paginate(results, limit as usize))-}--/// Searches documents by owner or IDs-async fn owner_search<'a>(- db: &Pool<Postgres>,- macro_user_id: &MacroUserId<Lowercase<'a>>,- document_ids: &[Uuid],- search_pattern: String,- highlight_pattern: String,- limit: u32,- cursor: Option<SearchMethodCursor>,-) -> Result<PaginatedResult<NameSearchResult>, NameSearchError> {- let (cursor_updated_at, cursor_entity_id) = cursor- .as_ref()- .and_then(|c| c.as_updated_at())- .map(|(id, ts)| (Some(ts), Some(id.to_string())))- .unwrap_or((None, None));-- // Fetch limit + 1 to determine if there are more results- let fetch_limit = limit as i64 + 1;-- let rows = sqlx::query!(- r#"- SELECT- d.id as entity_id,- d.name,- regexp_replace(- d.name,- $7,- '<macro_em>\1</macro_em>',- 'gi'- ) as name_highlighted,- d."updatedAt" as updated_at- FROM "Document" d- WHERE (d.owner = $1 OR d.id = ANY($2))- AND d."deletedAt" IS NULL- AND d.name ILIKE $3- AND (- $5::timestamptz IS NULL- OR (d."updatedAt", d.id) < ($5, $6)- )- ORDER BY d."updatedAt" DESC, d.id DESC- LIMIT $4- "#,- macro_user_id.as_ref(),- &document_ids- .iter()- .map(|d| d.to_string())- .collect::<Vec<String>>(),- search_pattern,- fetch_limit,- cursor_updated_at,- cursor_entity_id,- highlight_pattern,- )- .fetch_all(db)- .await- .map_err(NameSearchError::DatabaseError)?;-- let results: Vec<NameSearchResult> = rows- .into_iter()- .map(|row| NameSearchResult {- entity_id: row.entity_id.parse().unwrap(),- entity_type: SearchEntityType::Documents,- name: row.name_highlighted.unwrap_or(row.name),- updated_at: DateTime::<Utc>::from_naive_utc_and_offset(row.updated_at, Utc),- })- .collect();-- Ok(SearchCursorOption::paginate(results, limit as usize))-}--/// Searches over the users documents by name-#[tracing::instrument(skip(db), err)]-#[cfg_attr(- not(test),- cached(- time = 30,- result = true,- key = "String",- convert = r#"{ format!("{}-{:?}-{}-{}-{}-{}", macro_user_id.as_ref(), document_ids, term, ids_only, limit, cursor.as_ref().and_then(|c| c.as_updated_at()).map(|(id, ts)| format!("{}-{}", id, ts)).unwrap_or_default()) }"#- )-)]-pub async fn search_document_names<'a>(- db: &Pool<Postgres>,- macro_user_id: &MacroUserId<Lowercase<'a>>,- document_ids: &[Uuid],- term: String,- ids_only: bool,- limit: u32,- cursor: Option<SearchMethodCursor>,-) -> Result<PaginatedResult<NameSearchResult>, NameSearchError> {- if term.is_empty() {- return Err(NameSearchError::EmptySearchTerm);- }- if cursor.as_ref().is_some_and(|c| c.as_updated_at().is_none()) {- return Err(NameSearchError::IncompatibleCursor);- }-- let search_pattern = format!("%{term}%");- let highlight_pattern = format!("({})", escape_regex(&term));-- if ids_only {- ids_search(- db,- document_ids,- search_pattern,- highlight_pattern,- limit,- cursor,- )- .await- } else {- owner_search(- db,- macro_user_id,- document_ids,- search_pattern,- highlight_pattern,- limit,- cursor,- )- .await- }-}--#[cfg(test)]-mod test;diff --git a/rust/cloud-storage/name_search/src/document/test.rs b/rust/cloud-storage/name_search/src/document/test.rsdeleted file mode 100644index 3c5dd35573..0000000000--- a/rust/cloud-storage/name_search/src/document/test.rs+++ /dev/null@@ -1,428 +0,0 @@-//! Tests for document module--use macro_db_migrator::MACRO_DB_MIGRATIONS;-use models_search_cursor::{SearchCursorOption, SearchMethodCursor};-use sqlx::{Pool, Postgres};-use uuid::Uuid;--use super::*;--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_empty_term(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- let result = search_document_names(&pool, &user_id, &[], "".to_string(), false, 10, None).await;-- assert!(result.is_err());- assert!(matches!(- result.unwrap_err(),- NameSearchError::EmptySearchTerm- ));-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_ids_only_with_empty_ids(- pool: Pool<Postgres>,-) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- let result =- search_document_names(&pool, &user_id, &[], "report".to_string(), true, 10, None).await;-- assert!(result.is_err());- assert!(matches!(- result.unwrap_err(),- NameSearchError::EmptyIdsWithIdsOnly- ));-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_ids_only_mode(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search for "report" within specific document IDs- let doc_ids = vec![- Uuid::parse_str("11111111-1111-1111-1111-111111111111")?,- Uuid::parse_str("22222222-2222-2222-2222-222222222222")?,- Uuid::parse_str("66666666-6666-6666-6666-666666666666")?, // Budget Analysis - won't match- ];-- let response = search_document_names(- &pool,- &user_id,- &doc_ids,- "report".to_string(),- true,- 10,- None,- )- .await?;-- // Should only return the 2 documents that match "report" from the provided IDs- assert_eq!(response.items.len(), 2);-- // Verify results contain expected documents (ordered by updatedAt DESC)- assert_eq!(- response.items[0].entity_id.to_string(),- "22222222-2222-2222-2222-222222222222"- );- assert_eq!(response.items[0].entity_type, SearchEntityType::Documents);- assert_eq!(- response.items[0].name,- "Sales <macro_em>Report</macro_em> December"- );-- assert_eq!(- response.items[1].entity_id.to_string(),- "11111111-1111-1111-1111-111111111111"- );- assert_eq!(- response.items[1].name,- "Quarterly <macro_em>Report</macro_em> 2024"- );-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_normal_mode_owned_documents(- pool: Pool<Postgres>,-) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search for "report" across all user1's owned documents- let response =- search_document_names(&pool, &user_id, &[], "report".to_string(), false, 10, None).await?;-- // Should return 4 documents matching "report" (3 lowercase + 1 uppercase)- assert_eq!(response.items.len(), 4);-- // Verify ordering by updatedAt DESC- assert_eq!(- response.items[0].entity_id.to_string(),- "88888888-8888-8888-8888-888888888888"- );- assert_eq!(- response.items[0].name,- "ANNUAL <macro_em>REPORT</macro_em> 2024"- );-- assert_eq!(- response.items[1].entity_id.to_string(),- "33333333-3333-3333-3333-333333333333"- );- assert_eq!(- response.items[1].name,- "Financial <macro_em>Report</macro_em> Q3"- );-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_case_insensitive(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search with uppercase term should match both lowercase and uppercase names- let response =- search_document_names(&pool, &user_id, &[], "REPORT".to_string(), false, 10, None).await?;-- assert_eq!(response.items.len(), 4);-- // Search with lowercase term should also match both- let response =- search_document_names(&pool, &user_id, &[], "report".to_string(), false, 10, None).await?;-- assert_eq!(response.items.len(), 4);-- // Search with mixed case- let response =- search_document_names(&pool, &user_id, &[], "RePoRt".to_string(), false, 10, None).await?;-- assert_eq!(response.items.len(), 4);-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_with_shared_documents(- pool: Pool<Postgres>,-) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Include a document from user3 (shared via document_ids parameter)- let shared_doc_ids = vec![Uuid::parse_str("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")?];-- let response = search_document_names(- &pool,- &user_id,- &shared_doc_ids,- "report".to_string(),- false,- 10,- None,- )- .await?;-- // Should return user1's 4 "report" documents + user3's 1 "report" document- assert_eq!(response.items.len(), 5);-- // Verify user3's document is included- let user3_doc = response.items.iter().find(|r| {- r.entity_id- .to_string()- .eq("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb")- });- assert!(user3_doc.is_some());- assert_eq!(- user3_doc.unwrap().name,- "User3 <macro_em>Report</macro_em> Shared"- );-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_pagination_limit(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search with limit of 2- let response =- search_document_names(&pool, &user_id, &[], "report".to_string(), false, 2, None).await?;-- assert_eq!(response.items.len(), 2);-- // Should get the 2 most recently updated documents with "report"- assert_eq!(- response.items[0].entity_id.to_string(),- "88888888-8888-8888-8888-888888888888"- );- assert_eq!(- response.items[1].entity_id.to_string(),- "33333333-3333-3333-3333-333333333333"- );-- // Should have a next_cursor since there are more results- assert!(response.cursor.has_more());-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_pagination_cursor(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // First page with limit of 2- let first_response =- search_document_names(&pool, &user_id, &[], "report".to_string(), false, 2, None).await?;-- assert_eq!(first_response.items.len(), 2);- assert!(first_response.cursor.has_more());-- // Extract cursor for second page- let cursor = match first_response.cursor {- SearchCursorOption::NotDone(c) => c,- SearchCursorOption::Done => panic!("Expected more results"),- };-- // Second page using cursor- let second_response =- search_document_names(&pool, &user_id, &[], "report".to_string(), false, 2, cursor).await?;-- assert_eq!(second_response.items.len(), 2);-- // Should get the next 2 documents (skipping the first 2)- assert_eq!(- second_response.items[0].entity_id.to_string(),- "22222222-2222-2222-2222-222222222222"- );- assert_eq!(- second_response.items[1].entity_id.to_string(),- "11111111-1111-1111-1111-111111111111"- );-- // Should NOT have next_cursor since we've reached the end (fetched limit+1, got only 2)- assert!(second_response.cursor.is_done());-- // Verify no overlap between pages- let first_ids: Vec<String> = first_response- .items- .iter()- .map(|r| r.entity_id.to_string())- .collect();- let second_ids: Vec<String> = second_response- .items- .iter()- .map(|r| r.entity_id.to_string())- .collect();-- for id in &first_ids {- assert!(- !second_ids.contains(id),- "Found duplicate ID between pages: {}",- id- );- }-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_no_results(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search for a term that doesn't match any documents- let response = search_document_names(- &pool,- &user_id,- &[],- "nonexistent".to_string(),- false,- 10,- None,- )- .await?;-- assert_eq!(response.items.len(), 0);- assert!(response.cursor.is_done());-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_partial_match(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search for partial term "meet" should match "meeting"- let response =- search_document_names(&pool, &user_id, &[], "meet".to_string(), false, 10, None).await?;-- assert_eq!(response.items.len(), 2);- assert_eq!(- response.items[0].entity_id.to_string(),- "55555555-5555-5555-5555-555555555555"- );- assert_eq!(- response.items[0].name,- "Client <macro_em>Meet</macro_em>ing Agenda"- );-- assert_eq!(- response.items[1].entity_id.to_string(),- "44444444-4444-4444-4444-444444444444"- );- assert_eq!(- response.items[1].name,- "Team <macro_em>Meet</macro_em>ing Notes"- );-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_user_isolation(pool: Pool<Postgres>) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- // Search for "User2" - user1 should not see user2's private documents- let response =- search_document_names(&pool, &user_id, &[], "User2".to_string(), false, 10, None).await?;-- // Should return 0 results (user2's documents are not owned by user1 and not shared)- assert_eq!(response.items.len(), 0);-- Ok(())-}--#[sqlx::test(- migrator = "MACRO_DB_MIGRATIONS",- fixtures(path = "../../fixtures", scripts("document"))-)]-async fn test_search_document_names_rejects_thread_cursor(- pool: Pool<Postgres>,-) -> anyhow::Result<()> {- let user_id = MacroUserId::parse_from_str("macro|[email protected]")- .map(|l| l.lowercase())- .unwrap();-- let cursor = SearchMethodCursor::Thread {- thread_id: Uuid::new_v4(),- message_id: Uuid::new_v4(),- };-- let result = search_document_names(- &pool,- &user_id,- &[],- "test".to_string(),- false,- 10,- Some(cursor),- )- .await;-- assert!(matches!(- result.unwrap_err(),- NameSearchError::IncompatibleCursor- ));-- Ok(())-}diff --git a/rust/cloud-storage/name_search/src/lib.rs b/rust/cloud-storage/name_search/src/lib.rsindex 0cec3f97e0..53dafcdd06 100644--- a/rust/cloud-storage/name_search/src/lib.rs+++ b/rust/cloud-storage/name_search/src/lib.rs@@ -2,11 +2,9 @@//! This crate contains queries to search over macro db entities by their namemod chat;-mod document;mod highlight;pub use chat::search_chat_names;-pub use document::search_document_names;pub use highlight::highlight_name;pub use models_opensearch::SearchEntityType;use models_search_cursor::{PaginatedResult, SearchCursorAttributes};