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): restore DM priority in Quick Access (#6996)

dev-rb4c54787177a4
diff --git a/crates/client/cache-core/src/search.rs b/crates/client/cache-core/src/search.rs
index 71dd72234e..80afcac9fc 100644
--- a/crates/client/cache-core/src/search.rs
+++ b/crates/client/cache-core/src/search.rs
@@ -126,6 +126,8 @@ pub enum SearchError {
pub const MAX_SEARCH_LIMIT: usize = 500;
/// Maximum accepted query length in bytes.
pub const MAX_SEARCH_QUERY_BYTES: usize = 512;
+/// Restores the Quick Access preference for matching direct messages.
+const DM_SEARCH_BOOST: f64 = 1.8;
/// Validates and canonicalizes a request's buckets.
pub fn validate_search_request(request: &SearchRequest) -> Result<Vec<String>, SearchError> {
@@ -328,8 +330,8 @@ pub fn compare_recent(left: &SearchDocument, right: &SearchDocument) -> Ordering
}
/// Returns a fuzzy+freshness score, or `None` when every query token fails to
-/// match as an ordered subsequence. The weighting mirrors the existing Quick
-/// Access preference for fuzzy relevance (70%) plus freshness (30%).
+/// match as an ordered subsequence. Fuzzy relevance contributes 70%, freshness
+/// contributes 30%, and matching direct messages receive the legacy 1.8x boost.
pub fn fuzzy_freshness_score(document: &SearchDocument, query: &str, now_ms: i64) -> Option<f64> {
let normalized = normalize_search_text(query);
if normalized.is_empty() {
@@ -349,7 +351,12 @@ pub fn fuzzy_freshness_score(document: &SearchDocument, query: &str, now_ms: i64
} else {
(-0.5 * age / max_age).exp()
};
- Some(0.7 * fuzzy + 0.3 * freshness)
+ let score = 0.7 * fuzzy + 0.3 * freshness;
+ Some(if document.bucket == "dm" {
+ score * DM_SEARCH_BOOST
+ } else {
+ score
+ })
}
fn subsequence_score(haystack: &str, needle: &str) -> Option<f64> {
diff --git a/crates/client/cache-core/tests/search.rs b/crates/client/cache-core/tests/search.rs
index 6c1fcdd1c9..f35ec370e2 100644
--- a/crates/client/cache-core/tests/search.rs
+++ b/crates/client/cache-core/tests/search.rs
@@ -1,7 +1,7 @@
use cache_core::engine::{BeginOptimisticWrite, Engine};
use cache_core::search::{SearchCursor, SearchProfile, SearchRequest};
use cache_core::store::{InMemoryStorage, Storage};
-use cache_core::value::{CacheValue, EntityKey, Record};
+use cache_core::value::{CacheNumber, CacheValue, EntityKey, Record};
use pollster::block_on;
use serde_json::{Value as Json, json};
@@ -151,6 +151,61 @@ fn text_search_loads_compact_catalog_once_and_never_scans_records() {
});
}
+#[test]
+fn matching_dms_rank_above_documents_without_changing_recent_browse() {
+ block_on(async {
+ let mut storage = InMemoryStorage::new();
+ let entries = [
+ ("GraphqlSoupDocument", "doc-1", "Alex proposal", 1_000),
+ ("GraphqlSoupChannel", "dm-1", "Alex", 900),
+ ]
+ .map(|(typename, id, name, timestamp)| {
+ let mut record = Record::default();
+ record
+ .fields
+ .insert("__typename".into(), CacheValue::String(typename.into()));
+ record
+ .fields
+ .insert("name".into(), CacheValue::String(name.into()));
+ record.fields.insert(
+ "updatedAt".into(),
+ CacheValue::Number(CacheNumber::PosInt(timestamp)),
+ );
+ if typename == "GraphqlSoupChannel" {
+ record.fields.insert(
+ "channelType".into(),
+ CacheValue::String("direct_message".into()),
+ );
+ }
+ (EntityKey::entity(typename, &[id]), record)
+ });
+ storage.put_batch(entries.into()).await.unwrap();
+ let mut engine = Engine::new(storage);
+
+ let mut search = request("alex", 1);
+ search.buckets = vec!["document".into(), "dm".into()];
+ let matches = engine.search(&search).await.unwrap();
+ assert_eq!(
+ matches.documents[0].record_key.as_ref(),
+ "GraphqlSoupChannel:dm-1"
+ );
+
+ search.query = "proposal".into();
+ let matches = engine.search(&search).await.unwrap();
+ assert_eq!(
+ matches.documents[0].record_key.as_ref(),
+ "GraphqlSoupDocument:doc-1"
+ );
+
+ search.query.clear();
+ let recent = engine.search(&search).await.unwrap();
+ assert_eq!(
+ recent.documents[0].record_key.as_ref(),
+ "GraphqlSoupDocument:doc-1"
+ );
+ });
+}
+
#[test]
fn unnamed_notes_are_browsable_without_matching_ui_fallback_text() {
block_on(async {