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.

feat(search): sort on sent_at_seconds and updated_at_seconds before score (#623)

Will Hutchinson2c485e21755f
diff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rs
index bba3c00d4e..f819d3ca94 100644
--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs
@@ -459,8 +459,9 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchReques
// Build sort
let sort = vec![
+ SortType::Field(FieldSort::new("sent_at_seconds", SortOrder::Desc)),
+ SortType::Field(FieldSort::new("updated_at_seconds", SortOrder::Desc)),
SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),
- SortType::Field(FieldSort::new("entity_id", SortOrder::Desc)),
];
for sort in sort {
diff --git a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs
index 36a17fd6c9..13607247db 100644
--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs
@@ -398,6 +398,14 @@ fn test_deserialization() -> anyhow::Result<()> {
Ok(())
}
+fn expected_sort<'a>() -> Vec<SortType<'a>> {
+ vec![
+ SortType::Field(FieldSort::new("sent_at_seconds", SortOrder::Desc)),
+ SortType::Field(FieldSort::new("updated_at_seconds", SortOrder::Desc)),
+ SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),
+ ]
+}
+
#[test]
fn test_build_unified_search_request_content() -> anyhow::Result<()> {
let unified_search_args = UnifiedSearchArgs {
@@ -847,14 +855,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
}
},
"size": 20,
- "sort": [
- {
- "_score": "desc"
- },
- {
- "entity_id": "desc"
- }
- ]
+ "sort": expected_sort().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
});
assert_eq!(result.to_json(), expected);
@@ -1095,14 +1096,7 @@ fn test_build_unified_search_request_name() -> anyhow::Result<()> {
}
},
"size": 20,
- "sort": [
- {
- "_score": "desc"
- },
- {
- "entity_id": "desc"
- }
- ]
+ "sort": expected_sort().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
});
assert_eq!(result.to_json(), expected);
@@ -1810,14 +1804,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
}
},
"size": 20,
- "sort": [
- {
- "_score": "desc"
- },
- {
- "entity_id": "desc"
- }
- ]
+ "sort": expected_sort().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
});
assert_eq!(result.to_json(), expected);
@@ -1904,14 +1891,7 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {
},
"from": 20,
"size": 20,
- "sort": [
- {
- "_score": "desc"
- },
- {
- "entity_id": "desc"
- }
- ],
+ "sort": expected_sort().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
"highlight": {
"require_field_match": true,
"fields": {