Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
feat(search) remove channels name from search (#295)
Will Hutchinson5b402cde6e7b
diff --git a/infra/stacks/opensearch/helpers/scripts/create_indices.ts b/infra/stacks/opensearch/helpers/scripts/create_indices.tsindex 710dd71540..34cff3afad 100644--- a/infra/stacks/opensearch/helpers/scripts/create_indices.ts+++ b/infra/stacks/opensearch/helpers/scripts/create_indices.ts@@ -76,16 +76,6 @@ async function createChannelIndex(opensearchClient: Client) {entity_id: {type: 'keyword',},- channel_name: {- type: 'text',- fields: {- keyword: {- type: 'keyword',- ignore_above: 128,- },- },- index: true,- },channel_type: {type: 'keyword',index: true,diff --git a/infra/stacks/opensearch/helpers/scripts/remove_field_from_index.ts b/infra/stacks/opensearch/helpers/scripts/remove_field_from_index.tsnew file mode 100644index 0000000000..b5898f52ac--- /dev/null+++ b/infra/stacks/opensearch/helpers/scripts/remove_field_from_index.ts@@ -0,0 +1,72 @@+/**+ * This script removes a field from the provided comma-separated list of indices.+ * Usage: bun scripts/remove_field_from_index.ts <indices> <field_name>+ */+require('dotenv').config();++import { client } from '../client';+import { IS_DRY_RUN } from '../constants';+import { removeField } from '../utils/remove_field';++// Get indices and user_id from command line arguments+const indicesArg = process.argv[2];+const fieldName = process.argv[3];++if (!indicesArg || !fieldName) {+ console.error('Missing required command line arguments:');+ console.error(+ 'Usage: bun scripts/remove_field_from_index.ts <indices> <field_name>'+ );+ console.error(+ ' indices: Comma-separated list of index names (e.g., "documents,chats,emails")'+ );+ console.error(' field_name: The field name to remove');+ console.error('\nExample:');+ console.error('node script.js "documents,emails,chats" "random_field_name"');+ process.exit(1);+}++const INDICES_TO_PROCESS = indicesArg+ .split(',')+ .map((index: string) => index.trim());++async function run(dryRun: boolean = true) {+ const opensearchClient = client();++ console.log('\n' + '='.repeat(60));+ console.log(+ `OpenSearch Field Cleanup Script ${dryRun ? '(DRY-RUN MODE)' : '(LIVE MODE)'}`+ );+ console.log('='.repeat(60));+ console.log(`\nThis script will remove ${fieldName} field`);+ console.log(+ '\n⚠️ WARNING: This will permanently delete data from documents!'+ );++ if (dryRun) {+ console.log('\n⚠️ DRY-RUN MODE: No changes will be made to the database');+ } else {+ console.log('\n🚨 LIVE MODE: Fields will be permanently removed!');+ }++ for (const index of INDICES_TO_PROCESS) {+ console.log(`Processing index: ${index}`);+ try {+ removeField(opensearchClient, dryRun, {+ indexName: index,+ fieldNameToRemove: fieldName,+ });+ console.log('\n' + '='.repeat(60));+ console.log(`Cleanup completed successfully for ${index}!`);+ console.log('='.repeat(60));+ } catch (error) {+ console.error(+ `Error removing field ${fieldName} from index ${index}:`,+ error+ );+ process.exit(1);+ }+ }+}++run(IS_DRY_RUN);diff --git a/infra/stacks/opensearch/helpers/scripts/remove_project_parent_id_mapping.ts b/infra/stacks/opensearch/helpers/scripts/remove_project_parent_id_mapping.tsdeleted file mode 100644index 87c451b3b1..0000000000--- a/infra/stacks/opensearch/helpers/scripts/remove_project_parent_id_mapping.ts+++ /dev/null@@ -1,50 +0,0 @@-require('dotenv').config();--import { client } from '../client';-import { IS_DRY_RUN, PROJECT_INDEX } from '../constants';-import { removeField } from '../utils/remove_field';--async function run(dryRun: boolean = true) {- const opensearchClient = client();-- console.log('\n' + '='.repeat(60));- console.log(- `OpenSearch Field Cleanup Script ${dryRun ? '(DRY-RUN MODE)' : '(LIVE MODE)'}`- );- console.log('='.repeat(60));- console.log('\nThis script will remove old parent_project_id fields');- console.log(- '\n⚠️ WARNING: This will permanently delete data from documents!'- );-- if (dryRun) {- console.log('\n⚠️ DRY-RUN MODE: No changes will be made to the database');- } else {- console.log('\n🚨 LIVE MODE: Fields will be permanently removed!');- }-- try {- removeField(opensearchClient, dryRun, {- indexName: PROJECT_INDEX,- fieldNameToRemove: 'parent_project_id',- });-- console.log('\n' + '='.repeat(60));- console.log('Cleanup completed successfully!');- console.log('='.repeat(60));-- if (dryRun) {- console.log(- '\nTo run the cleanup for real, set DRY_RUN=false environment variable'- );- } else {- console.log('\n✓ parent_project_id has been removed.');- console.log('✓ Only entity_id fields remain.\n');- }- } catch (error) {- console.error('\n❌ Cleanup failed:', error);- throw error;- }-}--run(IS_DRY_RUN);diff --git a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rsindex 98fcf2887d..aefd69d40f 100644--- a/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/create_channel.rs@@ -8,10 +8,7 @@ use axum::{use comms_db_client::channels::create_channel::{CreateChannelOptions, create_channel};use model::comms::ChannelType;use model::user::UserContext;-use models_opensearch::SearchEntityType;use serde::{Deserialize, Serialize};-use sqs_client::search::{SearchQueueMessage, name::UpdateEntityName};-use tracing::Instrument;use utoipa::ToSchema;#[derive(Debug, Serialize, Deserialize, ToSchema)]@@ -114,29 +111,6 @@ pub async fn create_channel_handler(})?;}- if req.name.is_some() {- tokio::spawn({- let sqs_client = ctx.sqs_client.clone();- let channel_id = id;- async move {- tracing::trace!("sending message to search extractor queue");-- let _ = sqs_client- .send_message_to_search_event_queue(SearchQueueMessage::UpdateEntityName(- UpdateEntityName {- entity_id: channel_id,- entity_type: SearchEntityType::Channels,- },- ))- .await- .inspect_err(|e| {- tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");- });- }- .in_current_span()- });- }-Ok((StatusCode::OK,Json(CreateChannelResponse { id: id.to_string() }),diff --git a/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs b/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rsindex a7f55de2f3..fc4658455c 100644--- a/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs+++ b/rust/cloud-storage/comms_service/src/api/channels/patch_channel.rs@@ -7,8 +7,6 @@ use axum::{Json, extract::State, http::StatusCode};use axum_extra::extract::Cached;use comms_db_client::channels::patch_channel::{self, PatchChannelOptions};use model::comms::ChannelType;-use models_opensearch::SearchEntityType;-use tracing::Instrument;#[utoipa::path(patch,@@ -38,8 +36,6 @@ pub async fn patch_channel_handler());}- let name = req.channel_name.clone();-patch_channel::patch_channel(&ctx.db, &channel_id, &channel_owner.context.user_id, req).await.map_err(|e| {@@ -51,30 +47,5 @@ pub async fn patch_channel_handler()})?;- if name.is_some() {- tokio::spawn({- let sqs_client = ctx.sqs_client.clone();- let channel_id = channel_id;- async move {- tracing::trace!("sending message to search extractor queue");-- let _ = sqs_client- .send_message_to_search_event_queue(- sqs_client::search::SearchQueueMessage::UpdateEntityName(- sqs_client::search::name::UpdateEntityName {- entity_id: channel_id,- entity_type: SearchEntityType::Channels,- },- ),- )- .await- .inspect_err(|e| {- tracing::error!(error=?e, "SEARCH_QUEUE unable to enqueue message");- });- }- .in_current_span()- });- }-Ok((StatusCode::OK, "patched channel".to_string()))}diff --git a/rust/cloud-storage/macro_db_client/.sqlx/query-34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570.json b/rust/cloud-storage/macro_db_client/.sqlx/query-34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570.jsondeleted file mode 100644index 32c5fe0adb..0000000000--- a/rust/cloud-storage/macro_db_client/.sqlx/query-34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570.json+++ /dev/null@@ -1,22 +0,0 @@-{- "db_name": "PostgreSQL",- "query": "\n SELECT\n c.name as \"name?\"\n FROM\n \"comms_channels\" c\n WHERE\n c.id = $1\n ",- "describe": {- "columns": [- {- "ordinal": 0,- "name": "name?",- "type_info": "Varchar"- }- ],- "parameters": {- "Left": [- "Uuid"- ]- },- "nullable": [- true- ]- },- "hash": "34a1c3b64fdb985b5e78d815f8fac33efbd25ad5cb6854e9fe3949518f530570"-}diff --git a/rust/cloud-storage/macro_db_client/src/entity_name.rs b/rust/cloud-storage/macro_db_client/src/entity_name.rsindex 21e9404cd9..0543f12d49 100644--- a/rust/cloud-storage/macro_db_client/src/entity_name.rs+++ b/rust/cloud-storage/macro_db_client/src/entity_name.rs@@ -57,22 +57,6 @@ pub async fn get_entity_name(.fetch_one(db).await?}- SearchEntityType::Channels => {- sqlx::query!(- r#"- SELECT- c.name as "name?"- FROM- "comms_channels" c- WHERE- c.id = $1- "#,- entity_id,- )- .map(|row| row.name)- .fetch_one(db)- .await?- }_ => {anyhow::bail!("entity type not supported");}diff --git a/rust/cloud-storage/macro_db_client/src/entity_name/test.rs b/rust/cloud-storage/macro_db_client/src/entity_name/test.rsindex 7f44e9731e..a61c26dc6b 100644--- a/rust/cloud-storage/macro_db_client/src/entity_name/test.rs+++ b/rust/cloud-storage/macro_db_client/src/entity_name/test.rs@@ -9,9 +9,6 @@ async fn test_get_entity_name(pool: sqlx::Pool<sqlx::Postgres>) -> anyhow::Resullet entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Chats).await?;assert_eq!(entity_name, Some("chat".to_string()));- let entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Channels).await?;- assert_eq!(entity_name, Some("channel".to_string()));-let entity_name = get_entity_name(&pool, &entity_id, &SearchEntityType::Emails).await?;assert_eq!(entity_name, Some("subject".to_string()));diff --git a/rust/cloud-storage/models_search/src/channel.rs b/rust/cloud-storage/models_search/src/channel.rsindex e80bf7a6a4..a260bcd1f8 100644--- a/rust/cloud-storage/models_search/src/channel.rs+++ b/rust/cloud-storage/models_search/src/channel.rs@@ -31,7 +31,6 @@ pub struct ChannelSearchResponseItem {/// These field names are being aligned across all item types/// for consistency in our data model.pub id: String,- pub name: Option<String>,/// we don't store this for channels atm but keeping it here for consistencypub owner_id: Option<String>,@@ -39,8 +38,6 @@ pub struct ChannelSearchResponseItem {pub channel_type: String,/// The id of the channelpub channel_id: String,- /// The name of the channel if present- pub channel_name: Option<String>,/// The search results for the channel/// This may be empty if the search result match was not on contentpub channel_message_search_results: Vec<ChannelSearchResult>,@@ -71,8 +68,6 @@ pub struct ChannelSearchResponseItemWithMetadata {pub struct ChannelSearchMetadata {/// The id of the channelpub channel_id: String,- /// The name of the channel if present- pub channel_name: Option<String>,/// The type of channelpub channel_type: String,}@@ -83,12 +78,10 @@ impl From<SearchResponseItem<ChannelSearchResult, ChannelSearchMetadata>>fn from(response: SearchResponseItem<ChannelSearchResult, ChannelSearchMetadata>) -> Self {ChannelSearchResponseItem {id: response.metadata.channel_id.clone(),- name: response.metadata.channel_name.clone(),// we don't store this for channels atm but keeping it here for consistencyowner_id: None,channel_type: response.metadata.channel_type.clone(),channel_id: response.metadata.channel_id.clone(),- channel_name: response.metadata.channel_name.clone(),channel_message_search_results: response.results,}}@@ -128,8 +121,6 @@ pub struct ChannelSearchRequest {pub struct SimpleChannelSearchReponseBaseItem<T> {/// The channel idpub channel_id: String,- /// The channel name- pub channel_name: Option<String>,/// The channel typepub channel_type: String,/// The org id@@ -161,7 +152,6 @@ impl From<opensearch_client::search::channels::ChannelMessageSearchResponse>fn from(response: opensearch_client::search::channels::ChannelMessageSearchResponse) -> Self {Self {channel_id: response.channel_id,- channel_name: response.channel_name,channel_type: response.channel_type,org_id: response.org_id,message_id: response.message_id,diff --git a/rust/cloud-storage/models_search/src/unified.rs b/rust/cloud-storage/models_search/src/unified.rsindex a65637506f..2d3c900832 100644--- a/rust/cloud-storage/models_search/src/unified.rs+++ b/rust/cloud-storage/models_search/src/unified.rs@@ -210,7 +210,6 @@ impl From<opensearch_client::search::unified::UnifiedSearchResponse>opensearch_client::search::unified::UnifiedSearchResponse::ChannelMessage(a) => {SimpleUnifiedSearchResponseItem::Channel(SimpleChannelSearchReponseBaseItem {channel_id: a.channel_id,- channel_name: a.channel_name,channel_type: a.channel_type,org_id: a.org_id,message_id: a.message_id,diff --git a/rust/cloud-storage/opensearch_client/examples/generate_all_upserts.rs b/rust/cloud-storage/opensearch_client/examples/generate_all_upserts.rsindex c2c35e2e19..d67d1a770f 100644--- a/rust/cloud-storage/opensearch_client/examples/generate_all_upserts.rs+++ b/rust/cloud-storage/opensearch_client/examples/generate_all_upserts.rs@@ -46,14 +46,6 @@ async fn main() -> anyhow::Result<()> {"Jupiter Analytics Platform",];- // Varied channel names- let channel_names = [- "Engineering Team (Test keyword for matching: Pineapple)",- "Design Collaboration",- "Product Strategy",- "DevOps Alerts",- ];-// Varied chat titleslet chat_titles = ["Code Review Discussion",@@ -133,7 +125,6 @@ async fn main() -> anyhow::Result<()> {for i in 1..=4 {let channel_args = UpsertChannelMessageArgs {channel_id: format!("channel_{}", (i % 2) + 1),- channel_name: Some(channel_names[(i - 1) % channel_names.len()].to_string()),channel_type: "public".to_string(),org_id: Some(1),message_id: format!("msg_{}", i),diff --git a/rust/cloud-storage/opensearch_client/src/error.rs b/rust/cloud-storage/opensearch_client/src/error.rsindex d585d50a85..544b594cd5 100644--- a/rust/cloud-storage/opensearch_client/src/error.rs+++ b/rust/cloud-storage/opensearch_client/src/error.rs@@ -41,6 +41,9 @@ pub enum OpensearchClientError {details: String,method: Option<String>,},++ #[error("no title key is available for name search")]+ NoTitleKeyForNameSearch,}impl From<anyhow::Error> for OpensearchClientError {diff --git a/rust/cloud-storage/opensearch_client/src/search/builder.rs b/rust/cloud-storage/opensearch_client/src/search/builder.rsindex 78612cb333..79786c51cb 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder.rs@@ -48,8 +48,8 @@ pub trait SearchQueryConfig {const ID_KEY: &'static str = "entity_id";/// Key for user idconst USER_ID_KEY: &'static str;- /// Key for title- const TITLE_KEY: &'static str;+ /// Key for title (there may not be a title key for things like channels index)+ const TITLE_KEY: Option<&'static str>;/// Content fieldconst CONTENT_KEY: &'static str = "content";@@ -222,32 +222,45 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {let highlight = match self.search_on {SearchOn::Content => T::default_highlight(),- SearchOn::Name => Highlight::new().require_field_match(true).field(- T::TITLE_KEY,- HighlightField::new()- .highlight_type("plain")- .pre_tags(vec![MacroEm::Open.to_string()])- .post_tags(vec![MacroEm::Close.to_string()])- .number_of_fragments(1),- ),- SearchOn::NameContent => Highlight::new()- .require_field_match(false)- .field(- T::TITLE_KEY,- HighlightField::new()- .highlight_type("plain")- .pre_tags(vec![MacroEm::Open.to_string()])- .post_tags(vec![MacroEm::Close.to_string()])- .number_of_fragments(1),- )- .field(- T::CONTENT_KEY,+ SearchOn::Name => {+ if let Some(title_key) = T::TITLE_KEY {+ Highlight::new().require_field_match(true).field(+ title_key,+ HighlightField::new()+ .highlight_type("plain")+ .pre_tags(vec![MacroEm::Open.to_string()])+ .post_tags(vec![MacroEm::Close.to_string()])+ .number_of_fragments(1),+ )+ } else {+ return Err(OpensearchClientError::NoTitleKeyForNameSearch);+ }+ }+ SearchOn::NameContent => {+ let mut highlight = Highlight::new();+ highlight = highlight.require_field_match(false);+ if let Some(title_key) = T::TITLE_KEY {+ highlight = highlight.field(+ title_key,+ HighlightField::new()+ .highlight_type("plain")+ .pre_tags(vec![MacroEm::Open.to_string()])+ .post_tags(vec![MacroEm::Close.to_string()])+ .number_of_fragments(1),+ );+ }++ highlight = highlight.field(+ "content",HighlightField::new().highlight_type("plain").pre_tags(vec![MacroEm::Open.to_string()]).post_tags(vec![MacroEm::Close.to_string()]).number_of_fragments(1),- ),+ );++ highlight+ }};search_request.highlight(highlight);@@ -317,12 +330,16 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {match self.search_on {SearchOn::Name => {- // map all terms over title key- must_array.push(generate_terms_must_query(- query_key,- &[keys.title_key],- &self.terms,- ));+ if let Some(title_key) = keys.title_key {+ // map all terms over title key+ must_array.push(generate_terms_must_query(+ query_key,+ &[title_key],+ &self.terms,+ ));+ } else {+ return Err(OpensearchClientError::NoTitleKeyForNameSearch);+ }}SearchOn::Content => {// map all terms over content keydiff --git a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs b/rust/cloud-storage/opensearch_client/src/search/builder/test.rsindex a4c62b72d8..bdcac992fa 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder/test.rs@@ -6,7 +6,7 @@ struct TestSearchConfig;impl SearchQueryConfig for TestSearchConfig {const USER_ID_KEY: &'static str = "test_user_id";- const TITLE_KEY: &'static str = "test_title";+ const TITLE_KEY: Option<&'static str> = Some("test_title");}#[test]diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 0d054004a4..e26ba4046c 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -19,7 +19,6 @@ use serde_json::Value;#[derive(Debug, serde::Serialize, serde::Deserialize)]pub(crate) struct ChannelMessageIndex {pub entity_id: String,- pub channel_name: Option<String>,pub channel_type: String,pub org_id: Option<i64>,pub message_id: String,@@ -34,7 +33,6 @@ pub(crate) struct ChannelMessageIndex {#[derive(Debug, serde::Serialize, serde::Deserialize, Clone)]pub struct ChannelMessageSearchResponse {pub channel_id: String,- pub channel_name: Option<String>,pub channel_type: String,pub org_id: Option<i64>,pub message_id: String,@@ -54,7 +52,7 @@ pub(crate) struct ChannelMessageSearchConfig;impl SearchQueryConfig for ChannelMessageSearchConfig {const USER_ID_KEY: &'static str = "sender_id";- const TITLE_KEY: &'static str = "channel_name";+ const TITLE_KEY: Option<&'static str> = None;fn default_sort_types() -> Vec<SortType<'static>> {vec![@@ -226,7 +224,6 @@ pub(crate) async fn search_channel_messages(.into_iter().map(|hit| ChannelMessageSearchResponse {channel_id: hit.source.entity_id,- channel_name: hit.source.channel_name,channel_type: hit.source.channel_type,org_id: hit.source.org_id,message_id: hit.source.message_id,diff --git a/rust/cloud-storage/opensearch_client/src/search/chats.rs b/rust/cloud-storage/opensearch_client/src/search/chats.rsindex ef1983339d..3d90e3a5ce 100644--- a/rust/cloud-storage/opensearch_client/src/search/chats.rs+++ b/rust/cloud-storage/opensearch_client/src/search/chats.rs@@ -44,7 +44,7 @@ pub(crate) struct ChatSearchConfig;impl SearchQueryConfig for ChatSearchConfig {const USER_ID_KEY: &'static str = "user_id";- const TITLE_KEY: &'static str = "title";+ const TITLE_KEY: Option<&'static str> = Some("title");fn default_sort_types() -> Vec<SortType<'static>> {vec![diff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rsindex 5871823b5c..b8a9247004 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs@@ -21,7 +21,7 @@ pub(crate) struct DocumentSearchConfig;impl SearchQueryConfig for DocumentSearchConfig {const USER_ID_KEY: &'static str = "owner_id";- const TITLE_KEY: &'static str = "document_name";+ const TITLE_KEY: Option<&'static str> = Some("document_name");fn default_sort_types() -> Vec<SortType<'static>> {vec![diff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex 0152b3e53d..5a6424aa31 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -23,7 +23,7 @@ pub(crate) struct EmailSearchConfig;impl SearchQueryConfig for EmailSearchConfig {const USER_ID_KEY: &'static str = "user_id";- const TITLE_KEY: &'static str = "subject";+ const TITLE_KEY: Option<&'static str> = Some("subject");fn default_sort_types() -> Vec<SortType<'static>> {vec![diff --git a/rust/cloud-storage/opensearch_client/src/search/model.rs b/rust/cloud-storage/opensearch_client/src/search/model.rsindex da7c920d6c..d6bfaad537 100644--- a/rust/cloud-storage/opensearch_client/src/search/model.rs+++ b/rust/cloud-storage/opensearch_client/src/search/model.rs@@ -46,10 +46,14 @@ pub(crate) fn parse_highlight_hit(highlight: HashMap<String, Vec<String>>,keys: Keys,) -> Highlight {- let name = highlight- .get(keys.title_key)- .and_then(|v| v.first())- .map(|v| v.to_string());+ let name = if let Some(title_key) = keys.title_key {+ highlight+ .get(title_key)+ .and_then(|v| v.first())+ .map(|v| v.to_string())+ } else {+ None+ };Highlight {name,diff --git a/rust/cloud-storage/opensearch_client/src/search/projects.rs b/rust/cloud-storage/opensearch_client/src/search/projects.rsindex 54ce9e8e75..f9205fecee 100644--- a/rust/cloud-storage/opensearch_client/src/search/projects.rs+++ b/rust/cloud-storage/opensearch_client/src/search/projects.rs@@ -19,14 +19,15 @@ pub(crate) struct ProjectSearchConfig;impl SearchQueryConfig for ProjectSearchConfig {const USER_ID_KEY: &'static str = "user_id";- const TITLE_KEY: &'static str = "project_name";+ const TITLE_KEY: Option<&'static str> = Some("project_name");// Projects have no "content" to highlight match on, so match on the TITLE_KEY insteadfn default_highlight() -> opensearch_query_builder::Highlight<'static> {opensearch_query_builder::Highlight::new().require_field_match(true).field(- Self::TITLE_KEY,+ // we know the title key exists because it's implemented right above+ Self::TITLE_KEY.unwrap(),HighlightField::new().highlight_type("plain").number_of_fragments(1)diff --git a/rust/cloud-storage/opensearch_client/src/search/query.rs b/rust/cloud-storage/opensearch_client/src/search/query.rsindex dea0c0813a..795dff60e2 100644--- a/rust/cloud-storage/opensearch_client/src/search/query.rs+++ b/rust/cloud-storage/opensearch_client/src/search/query.rs@@ -8,7 +8,7 @@ use unicode_segmentation::UnicodeSegmentation;/// Containing keys for the title and content fieldspub struct Keys<'a> {/// The title field key- pub title_key: &'a str,+ pub title_key: Option<&'a str>,/// The content field keypub content_key: &'a str,}@@ -150,20 +150,24 @@ pub(crate) fn generate_name_content_query(keys: &Keys, terms: &[String]) -> Querlet mut bool_query = BoolQueryBuilder::new();bool_query.minimum_should_match(1);- bool_query.should(QueryType::MatchPhrasePrefix(- MatchPhrasePrefixQuery::new(keys.title_key.to_string(), term.clone()).boost(1000.0),- ));+ if let Some(title_key) = keys.title_key {+ bool_query.should(QueryType::MatchPhrasePrefix(+ MatchPhrasePrefixQuery::new(title_key.to_string(), term.clone()).boost(1000.0),+ ));+ }bool_query.should(QueryType::MatchPhrasePrefix(MatchPhrasePrefixQuery::new(keys.content_key.to_string(), term.clone()).boost(900.0),));- bool_query.should(QueryType::Match(- MatchQuery::new(keys.title_key.to_string(), term.clone())- .boost(0.1)- .minimum_should_match("80%"), // TODO: we may need to play around with this to get the best highlight match- ));+ if let Some(title_key) = keys.title_key {+ bool_query.should(QueryType::Match(+ MatchQuery::new(title_key.to_string(), term.clone())+ .boost(0.1)+ .minimum_should_match("80%"), // TODO: we may need to play around with this to get the best highlight match+ ));+ }bool_query.should(QueryType::Match(MatchQuery::new(keys.content_key.to_string(), term.clone())diff --git a/rust/cloud-storage/opensearch_client/src/search/query/test.rs b/rust/cloud-storage/opensearch_client/src/search/query/test.rsindex f4f2ab5305..3dd3f13afc 100644--- a/rust/cloud-storage/opensearch_client/src/search/query/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/query/test.rs@@ -126,7 +126,7 @@ fn test_generate_terms_must_query() -> anyhow::Result<()> {#[test]fn test_generate_name_content_query() -> anyhow::Result<()> {let keys = Keys {- title_key: "test_title",+ title_key: Some("test_title"),content_key: "test_content",};@@ -270,5 +270,39 @@ fn test_generate_name_content_query() -> anyhow::Result<()> {assert_eq!(result.to_json(), expected);+ let keys = Keys {+ title_key: None,+ content_key: "test_content",+ };++ let result = generate_name_content_query(&keys, &["test".to_string()]);++ let expected = serde_json::json!({+ "bool": {+ "minimum_should_match": 1,+ "should": [+ {+ "match_phrase_prefix": {+ "test_content": {+ "query": "test",+ "boost": 900.0+ }+ }+ },+ {+ "match": {+ "test_content": {+ "boost": 0.09,+ "minimum_should_match": "1",+ "query": "test"+ }+ }+ }+ ]+ }+ });++ assert_eq!(result.to_json(), expected);+Ok(())}diff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rsindex 987967e97e..c6511df682 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs@@ -264,7 +264,6 @@ impl From<Hit<UnifiedSearchIndex>> for UnifiedSearchResponse {UnifiedSearchIndex::ChannelMessage(a) => {UnifiedSearchResponse::ChannelMessage(ChannelMessageSearchResponse {channel_id: a.entity_id,- channel_name: a.channel_name,channel_type: a.channel_type,org_id: a.org_id,message_id: a.message_id,@@ -392,7 +391,7 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequesreturn Err(OpensearchClientError::EmptySearchIndices);}// Build out the title keys that we could need for highlighting- let mut title_keys = vec![];+ let mut title_keys: Vec<Option<&'static str>> = vec![];for index in &args.search_indices {match index {SearchEntityType::Channels => title_keys.push(ChannelMessageSearchConfig::TITLE_KEY),@@ -403,6 +402,8 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchReques}}+ let title_keys: Vec<&'static str> = title_keys.into_iter().flatten().collect();+let mut bool_query = BoolQueryBuilder::new();bool_query.minimum_should_match(1);@@ -422,7 +423,9 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequesbool_query.should(email_bool_query.build().into());}- if args.search_indices.contains(&SearchEntityType::Channels) {+ // We can only search over channels if we are not explicitly searching by name+ if args.search_indices.contains(&SearchEntityType::Channels) && args.search_on != SearchOn::Name+ {let channel_message_search_args: ChannelMessageSearchArgs = args.clone().into();let channel_message_query_builder: ChannelMessageQueryBuilder =channel_message_search_args.into();diff --git a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs b/rust/cloud-storage/opensearch_client/src/search/unified/test.rsindex ac8a5d84ba..d691d71f0d 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs@@ -882,16 +882,6 @@ fn test_build_unified_search_request_name() -> anyhow::Result<()> {],"type": "plain"},- "channel_name": {- "number_of_fragments": 1,- "post_tags": [- "</macro_em>"- ],- "pre_tags": [- "<macro_em>"- ],- "type": "plain"- },"project_name": {"number_of_fragments": 1,"post_tags": [@@ -1073,57 +1063,6 @@ fn test_build_unified_search_request_name() -> anyhow::Result<()> {]}},- {- "bool": {- "minimum_should_match": 1,- "must": [- {- "match_phrase": {- "channel_name": "test"- }- },- {- "terms": {- "thread_id": [- "id1",- "id2"- ]- }- },- {- "terms": {- "mentions": [- "id1",- "id2"- ]- }- },- {- "terms": {- "sender_id": [- "id1",- "id2"- ]- }- },- {- "term": {- "_index": "channels"- }- }- ],- "should": [- {- "terms": {- "entity_id": [- "id1",- "id2"- ]- }- },- ]- }- },{"bool": {"minimum_should_match": 1,@@ -1296,16 +1235,6 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"from": 20,"highlight": {"fields": {- "channel_name": {- "number_of_fragments": 1,- "post_tags": [- "</macro_em>"- ],- "pre_tags": [- "<macro_em>"- ],- "type": "plain"- },"content": {"number_of_fragments": 1,"post_tags": [@@ -1623,14 +1552,6 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {"bool": {"minimum_should_match": 1,"should": [- {- "match_phrase_prefix": {- "channel_name": {- "boost": 1000.0,- "query": "test"- }- }- },{"match_phrase_prefix": {"content": {@@ -1639,15 +1560,6 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {}}},- {- "match": {- "channel_name": {- "boost": 0.1,- "minimum_should_match": "80%",- "query": "test"- }- }- },{"match": {"content": {diff --git a/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs b/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rsindex ca9d4e0d8f..8f696b5da4 100644--- a/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs+++ b/rust/cloud-storage/opensearch_client/src/upsert/channel_message.rs@@ -7,7 +7,6 @@ use crate::{Result, date_format::EpochSeconds, error::OpensearchClientError};pub struct UpsertChannelMessageArgs {#[serde(rename = "entity_id")]pub channel_id: String,- pub channel_name: Option<String>,pub channel_type: String,pub org_id: Option<i64>,pub message_id: String,diff --git a/rust/cloud-storage/search_processing_service/src/process/channel.rs b/rust/cloud-storage/search_processing_service/src/process/channel.rsindex cb31069525..c1cd427554 100644--- a/rust/cloud-storage/search_processing_service/src/process/channel.rs+++ b/rust/cloud-storage/search_processing_service/src/process/channel.rs@@ -27,7 +27,6 @@ pub async fn process_channel_message_update(let upsert_channel_message_args = UpsertChannelMessageArgs {channel_id: channel_message_info.channel_id.to_string(),- channel_name: channel_message_info.name,channel_type: channel_message_info.channel_type.to_string(),org_id: channel_message_info.org_id,message_id: channel_message_info.channel_message.message_id.to_string(),diff --git a/rust/cloud-storage/search_processing_service/src/process/name.rs b/rust/cloud-storage/search_processing_service/src/process/name.rsindex 5a1cd458ef..58149c9dce 100644--- a/rust/cloud-storage/search_processing_service/src/process/name.rs+++ b/rust/cloud-storage/search_processing_service/src/process/name.rs@@ -21,6 +21,10 @@ pub async fn upsert_name(return Ok(());};+ if name.is_empty() {+ return Ok(());+ }+// Perform upsertopensearch_client.upsert_entity_name(&UpsertEntityNameArgs {diff --git a/rust/cloud-storage/search_service/src/api/search/channel/test.rs b/rust/cloud-storage/search_service/src/api/search/channel/test.rsindex b9ca8bcca1..dbcde20042 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@@ -15,7 +15,6 @@ fn test_construct_search_result_single_channel() {let search_results = vec![opensearch_client::search::channels::ChannelMessageSearchResponse {channel_id: channel_uuid.to_string(),- channel_name: Some("Test Channel".to_string()),channel_type: "public".to_string(),org_id: Some(123),message_id: "msg1".to_string(),@@ -43,12 +42,6 @@ fn test_construct_search_result_single_channel() {assert_eq!(result.len(), 1);assert_eq!(result[0].extra.channel_id, channel_uuid);assert_eq!(result[0].extra.id, channel_uuid);- assert_eq!(- result[0].extra.channel_name,- Some("Test Channel".to_string())- );- assert_eq!(result[0].extra.name, Some("Test Channel".to_string()));- assert_eq!(result[0].extra.channel_message_search_results.len(), 1);assert_eq!(result[0].extra.channel_message_search_results[0].message_id,"msg1"@@ -69,7 +62,6 @@ fn test_construct_search_result_multiple_messages_same_channel() {let search_results = vec![opensearch_client::search::channels::ChannelMessageSearchResponse {channel_id: channel_uuid.to_string(),- channel_name: Some("Test Channel".to_string()),channel_type: "public".to_string(),org_id: Some(123),message_id: "msg1".to_string(),@@ -86,7 +78,6 @@ fn test_construct_search_result_multiple_messages_same_channel() {},opensearch_client::search::channels::ChannelMessageSearchResponse {channel_id: channel_uuid.to_string(),- channel_name: Some("Test Channel".to_string()),channel_type: "public".to_string(),org_id: Some(123),message_id: "msg2".to_string(),@@ -114,7 +105,6 @@ fn test_construct_search_result_multiple_messages_same_channel() {assert_eq!(result.len(), 1);assert_eq!(result[0].extra.channel_id, channel_uuid);assert_eq!(result[0].extra.id, channel_uuid);- assert_eq!(result[0].extra.name, Some("Test Channel".to_string()));assert_eq!(result[0].extra.channel_message_search_results.len(), 2);let message_ids: Vec<String> = result[0]@@ -142,7 +132,6 @@ fn test_construct_search_result_filters_messages_without_content() {let search_results = vec![opensearch_client::search::channels::ChannelMessageSearchResponse {channel_id: channel_uuid.to_string(),- channel_name: Some("Test Channel".to_string()),channel_type: "public".to_string(),org_id: Some(123),message_id: "msg1".to_string(),@@ -159,7 +148,6 @@ fn test_construct_search_result_filters_messages_without_content() {},opensearch_client::search::channels::ChannelMessageSearchResponse {channel_id: channel_uuid.to_string(),- channel_name: Some("Test Channel".to_string()),channel_type: "public".to_string(),org_id: Some(123),message_id: "msg2".to_string(),@@ -197,7 +185,6 @@ fn create_test_channel_response() -> opensearch_client::search::channels::ChannelMessageSearchResponse {opensearch_client::search::channels::ChannelMessageSearchResponse {channel_id: channel_id.to_string(),- channel_name: Some("Test Channel".to_string()),channel_type: "public".to_string(),org_id: Some(123),message_id: message_id.to_string(),diff --git a/rust/cloud-storage/search_service/src/model/mod.rs b/rust/cloud-storage/search_service/src/model/mod.rsindex 3c6ee78f8f..8bde0a179e 100644--- a/rust/cloud-storage/search_service/src/model/mod.rs+++ b/rust/cloud-storage/search_service/src/model/mod.rs@@ -169,7 +169,6 @@ impl Metadata<ChannelSearchMetadata> for ChannelOpenSearchResponse {fn metadata(&self, id: &str) -> ChannelSearchMetadata {ChannelSearchMetadata {channel_id: id.to_string(),- channel_name: self.inner.channel_name.clone(),channel_type: self.inner.channel_type.clone(),}}