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.

fix(search): filter noise emails from search results (#2534)

gbirmand11247ee37f1
diff --git a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts b/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts
index 2ac15be1a3..694150124a 100644
--- a/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts
+++ b/js/app/packages/app/component/app-sidebar/soup-filter-presets.ts
@@ -316,6 +316,7 @@ export const VIEW_TAB_PRESETS: Record<ListView, ViewTabConfig> = {
all: () => ({
queryFilters: {
...QUERY_FILTERS.default,
+ email_filters: { importance: true },
},
clientFilters: { and: [], or: [] },
}),
diff --git a/js/app/packages/app/component/next-soup/filters/query-filters.ts b/js/app/packages/app/component/next-soup/filters/query-filters.ts
index c8f6bd638b..28c651fea1 100644
--- a/js/app/packages/app/component/next-soup/filters/query-filters.ts
+++ b/js/app/packages/app/component/next-soup/filters/query-filters.ts
@@ -94,7 +94,7 @@ export const QUERY_FILTERS = {
chat_filters: { chat_ids: EXCLUDE },
document_filters: { document_ids: EXCLUDE },
project_filters: { project_ids: EXCLUDE },
- email_filters: {},
+ email_filters: { importance: true },
},
people: {
diff --git a/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
index 22cd07d0ef..fbcfb3f934 100644
--- a/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
+++ b/js/app/packages/app/component/next-soup/soup-view/filters-bar/search-filter-controls.tsx
@@ -15,9 +15,13 @@ import type { SoupBody } from '@queries/soup/items';
import { batch, createEffect, createMemo, Show } from 'solid-js';
import { FilterCombobox, FilterSelect, type Option } from './filter-primitives';
import type { FilterID } from '@app/component/next-soup/filters/configs';
-import type { ChannelFilters } from '@service-storage/generated/schemas';
+import type {
+ ChannelFilters,
+ EmailFilters,
+} from '@service-storage/generated/schemas';
type ChannelSubFilters = Pick<ChannelFilters, 'channel_ids' | 'sender_ids'>;
+type EmailSubFilters = Pick<EmailFilters, 'importance'>;
function getCachedChannelSubFilters(contentId: string): ChannelSubFilters {
if ((activeSoupViewCounts.get(contentId) ?? 0) > 1) return {};
@@ -43,6 +47,30 @@ function cacheChannelSubFilters(contentId: string, filters: ChannelSubFilters) {
}
}
+function getCachedEmailSubFilters(contentId: string): EmailSubFilters {
+ if ((activeSoupViewCounts.get(contentId) ?? 0) > 1) return {};
+ try {
+ const raw = localStorage.getItem(
+ soupViewCacheKey(contentId, 'email-sub-filters')
+ );
+ return raw ? JSON.parse(raw) : {};
+ } catch {
+ return {};
+ }
+}
+
+function cacheEmailSubFilters(contentId: string, filters: EmailSubFilters) {
+ if ((activeSoupViewCounts.get(contentId) ?? 0) > 1) return;
+ try {
+ localStorage.setItem(
+ soupViewCacheKey(contentId, 'email-sub-filters'),
+ JSON.stringify(filters)
+ );
+ } catch {
+ // best-effort
+ }
+}
+
export const INDEX_OPTIONS: (Option & { queryFilters: SoupBody })[] = [
{
value: 'channels',
@@ -106,6 +134,7 @@ export const SearchIndexFilter = () => {
const isChannelsActive = () =>
activeIndex().some((o) => o.value === 'channels');
+ const isEmailActive = () => activeIndex().some((o) => o.value === 'email');
createEffect(() => {
if (!isChannelsActive()) return;
@@ -116,6 +145,13 @@ export const SearchIndexFilter = () => {
cacheChannelSubFilters(contentId, sub);
});
+ createEffect(() => {
+ if (!isEmailActive()) return;
+ const ef = queryFilters().email_filters;
+ // Use null as sentinel for "explicitly cleared" since undefined is dropped by JSON.stringify
+ cacheEmailSubFilters(contentId, { importance: ef?.importance ?? null });
+ });
+
const handleChange = (selected: Option[]) => {
batch(() => {
for (const opt of INDEX_OPTIONS) {
@@ -137,6 +173,20 @@ export const SearchIndexFilter = () => {
...cached,
},
});
+ } else if (opt.value === 'email') {
+ const cached = getCachedEmailSubFilters(contentId);
+ // null in cache means "explicitly cleared" — convert to undefined to override the default
+ const importance =
+ 'importance' in cached
+ ? (cached.importance ?? undefined)
+ : opt.queryFilters.email_filters?.importance;
+ setQueryFilters({
+ ...opt.queryFilters,
+ email_filters: {
+ ...opt.queryFilters.email_filters,
+ importance,
+ },
+ });
} else {
setQueryFilters({
...opt.queryFilters,
@@ -146,6 +196,7 @@ export const SearchIndexFilter = () => {
} else {
setQueryFilters({
...QUERY_FILTERS.default,
+ email_filters: { importance: true },
});
}
});
@@ -153,7 +204,8 @@ export const SearchIndexFilter = () => {
const indexLabel = createMemo(() => {
const active = activeIndex();
- return active.length > 0 ? active[0].label : 'All';
+ const value = active.length > 0 ? active[0].label : 'All';
+ return `Type: ${value}`;
});
const hasActiveIndex = () => activeIndex().length > 0;
@@ -176,6 +228,9 @@ export const SearchIndexFilter = () => {
<InChannelFilter />
<FromSenderFilter />
</Show>
+ <Show when={isEmailActive()}>
+ <EmailImportanceFilter />
+ </Show>
<Show when={hasActiveIndex()}>
<button
type="button"
@@ -189,6 +244,53 @@ export const SearchIndexFilter = () => {
);
};
+const EMAIL_IMPORTANCE_OPTIONS: Option[] = [
+ { value: 'signal', label: 'Signal' },
+ { value: 'noise', label: 'Noise' },
+];
+
+function importanceToOption(importance: boolean | null | undefined): Option[] {
+ if (importance === true) return [EMAIL_IMPORTANCE_OPTIONS[0]];
+ if (importance === false) return [EMAIL_IMPORTANCE_OPTIONS[1]];
+ return [];
+}
+
+const EmailImportanceFilter = () => {
+ const { setQueryFilters, queryFilters } = useSoupView();
+
+ const active = createMemo(() =>
+ importanceToOption(queryFilters().email_filters?.importance)
+ );
+
+ const label = createMemo(() => {
+ const a = active();
+ const value = a.length > 0 ? a[0].label : 'All';
+ return `Importance: ${value}`;
+ });
+
+ const handleChange = (selected: Option[]) => {
+ const importance =
+ selected.length > 0 ? selected[0].value === 'signal' : undefined;
+ setQueryFilters((prev) => ({
+ ...prev,
+ email_filters: {
+ ...prev.email_filters,
+ importance,
+ },
+ }));
+ };
+
+ return (
+ <FilterSelect
+ label={label()}
+ options={EMAIL_IMPORTANCE_OPTIONS}
+ active={active()}
+ onChange={handleChange}
+ multiple={false}
+ />
+ );
+};
+
const InChannelFilter = () => {
const { setQueryFilters, queryFilters } = useSoupView();
const { useList } = useQuickAccess();
diff --git a/rust/cloud-storage/email_contact_search/.sqlx/query-e810dc79f4e3314d1879335813476bb5fbbd9217eda4c91f37a38eda6aec3a4e.json b/rust/cloud-storage/email_contact_search/.sqlx/query-e810dc79f4e3314d1879335813476bb5fbbd9217eda4c91f37a38eda6aec3a4e.json
deleted file mode 100644
index 8d995ef0b6..0000000000
--- a/rust/cloud-storage/email_contact_search/.sqlx/query-e810dc79f4e3314d1879335813476bb5fbbd9217eda4c91f37a38eda6aec3a4e.json
+++ /dev/null
@@ -1,32 +0,0 @@
-{
- "db_name": "PostgreSQL",
- "query": "\n SELECT t.id as \"thread_id!\", t.latest_non_spam_message_ts as \"updated_at!\"\n FROM email_threads t\n WHERE t.id IN (\n SELECT DISTINCT ecsi.thread_id\n FROM email_contact_search_index ecsi\n WHERE ecsi.link_id = (SELECT id FROM email_links WHERE macro_id = $1)\n AND (ecsi.contact_name ILIKE $2 OR ecsi.contact_email ILIKE $2)\n )\n AND t.latest_non_spam_message_ts IS NOT NULL\n AND (\n $4::timestamptz IS NULL\n OR (t.latest_non_spam_message_ts, t.id) < ($4, $5)\n )\n ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC\n LIMIT $3\n ",
- "describe": {
- "columns": [
- {
- "ordinal": 0,
- "name": "thread_id!",
- "type_info": "Uuid"
- },
- {
- "ordinal": 1,
- "name": "updated_at!",
- "type_info": "Timestamptz"
- }
- ],
- "parameters": {
- "Left": [
- "Text",
- "Text",
- "Int8",
- "Timestamptz",
- "Uuid"
- ]
- },
- "nullable": [
- false,
- true
- ]
- },
- "hash": "e810dc79f4e3314d1879335813476bb5fbbd9217eda4c91f37a38eda6aec3a4e"
-}
diff --git a/rust/cloud-storage/email_contact_search/.sqlx/query-eae7fe5dd206f2147ef8f9e7c38c3dd2cc18f500c92b8912c8ba1376fc302d16.json b/rust/cloud-storage/email_contact_search/.sqlx/query-eae7fe5dd206f2147ef8f9e7c38c3dd2cc18f500c92b8912c8ba1376fc302d16.json
new file mode 100644
index 0000000000..7ced9951e5
--- /dev/null
+++ b/rust/cloud-storage/email_contact_search/.sqlx/query-eae7fe5dd206f2147ef8f9e7c38c3dd2cc18f500c92b8912c8ba1376fc302d16.json
@@ -0,0 +1,33 @@
+{
+ "db_name": "PostgreSQL",
+ "query": "\n SELECT t.id as \"thread_id!\", t.latest_non_spam_message_ts as \"updated_at!\"\n FROM email_threads t\n WHERE t.id IN (\n SELECT DISTINCT ecsi.thread_id\n FROM email_contact_search_index ecsi\n WHERE ecsi.link_id = (SELECT id FROM email_links WHERE macro_id = $1)\n AND (ecsi.contact_name ILIKE $2 OR ecsi.contact_email ILIKE $2)\n )\n AND t.latest_non_spam_message_ts IS NOT NULL\n AND (\n $4::timestamptz IS NULL\n OR (t.latest_non_spam_message_ts, t.id) < ($4, $5)\n )\n AND (\n $6::bool IS NULL\n OR $6::bool = (NOT (\n EXISTS (\n SELECT 1 FROM email_messages em_dep\n JOIN email_message_labels ml_dep ON ml_dep.message_id = em_dep.id\n JOIN email_labels l_dep ON ml_dep.label_id = l_dep.id\n WHERE em_dep.thread_id = t.id\n AND l_dep.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')\n )\n AND NOT EXISTS (\n SELECT 1 FROM email_messages em_pri\n JOIN email_message_labels ml_pri ON ml_pri.message_id = em_pri.id\n JOIN email_labels l_pri ON ml_pri.label_id = l_pri.id\n WHERE em_pri.thread_id = t.id\n AND l_pri.name IN ('CATEGORY_PERSONAL', 'SENT', 'DRAFT')\n )\n ))\n )\n ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC\n LIMIT $3\n ",
+ "describe": {
+ "columns": [
+ {
+ "ordinal": 0,
+ "name": "thread_id!",
+ "type_info": "Uuid"
+ },
+ {
+ "ordinal": 1,
+ "name": "updated_at!",
+ "type_info": "Timestamptz"
+ }
+ ],
+ "parameters": {
+ "Left": [
+ "Text",
+ "Text",
+ "Int8",
+ "Timestamptz",
+ "Uuid",
+ "Bool"
+ ]
+ },
+ "nullable": [
+ false,
+ true
+ ]
+ },
+ "hash": "eae7fe5dd206f2147ef8f9e7c38c3dd2cc18f500c92b8912c8ba1376fc302d16"
+}
diff --git a/rust/cloud-storage/email_contact_search/src/lib.rs b/rust/cloud-storage/email_contact_search/src/lib.rs
index c5909c46d0..ea83843278 100644
--- a/rust/cloud-storage/email_contact_search/src/lib.rs
+++ b/rust/cloud-storage/email_contact_search/src/lib.rs
@@ -86,7 +86,7 @@ impl SearchCursorAttributes for ThreadPaginationEntry {
time = 30,
result = true,
key = "String",
- convert = r#"{ format!("{}-{}-{}-{}", macro_user_id.as_ref(), term, limit, cursor.as_ref().map(|c| format!("{}-{}", c.entity_id, c.updated_at)).unwrap_or_default()) }"#
+ convert = r#"{ format!("{}-{}-{}-{}-{:?}", macro_user_id.as_ref(), term, limit, cursor.as_ref().map(|c| format!("{}-{}", c.entity_id, c.updated_at)).unwrap_or_default(), importance) }"#
)
)]
pub async fn search_email_contacts<'a>(
@@ -95,6 +95,7 @@ pub async fn search_email_contacts<'a>(
term: String,
limit: u32,
cursor: Option<SearchMethodCursor>,
+ importance: Option<bool>,
) -> Result<PaginatedResult<EmailContactMatchThreadResult>, EmailContactSearchError> {
if term.is_empty() {
return Err(EmailContactSearchError::EmptySearchTerm);
@@ -128,6 +129,25 @@ pub async fn search_email_contacts<'a>(
$4::timestamptz IS NULL
OR (t.latest_non_spam_message_ts, t.id) < ($4, $5)
)
+ AND (
+ $6::bool IS NULL
+ OR $6::bool = (NOT (
+ EXISTS (
+ SELECT 1 FROM email_messages em_dep
+ JOIN email_message_labels ml_dep ON ml_dep.message_id = em_dep.id
+ JOIN email_labels l_dep ON ml_dep.label_id = l_dep.id
+ WHERE em_dep.thread_id = t.id
+ AND l_dep.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')
+ )
+ AND NOT EXISTS (
+ SELECT 1 FROM email_messages em_pri
+ JOIN email_message_labels ml_pri ON ml_pri.message_id = em_pri.id
+ JOIN email_labels l_pri ON ml_pri.label_id = l_pri.id
+ WHERE em_pri.thread_id = t.id
+ AND l_pri.name IN ('CATEGORY_PERSONAL', 'SENT', 'DRAFT')
+ )
+ ))
+ )
ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC
LIMIT $3
"#,
@@ -136,6 +156,7 @@ pub async fn search_email_contacts<'a>(
fetch_limit,
cursor_updated_at,
cursor_entity_id,
+ importance,
)
.fetch_all(db)
.await?;
diff --git a/rust/cloud-storage/email_contact_search/src/test.rs b/rust/cloud-storage/email_contact_search/src/test.rs
index ebce400083..09bd8fabd2 100644
--- a/rust/cloud-storage/email_contact_search/src/test.rs
+++ b/rust/cloud-storage/email_contact_search/src/test.rs
@@ -16,7 +16,7 @@ async fn test_search_email_contacts_empty_term(pool: Pool<Postgres>) -> anyhow::
.map(|l| l.lowercase())
.unwrap();
- let result = search_email_contacts(&pool, user_id, "".to_string(), 10, None).await;
+ let result = search_email_contacts(&pool, user_id, "".to_string(), 10, None, None).await;
assert!(result.is_err());
assert!(matches!(
@@ -39,7 +39,8 @@ async fn test_search_email_contacts_finds_sender_by_name(
.unwrap();
// Search for "Alice" - should find Thread 1 where Alice is the sender
- let response = search_email_contacts(&pool, user_id, "Alice".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "Alice".to_string(), 10, None, None).await?;
// Should find matches (Alice is sender in thread 1, recipient in threads 1 and 2)
assert!(!response.items.is_empty());
@@ -64,7 +65,7 @@ async fn test_search_email_contacts_finds_recipients(pool: Pool<Postgres>) -> an
.unwrap();
// Search for "Bob" - should find threads where Bob is a recipient
- let response = search_email_contacts(&pool, user_id, "Bob".to_string(), 10, None).await?;
+ let response = search_email_contacts(&pool, user_id, "Bob".to_string(), 10, None, None).await?;
assert!(!response.items.is_empty());
@@ -91,7 +92,8 @@ async fn test_search_email_contacts_finds_bcc_recipients(
.unwrap();
// Search for "David" - should find thread 2 where David is BCC
- let response = search_email_contacts(&pool, user_id, "David".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "David".to_string(), 10, None, None).await?;
assert!(!response.items.is_empty());
@@ -118,7 +120,8 @@ async fn test_search_email_contacts_sorted_by_latest_message(
.unwrap();
// Search for "Smith" - Alice Smith appears in multiple threads
- let response = search_email_contacts(&pool, user_id, "Smith".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "Smith".to_string(), 10, None, None).await?;
assert!(!response.items.is_empty());
@@ -146,11 +149,11 @@ async fn test_search_email_contacts_case_insensitive(pool: Pool<Postgres>) -> an
// Search with different cases
let response_lower =
- search_email_contacts(&pool, user_id.clone(), "alice".to_string(), 10, None).await?;
+ search_email_contacts(&pool, user_id.clone(), "alice".to_string(), 10, None, None).await?;
let response_upper =
- search_email_contacts(&pool, user_id.clone(), "ALICE".to_string(), 10, None).await?;
+ search_email_contacts(&pool, user_id.clone(), "ALICE".to_string(), 10, None, None).await?;
let response_mixed =
- search_email_contacts(&pool, user_id, "AlIcE".to_string(), 10, None).await?;
+ search_email_contacts(&pool, user_id, "AlIcE".to_string(), 10, None, None).await?;
// All should return the same number of results
assert_eq!(response_lower.items.len(), response_upper.items.len());
@@ -170,7 +173,8 @@ async fn test_search_email_contacts_partial_match(pool: Pool<Postgres>) -> anyho
.unwrap();
// Search for partial term "John" should match "Bob Johnson"
- let response = search_email_contacts(&pool, user_id, "John".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "John".to_string(), 10, None, None).await?;
assert!(!response.items.is_empty());
assert!(response.items.iter().any(|r| {
@@ -192,7 +196,7 @@ async fn test_search_email_contacts_pagination_limit(pool: Pool<Postgres>) -> an
.unwrap();
// Search with limit of 2 threads - may return multiple rows per thread (one per contact match)
- let response = search_email_contacts(&pool, user_id, "a".to_string(), 2, None).await?;
+ let response = search_email_contacts(&pool, user_id, "a".to_string(), 2, None, None).await?;
// Limit applies to threads, not rows - verify we get at most 2 unique threads
let unique_threads: std::collections::HashSet<_> =
@@ -216,7 +220,7 @@ async fn test_search_email_contacts_pagination_cursor(pool: Pool<Postgres>) -> a
// First page with limit of 2
let first_response =
- search_email_contacts(&pool, user_id.clone(), "a".to_string(), 2, None).await?;
+ search_email_contacts(&pool, user_id.clone(), "a".to_string(), 2, None, None).await?;
// Count unique threads in first page
let first_threads: std::collections::HashSet<_> =
@@ -232,7 +236,7 @@ async fn test_search_email_contacts_pagination_cursor(pool: Pool<Postgres>) -> a
// Second page using cursor
let second_response =
- search_email_contacts(&pool, user_id.clone(), "a".to_string(), 2, cursor).await?;
+ search_email_contacts(&pool, user_id.clone(), "a".to_string(), 2, cursor, None).await?;
// Count unique threads in second page
let second_threads: std::collections::HashSet<_> =
@@ -254,7 +258,8 @@ async fn test_search_email_contacts_user_isolation(pool: Pool<Postgres>) -> anyh
.unwrap();
// Search for "Frank" - Frank belongs to user2, not user1
- let response = search_email_contacts(&pool, user_id, "Frank".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "Frank".to_string(), 10, None, None).await?;
// Should return 0 results (Frank is not accessible to user1)
assert_eq!(response.items.len(), 0);
@@ -273,8 +278,15 @@ async fn test_search_email_contacts_no_results(pool: Pool<Postgres>) -> anyhow::
.unwrap();
// Search for a name that doesn't exist
- let response =
- search_email_contacts(&pool, user_id, "NonexistentPerson".to_string(), 10, None).await?;
+ let response = search_email_contacts(
+ &pool,
+ user_id,
+ "NonexistentPerson".to_string(),
+ 10,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(response.items.len(), 0);
assert!(response.cursor.is_done());
@@ -294,7 +306,8 @@ async fn test_search_email_contacts_includes_email_address(
.unwrap();
// Search for "Alice"
- let response = search_email_contacts(&pool, user_id, "Alice".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "Alice".to_string(), 10, None, None).await?;
assert!(!response.items.is_empty());
@@ -321,8 +334,15 @@ async fn test_search_email_contacts_uses_message_level_name_override(
.unwrap();
// Search for "Charles" - Thread 3 has from_name = "Charles B. Brown" which overrides contact name "Charlie Brown"
- let response =
- search_email_contacts(&pool, user_id.clone(), "Charles".to_string(), 10, None).await?;
+ let response = search_email_contacts(
+ &pool,
+ user_id.clone(),
+ "Charles".to_string(),
+ 10,
+ None,
+ None,
+ )
+ .await?;
// Should find the message with from_name override
let charles_match = response
@@ -353,7 +373,8 @@ async fn test_search_email_contacts_searches_both_from_name_and_contact_name(
// Search for "Charlie" - should find thread 3 because the contact name is "Charlie Brown"
// even though the from_name is "Charles B. Brown"
- let response = search_email_contacts(&pool, user_id, "Charlie".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "Charlie".to_string(), 10, None, None).await?;
// Should find thread 3's sender by searching the contact name
let charlie_from_match = response.items.iter().find(|r| {
@@ -383,7 +404,8 @@ async fn test_search_email_contacts_recipient_name_override(
.unwrap();
// Search for "Robert" - Thread 3 has recipient with name override "Robert J." for Bob Johnson
- let response = search_email_contacts(&pool, user_id, "Robert".to_string(), 10, None).await?;
+ let response =
+ search_email_contacts(&pool, user_id, "Robert".to_string(), 10, None, None).await?;
// Should find the recipient with name override
let robert_match = response
@@ -412,7 +434,8 @@ async fn test_search_email_contacts_pagination_by_thread(
// This ensures we have 2 threads to paginate over
// Get first thread (limit=1, cursor=None) - should be Thread 1 (most recent)
- let page1 = search_email_contacts(&pool, user_id.clone(), "Smith".to_string(), 1, None).await?;
+ let page1 =
+ search_email_contacts(&pool, user_id.clone(), "Smith".to_string(), 1, None, None).await?;
// All results on page 1 should be from Thread 1 (the most recent)
assert!(!page1.items.is_empty());
@@ -432,8 +455,15 @@ async fn test_search_email_contacts_pagination_by_thread(
};
// Get second thread using cursor - should be Thread 2 (second most recent)
- let page2 =
- search_email_contacts(&pool, user_id.clone(), "Smith".to_string(), 1, cursor1).await?;
+ let page2 = search_email_contacts(
+ &pool,
+ user_id.clone(),
+ "Smith".to_string(),
+ 1,
+ cursor1,
+ None,
+ )
+ .await?;
// All results on page 2 should be from Thread 2
assert!(!page2.items.is_empty());
@@ -464,8 +494,15 @@ async fn test_search_email_contacts_by_email_address(pool: Pool<Postgres>) -> an
.unwrap();
// Search for "bob.johnson" - should match [email protected]
- let response =
- search_email_contacts(&pool, user_id.clone(), "bob.johnson".to_string(), 10, None).await?;
+ let response = search_email_contacts(
+ &pool,
+ user_id.clone(),
+ "bob.johnson".to_string(),
+ 10,
+ None,
+ None,
+ )
+ .await?;
assert!(!response.items.is_empty());
@@ -478,7 +515,7 @@ async fn test_search_email_contacts_by_email_address(pool: Pool<Postgres>) -> an
// Search for partial email domain - should match all @example.com contacts
let domain_response =
- search_email_contacts(&pool, user_id, "@example.com".to_string(), 10, None).await?;
+ search_email_contacts(&pool, user_id, "@example.com".to_string(), 10, None, None).await?;
assert!(!domain_response.items.is_empty());
@@ -503,7 +540,7 @@ async fn test_search_email_contacts_cursor_tiebreak_on_identical_timestamps(
// Page 1: limit=1 should return thread 7
let page1 =
- search_email_contacts(&pool, user_id.clone(), "Taylor".to_string(), 1, None).await?;
+ search_email_contacts(&pool, user_id.clone(), "Taylor".to_string(), 1, None, None).await?;
let page1_thread_ids: Vec<_> = {
let mut seen = std::collections::HashSet::new();
@@ -523,7 +560,8 @@ async fn test_search_email_contacts_cursor_tiebreak_on_identical_timestamps(
SearchCursorOption::Done => panic!("Expected more results"),
};
- let page2 = search_email_contacts(&pool, user_id, "Taylor".to_string(), 1, cursor).await?;
+ let page2 =
+ search_email_contacts(&pool, user_id, "Taylor".to_string(), 1, cursor, None).await?;
let page2_thread_ids: Vec<_> = {
let mut seen = std::collections::HashSet::new();
diff --git a/rust/cloud-storage/name_search/.sqlx/query-c7561d429d5838d4af4740208dc0453028c8cb196e76544ceeddb0c8a4c7bbea.json b/rust/cloud-storage/name_search/.sqlx/query-0e403c8b2157afd77299829b8cdf94755523a26b5434b639bb8e42ecfa0441f2.json
similarity index 55%
rename from rust/cloud-storage/name_search/.sqlx/query-c7561d429d5838d4af4740208dc0453028c8cb196e76544ceeddb0c8a4c7bbea.json
rename to rust/cloud-storage/name_search/.sqlx/query-0e403c8b2157afd77299829b8cdf94755523a26b5434b639bb8e42ecfa0441f2.json
index 62a5665c93..607c6d8d85 100644
--- a/rust/cloud-storage/name_search/.sqlx/query-c7561d429d5838d4af4740208dc0453028c8cb196e76544ceeddb0c8a4c7bbea.json
+++ b/rust/cloud-storage/name_search/.sqlx/query-0e403c8b2157afd77299829b8cdf94755523a26b5434b639bb8e42ecfa0441f2.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH oldest_messages AS (\n SELECT DISTINCT ON (thread_id)\n thread_id,\n subject\n FROM email_messages\n WHERE thread_id = ANY($1)\n ORDER BY thread_id, internal_date_ts ASC\n )\n SELECT\n t.id as entity_id,\n om.subject as \"name!\",\n regexp_replace(\n om.subject,\n $6,\n '<macro_em>\\1</macro_em>',\n 'gi'\n ) as name_highlighted,\n t.latest_non_spam_message_ts as updated_at\n FROM email_threads t\n INNER JOIN oldest_messages om ON om.thread_id = t.id\n WHERE om.subject ILIKE $2\n AND (\n $4::timestamptz IS NULL\n OR (t.latest_non_spam_message_ts, t.id) < ($4, $5)\n )\n ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC\n LIMIT $3\n ",
+ "query": "\n WITH oldest_messages AS (\n SELECT DISTINCT ON (thread_id)\n thread_id,\n subject\n FROM email_messages\n WHERE thread_id = ANY($1)\n ORDER BY thread_id, internal_date_ts ASC\n )\n SELECT\n t.id as entity_id,\n om.subject as \"name!\",\n regexp_replace(\n om.subject,\n $6,\n '<macro_em>\\1</macro_em>',\n 'gi'\n ) as name_highlighted,\n t.latest_non_spam_message_ts as updated_at\n FROM email_threads t\n INNER JOIN oldest_messages om ON om.thread_id = t.id\n WHERE om.subject ILIKE $2\n AND (\n $4::timestamptz IS NULL\n OR (t.latest_non_spam_message_ts, t.id) < ($4, $5)\n )\n AND (\n $7::bool IS NULL\n OR $7::bool = (NOT (\n EXISTS (\n SELECT 1 FROM email_messages em_dep\n JOIN email_message_labels ml_dep ON ml_dep.message_id = em_dep.id\n JOIN email_labels l_dep ON ml_dep.label_id = l_dep.id\n WHERE em_dep.thread_id = t.id\n AND l_dep.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')\n )\n AND NOT EXISTS (\n SELECT 1 FROM email_messages em_pri\n JOIN email_message_labels ml_pri ON ml_pri.message_id = em_pri.id\n JOIN email_labels l_pri ON ml_pri.label_id = l_pri.id\n WHERE em_pri.thread_id = t.id\n AND l_pri.name IN ('CATEGORY_PERSONAL', 'SENT', 'DRAFT')\n )\n ))\n )\n ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC\n LIMIT $3\n ",
"describe": {
"columns": [
{
@@ -31,7 +31,8 @@
"Int8",
"Timestamptz",
"Uuid",
- "Text"
+ "Text",
+ "Bool"
]
},
"nullable": [
@@ -41,5 +42,5 @@
true
]
},
- "hash": "c7561d429d5838d4af4740208dc0453028c8cb196e76544ceeddb0c8a4c7bbea"
+ "hash": "0e403c8b2157afd77299829b8cdf94755523a26b5434b639bb8e42ecfa0441f2"
}
diff --git a/rust/cloud-storage/name_search/.sqlx/query-fa30f66ffec23b15ed938b6b3b8f8d5b57776d44c6c9528e2b686d3b6d660238.json b/rust/cloud-storage/name_search/.sqlx/query-2a2aeff74152cf2eaec9f76d9d6793697687c7ec622074bed484fd62fbd8fd57.json
similarity index 63%
rename from rust/cloud-storage/name_search/.sqlx/query-fa30f66ffec23b15ed938b6b3b8f8d5b57776d44c6c9528e2b686d3b6d660238.json
rename to rust/cloud-storage/name_search/.sqlx/query-2a2aeff74152cf2eaec9f76d9d6793697687c7ec622074bed484fd62fbd8fd57.json
index 4df9398fb5..03dfa800fe 100644
--- a/rust/cloud-storage/name_search/.sqlx/query-fa30f66ffec23b15ed938b6b3b8f8d5b57776d44c6c9528e2b686d3b6d660238.json
+++ b/rust/cloud-storage/name_search/.sqlx/query-2a2aeff74152cf2eaec9f76d9d6793697687c7ec622074bed484fd62fbd8fd57.json
@@ -1,6 +1,6 @@
{
"db_name": "PostgreSQL",
- "query": "\n WITH user_link_ids AS (\n SELECT id FROM email_links WHERE macro_id = $1\n ),\n matching_threads AS (\n SELECT DISTINCT thread_id\n FROM email_messages em\n WHERE em.link_id IN (SELECT id FROM user_link_ids)\n AND (thread_id = ANY($2) OR $3)\n AND em.subject ILIKE $4\n ),\n oldest_messages AS (\n SELECT DISTINCT ON (thread_id)\n thread_id,\n subject\n FROM email_messages\n WHERE thread_id IN (SELECT thread_id FROM matching_threads)\n ORDER BY thread_id, internal_date_ts ASC\n )\n SELECT\n t.id as entity_id,\n om.subject as \"name!\",\n regexp_replace(\n om.subject,\n $8,\n '<macro_em>\\1</macro_em>',\n 'gi'\n ) as name_highlighted,\n t.latest_non_spam_message_ts as updated_at\n FROM email_threads t\n INNER JOIN oldest_messages om ON om.thread_id = t.id\n WHERE t.link_id IN (SELECT id FROM user_link_ids)\n AND (\n $6::timestamptz IS NULL\n OR (t.latest_non_spam_message_ts, t.id) < ($6, $7)\n )\n ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC\n LIMIT $5\n ",
+ "query": "\n WITH user_link_ids AS (\n SELECT id FROM email_links WHERE macro_id = $1\n ),\n matching_threads AS (\n SELECT DISTINCT thread_id\n FROM email_messages em\n WHERE em.link_id IN (SELECT id FROM user_link_ids)\n AND (thread_id = ANY($2) OR $3)\n AND em.subject ILIKE $4\n ),\n oldest_messages AS (\n SELECT DISTINCT ON (thread_id)\n thread_id,\n subject\n FROM email_messages\n WHERE thread_id IN (SELECT thread_id FROM matching_threads)\n ORDER BY thread_id, internal_date_ts ASC\n )\n SELECT\n t.id as entity_id,\n om.subject as \"name!\",\n regexp_replace(\n om.subject,\n $8,\n '<macro_em>\\1</macro_em>',\n 'gi'\n ) as name_highlighted,\n t.latest_non_spam_message_ts as updated_at\n FROM email_threads t\n INNER JOIN oldest_messages om ON om.thread_id = t.id\n WHERE t.link_id IN (SELECT id FROM user_link_ids)\n AND (\n $6::timestamptz IS NULL\n OR (t.latest_non_spam_message_ts, t.id) < ($6, $7)\n )\n AND (\n $9::bool IS NULL\n OR $9::bool = (NOT (\n EXISTS (\n SELECT 1 FROM email_messages em_dep\n JOIN email_message_labels ml_dep ON ml_dep.message_id = em_dep.id\n JOIN email_labels l_dep ON ml_dep.label_id = l_dep.id\n WHERE em_dep.thread_id = t.id\n AND l_dep.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')\n )\n AND NOT EXISTS (\n SELECT 1 FROM email_messages em_pri\n JOIN email_message_labels ml_pri ON ml_pri.message_id = em_pri.id\n JOIN email_labels l_pri ON ml_pri.label_id = l_pri.id\n WHERE em_pri.thread_id = t.id\n AND l_pri.name IN ('CATEGORY_PERSONAL', 'SENT', 'DRAFT')\n )\n ))\n )\n ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC\n LIMIT $5\n ",
"describe": {
"columns": [
{
@@ -33,7 +33,8 @@
"Int8",
"Timestamptz",
"Uuid",
- "Text"
+ "Text",
+ "Bool"
]
},
"nullable": [
@@ -43,5 +44,5 @@
true
]
},
- "hash": "fa30f66ffec23b15ed938b6b3b8f8d5b57776d44c6c9528e2b686d3b6d660238"
+ "hash": "2a2aeff74152cf2eaec9f76d9d6793697687c7ec622074bed484fd62fbd8fd57"
}
diff --git a/rust/cloud-storage/name_search/src/email.rs b/rust/cloud-storage/name_search/src/email.rs
index 102f37bce6..27234431bb 100644
--- a/rust/cloud-storage/name_search/src/email.rs
+++ b/rust/cloud-storage/name_search/src/email.rs
@@ -16,6 +16,7 @@ async fn ids_search(
highlight_pattern: String,
limit: u32,
cursor: Option<SearchMethodCursor>,
+ importance: Option<bool>,
) -> Result<PaginatedResult<NameSearchResult>, NameSearchError> {
if thread_ids.is_empty() {
return Err(NameSearchError::EmptyIdsWithIdsOnly);
@@ -56,6 +57,25 @@ async fn ids_search(
$4::timestamptz IS NULL
OR (t.latest_non_spam_message_ts, t.id) < ($4, $5)
)
+ AND (
+ $7::bool IS NULL
+ OR $7::bool = (NOT (
+ EXISTS (
+ SELECT 1 FROM email_messages em_dep
+ JOIN email_message_labels ml_dep ON ml_dep.message_id = em_dep.id
+ JOIN email_labels l_dep ON ml_dep.label_id = l_dep.id
+ WHERE em_dep.thread_id = t.id
+ AND l_dep.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')
+ )
+ AND NOT EXISTS (
+ SELECT 1 FROM email_messages em_pri
+ JOIN email_message_labels ml_pri ON ml_pri.message_id = em_pri.id
+ JOIN email_labels l_pri ON ml_pri.label_id = l_pri.id
+ WHERE em_pri.thread_id = t.id
+ AND l_pri.name IN ('CATEGORY_PERSONAL', 'SENT', 'DRAFT')
+ )
+ ))
+ )
ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC
LIMIT $3
"#,
@@ -65,6 +85,7 @@ async fn ids_search(
cursor_updated_at,
cursor_entity_id,
highlight_pattern,
+ importance,
)
.fetch_all(db)
.await
@@ -94,6 +115,7 @@ async fn owner_search<'a>(
highlight_pattern: String,
limit: u32,
cursor: Option<SearchMethodCursor>,
+ importance: Option<bool>,
) -> Result<PaginatedResult<NameSearchResult>, NameSearchError> {
let (cursor_updated_at, cursor_entity_id) = cursor
.as_ref()
@@ -140,6 +162,25 @@ async fn owner_search<'a>(
$6::timestamptz IS NULL
OR (t.latest_non_spam_message_ts, t.id) < ($6, $7)
)
+ AND (
+ $9::bool IS NULL
+ OR $9::bool = (NOT (
+ EXISTS (
+ SELECT 1 FROM email_messages em_dep
+ JOIN email_message_labels ml_dep ON ml_dep.message_id = em_dep.id
+ JOIN email_labels l_dep ON ml_dep.label_id = l_dep.id
+ WHERE em_dep.thread_id = t.id
+ AND l_dep.name IN ('CATEGORY_UPDATES', 'CATEGORY_PROMOTIONS', 'CATEGORY_SOCIAL', 'CATEGORY_FORUMS')
+ )
+ AND NOT EXISTS (
+ SELECT 1 FROM email_messages em_pri
+ JOIN email_message_labels ml_pri ON ml_pri.message_id = em_pri.id
+ JOIN email_labels l_pri ON ml_pri.label_id = l_pri.id
+ WHERE em_pri.thread_id = t.id
+ AND l_pri.name IN ('CATEGORY_PERSONAL', 'SENT', 'DRAFT')
+ )
+ ))
+ )
ORDER BY t.latest_non_spam_message_ts DESC, t.id DESC
LIMIT $5
"#,
@@ -151,6 +192,7 @@ async fn owner_search<'a>(
cursor_updated_at,
cursor_entity_id,
highlight_pattern,
+ importance,
)
.fetch_all(db)
.await
@@ -179,7 +221,7 @@ async fn owner_search<'a>(
time = 30,
result = true,
key = "String",
- convert = r#"{ format!("{}-{:?}-{}-{}-{}-{}", macro_user_id.as_ref(), thread_ids, term, ids_only, limit, cursor.as_ref().map(|c| format!("{}-{}", c.entity_id, c.updated_at)).unwrap_or_default()) }"#
+ convert = r#"{ format!("{}-{:?}-{}-{}-{}-{}-{:?}", macro_user_id.as_ref(), thread_ids, term, ids_only, limit, cursor.as_ref().map(|c| format!("{}-{}", c.entity_id, c.updated_at)).unwrap_or_default(), importance) }"#
)
)]
pub async fn search_email_subjects<'a>(
@@ -190,6 +232,7 @@ pub async fn search_email_subjects<'a>(
ids_only: bool,
limit: u32,
cursor: Option<SearchMethodCursor>,
+ importance: Option<bool>,
) -> Result<PaginatedResult<NameSearchResult>, NameSearchError> {
if term.is_empty() {
return Err(NameSearchError::EmptySearchTerm);
@@ -206,6 +249,7 @@ pub async fn search_email_subjects<'a>(
highlight_pattern,
limit,
cursor,
+ importance,
)
.await
} else {
@@ -217,6 +261,7 @@ pub async fn search_email_subjects<'a>(
highlight_pattern,
limit,
cursor,
+ importance,
)
.await
}
diff --git a/rust/cloud-storage/name_search/src/email/test.rs b/rust/cloud-storage/name_search/src/email/test.rs
index 0b66a98cfe..1c1fdedfaa 100644
--- a/rust/cloud-storage/name_search/src/email/test.rs
+++ b/rust/cloud-storage/name_search/src/email/test.rs
@@ -16,7 +16,8 @@ async fn test_search_email_subjects_empty_term(pool: Pool<Postgres>) -> anyhow::
.map(|l| l.lowercase())
.unwrap();
- let result = search_email_subjects(&pool, &user_id, &[], "".to_string(), false, 10, None).await;
+ let result =
+ search_email_subjects(&pool, &user_id, &[], "".to_string(), false, 10, None, None).await;
assert!(result.is_err());
assert!(matches!(
@@ -38,8 +39,17 @@ async fn test_search_email_subjects_ids_only_with_empty_ids(
.map(|l| l.lowercase())
.unwrap();
- let result =
- search_email_subjects(&pool, &user_id, &[], "invoice".to_string(), true, 10, None).await;
+ let result = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "invoice".to_string(),
+ true,
+ 10,
+ None,
+ None,
+ )
+ .await;
assert!(result.is_err());
assert!(matches!(
@@ -74,6 +84,7 @@ async fn test_search_email_subjects_ids_only_mode(pool: Pool<Postgres>) -> anyho
true,
10,
None,
+ None,
)
.await?;
@@ -115,8 +126,17 @@ async fn test_search_email_subjects_normal_mode_owned_threads(
.unwrap();
// Search for "invoice" across all user1's email threads
- let response =
- search_email_subjects(&pool, &user_id, &[], "invoice".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "invoice".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
// Should return 3 threads matching "invoice" (2 with "invoice" + 1 with "INVOICE")
assert_eq!(response.items.len(), 3);
@@ -153,20 +173,47 @@ async fn test_search_email_subjects_case_insensitive(pool: Pool<Postgres>) -> an
.unwrap();
// Search with uppercase term should match both lowercase and uppercase subjects
- let response =
- search_email_subjects(&pool, &user_id, &[], "INVOICE".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "INVOICE".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(response.items.len(), 3);
// Search with lowercase term should also match both
- let response =
- search_email_subjects(&pool, &user_id, &[], "invoice".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "invoice".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(response.items.len(), 3);
// Search with mixed case
- let response =
- search_email_subjects(&pool, &user_id, &[], "InVoIcE".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "InVoIcE".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(response.items.len(), 3);
@@ -198,6 +245,7 @@ async fn test_search_email_subjects_with_shared_threads(
false,
10,
None,
+ None,
)
.await?;
@@ -218,8 +266,17 @@ async fn test_search_email_subjects_pagination_limit(pool: Pool<Postgres>) -> an
.unwrap();
// Search with limit of 2
- let response =
- search_email_subjects(&pool, &user_id, &[], "invoice".to_string(), false, 2, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "invoice".to_string(),
+ false,
+ 2,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(response.items.len(), 2);
@@ -249,8 +306,17 @@ async fn test_search_email_subjects_pagination_cursor(pool: Pool<Postgres>) -> a
.unwrap();
// First page with limit of 2
- let first_response =
- search_email_subjects(&pool, &user_id, &[], "invoice".to_string(), false, 2, None).await?;
+ let first_response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "invoice".to_string(),
+ false,
+ 2,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(first_response.items.len(), 2);
assert!(first_response.cursor.has_more());
@@ -270,6 +336,7 @@ async fn test_search_email_subjects_pagination_cursor(pool: Pool<Postgres>) -> a
false,
2,
cursor,
+ None,
)
.await?;
@@ -325,6 +392,7 @@ async fn test_search_email_subjects_no_results(pool: Pool<Postgres>) -> anyhow::
false,
10,
None,
+ None,
)
.await?;
@@ -344,8 +412,17 @@ async fn test_search_email_subjects_partial_match(pool: Pool<Postgres>) -> anyho
.unwrap();
// Search for partial term "meet" should match "meeting"
- let response =
- search_email_subjects(&pool, &user_id, &[], "meet".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "meet".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
assert_eq!(response.items.len(), 2);
assert_eq!(
@@ -379,8 +456,17 @@ async fn test_search_email_subjects_user_isolation(pool: Pool<Postgres>) -> anyh
.unwrap();
// Search for "User2" - user1 should not see user2's private email threads
- let response =
- search_email_subjects(&pool, &user_id, &[], "User2".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "User2".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
// Should return 0 results (user2's emails are not linked to user1)
assert_eq!(response.items.len(), 0);
@@ -413,6 +499,7 @@ async fn test_search_email_subjects_searches_oldest_message(
false,
10,
None,
+ None,
)
.await?;
@@ -431,6 +518,7 @@ async fn test_search_email_subjects_searches_oldest_message(
false,
10,
None,
+ None,
)
.await?;
@@ -455,8 +543,17 @@ async fn test_search_email_subjects_multiple_messages_per_thread(
.unwrap();
// Thread 11111111 has multiple messages - should return thread only once with oldest subject
- let response =
- search_email_subjects(&pool, &user_id, &[], "invoice".to_string(), false, 10, None).await?;
+ let response = search_email_subjects(
+ &pool,
+ &user_id,
+ &[],
+ "invoice".to_string(),
+ false,
+ 10,
+ None,
+ None,
+ )
+ .await?;
// Count how many times thread 11111111 appears (should be exactly once)
let count = response
diff --git a/rust/cloud-storage/name_search/src/lib.rs b/rust/cloud-storage/name_search/src/lib.rs
index 28d37551c3..9bc284584d 100644
--- a/rust/cloud-storage/name_search/src/lib.rs
+++ b/rust/cloud-storage/name_search/src/lib.rs
@@ -3,6 +3,7 @@
mod chat;
mod document;
+#[allow(clippy::too_many_arguments)]
mod email;
mod project;
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_email.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_email.rs
index e3bf62651a..1bb8e3b7d1 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_email.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_email.rs
@@ -9,6 +9,7 @@ use sqlx::{Pool, Postgres, types::Uuid};
pub(in crate::api::search) struct FilterEmailResponse {
pub thread_ids: Vec<String>,
pub ids_only: bool,
+ pub importance: Option<bool>,
}
/// Performs the name search over email subjects
@@ -43,6 +44,7 @@ pub(in crate::api::search::simple) async fn search_names<'a>(
filter_email_response.ids_only,
limit,
inner_cursor,
+ filter_email_response.importance,
)
.await
.map_err(SearchError::NameSearch)
@@ -76,6 +78,7 @@ pub(in crate::api::search::simple) async fn search_contacts<'a>(
term: String,
limit: u32,
cursor: models_search_cursor::SearchCursorOption,
+ importance: Option<bool>,
) -> Result<(Vec<SearchHit>, models_search_cursor::SearchCursorOption), SearchError> {
// If cursor is Done, no more results to fetch
let inner_cursor = match cursor {
@@ -85,7 +88,7 @@ pub(in crate::api::search::simple) async fn search_contacts<'a>(
models_search_cursor::SearchCursorOption::NotDone(c) => c,
};
- email_contact_search::search_email_contacts(db, user_id, term, limit, inner_cursor)
+ email_contact_search::search_email_contacts(db, user_id, term, limit, inner_cursor, importance)
.await
.map_err(SearchError::EmailContactSearch)
.map(|response| {
diff --git a/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs b/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs
index 473ec57eb4..eba86beaaa 100644
--- a/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs
+++ b/rust/cloud-storage/search_service/src/api/search/simple/simple_unified.rs
@@ -371,6 +371,7 @@ pub(in crate::api::search) async fn perform_unified_search(
&simple_email::FilterEmailResponse {
ids_only: false,
thread_ids: filter_email_response.thread_ids,
+ importance: filter_email_response.importance,
},
name_search_term.clone(),
page_size,
@@ -396,6 +397,7 @@ pub(in crate::api::search) async fn perform_unified_search(
name_search_term.clone(),
page_size,
email_contact_cursor_for_search,
+ filter_email_response.importance,
)
.await
}