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): return total_count from channel search (#3194)
gbirman4c49d63d0deb
diff --git a/js/app/packages/service-clients/service-search/generated/models/channelSearchResponse.ts b/js/app/packages/service-clients/service-search/generated/models/channelSearchResponse.tsindex 3e3a074f06..21304b295a 100644--- a/js/app/packages/service-clients/service-search/generated/models/channelSearchResponse.ts+++ b/js/app/packages/service-clients/service-search/generated/models/channelSearchResponse.ts@@ -16,4 +16,6 @@ export interface ChannelSearchResponse {next_cursor?: ChannelSearchResponseNextCursor;/** List containing results from email threads */results: ChannelSearchResponseItemWithMetadata[];+ /** Total number of matching channel messages across all pages. */+ total_count: number;}diff --git a/js/app/packages/service-clients/service-search/openapi.json b/js/app/packages/service-clients/service-search/openapi.jsonindex c39b2dcd71..582e8c33ce 100644--- a/js/app/packages/service-clients/service-search/openapi.json+++ b/js/app/packages/service-clients/service-search/openapi.json@@ -472,7 +472,7 @@"ChannelSearchResponse": {"type": "object","description": "The document search response object",- "required": ["results"],+ "required": ["results", "total_count"],"properties": {"next_cursor": {"type": ["string", "null"],@@ -484,6 +484,11 @@"$ref": "#/components/schemas/ChannelSearchResponseItemWithMetadata"},"description": "List containing results from email threads"+ },+ "total_count": {+ "type": "integer",+ "format": "int64",+ "description": "Total number of matching channel messages across all pages."}}},diff --git a/rust/cloud-storage/models_search/src/channel.rs b/rust/cloud-storage/models_search/src/channel.rsindex bd4b0ca29e..9c6ebe489f 100644--- a/rust/cloud-storage/models_search/src/channel.rs+++ b/rust/cloud-storage/models_search/src/channel.rs@@ -115,6 +115,8 @@ pub struct ChannelSearchResponse {/// Base64-encoded cursor for the next page; `None` when exhausted.#[serde(skip_serializing_if = "Option::is_none")]pub next_cursor: Option<String>,+ /// Total number of matching channel messages across all pages.+ pub total_count: i64,}#[derive(Serialize, Deserialize, Debug, ToSchema, JsonSchema)]diff --git a/rust/cloud-storage/opensearch_client/src/channel_message.rs b/rust/cloud-storage/opensearch_client/src/channel_message.rsindex efbd10e782..28dbd93a4c 100644--- a/rust/cloud-storage/opensearch_client/src/channel_message.rs+++ b/rust/cloud-storage/opensearch_client/src/channel_message.rs@@ -1,18 +1,16 @@-use models_search_cursor::SearchCursorOption;-use crate::{OpensearchClient, Result, delete,- search::{self, channels::ChannelSearchArgs, model::SearchHit},+ search::{+ self,+ channels::{ChannelSearchArgs, ChannelSearchResults},+ },upsert::{self, channel_message::UpsertChannelMessageArgs},};impl OpensearchClient {/// Performs a channel content search.#[tracing::instrument(skip(self, args))]- pub async fn search_channel(- &self,- args: ChannelSearchArgs,- ) -> Result<(Vec<SearchHit>, SearchCursorOption)> {+ pub async fn search_channel(&self, args: ChannelSearchArgs) -> Result<ChannelSearchResults> {search::channels::search_channel(&self.inner, args).await}}diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 128d11aa67..3099d3083f 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -207,11 +207,17 @@ fn build_channel_search_request(Ok(request_builder.build())}+pub struct ChannelSearchResults {+ pub hits: Vec<SearchHit>,+ pub next_cursor: SearchCursorOption,+ pub total: i64,+}+#[tracing::instrument(skip(client, args), err)]pub(crate) async fn search_channel(client: &opensearch::OpenSearch,args: ChannelSearchArgs,-) -> Result<(Vec<SearchHit>, SearchCursorOption)> {+) -> Result<ChannelSearchResults> {let mut search_request = build_channel_search_request(&args)?.to_json();inject_fragment_size(&mut search_request, 1000);exclude_source_content(&mut search_request);@@ -246,20 +252,22 @@ pub(crate) async fn search_channel(raw_body: String::from_utf8_lossy(&bytes).to_string(),})?;- let mut results: Vec<SearchHit> = result+ let total = result.hits.total.value;++ let mut hits: Vec<SearchHit> = result.hits.hits.into_iter().map(channel_hit_to_search_hit).collect();- let has_more = results.len() > args.page_size as usize;+ let has_more = hits.len() > args.page_size as usize;if has_more {- results.pop();+ hits.pop();}- let cursor = if has_more {- let last_cursor = results+ let next_cursor = if has_more {+ let last_cursor = hits.last().and_then(|last| build_channel_cursor(last, args.sort_mode));SearchCursorOption::NotDone(last_cursor)@@ -267,7 +275,11 @@ pub(crate) async fn search_channel(SearchCursorOption::Done};- Ok((results, cursor))+ Ok(ChannelSearchResults {+ hits,+ next_cursor,+ total,+ })}fn channel_hit_to_search_hit(hit: Hit<ChannelMessageIndex>) -> SearchHit {diff --git a/rust/cloud-storage/search_service/src/api/search/channel.rs b/rust/cloud-storage/search_service/src/api/search/channel.rsindex 774583c101..de940db5ca 100644--- a/rust/cloud-storage/search_service/src/api/search/channel.rs+++ b/rust/cloud-storage/search_service/src/api/search/channel.rs@@ -245,7 +245,11 @@ pub async fn handler(sort_mode,};- let (hits, next_cursor) = ctx+ let opensearch_client::search::channels::ChannelSearchResults {+ hits,+ next_cursor,+ total: total_count,+ } = ctx.opensearch_client.search_channel(args).await@@ -261,6 +265,7 @@ pub async fn handler(Ok(Json(ChannelSearchResponse {results,next_cursor,+ total_count,}))}