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): search should include searching over participants and owner of items (#531)

Will Hutchinsonc8dd2d5c9a96
diff --git a/rust/cloud-storage/opensearch_client/src/search/builder.rs b/rust/cloud-storage/opensearch_client/src/search/builder.rs
index 6fdcf220ce..380bfd3622 100644
--- a/rust/cloud-storage/opensearch_client/src/search/builder.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/builder.rs
@@ -186,37 +186,90 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {
let content_bool_query = match self.search_on {
SearchOn::Name => None,
SearchOn::NameContent | SearchOn::Content => {
- let mut bool_query = BoolQueryBuilder::new();
+ let mut access_bool_query = BoolQueryBuilder::new();
// Currently, the minimum should match is always one.
// This should of the bool query contains the ids and potentially the user_id
- bool_query.minimum_should_match(1);
+ access_bool_query.minimum_should_match(1);
// For name OR content queries, we can build a much more simple bool query
let term_must_array: Vec<QueryType<'a>> =
self.build_must_term_query(SearchOn::Content)?;
- // For each item in term must array, add to bool must query
+ let mut inner_bool_query = BoolQueryBuilder::new();
+
+ inner_bool_query.minimum_should_match(1);
+
+ // Create a vec of owner queries for each term
+ // We want to search over the content **and** the owner here
+ let mut owner_queries: Vec<QueryType> = Vec::new();
+
+ for term in &self.terms {
+ let formatted_term = format!("*{}*", term);
+ owner_queries.push(QueryType::wildcard(T::USER_ID_KEY, formatted_term, true));
+ }
+
+ // Add the owner queries to the bool query
+ for owner_query in owner_queries {
+ inner_bool_query.should(owner_query);
+ }
+
+ // If the search is on email, we need to add in participants to the query as well
+ if T::ENTITY_INDEX == SearchEntityType::Emails {
+ let mut participant_queries: Vec<QueryType> = Vec::new();
+ for term in &self.terms {
+ let formatted_term = format!("*{}*", term);
+ participant_queries.push(QueryType::wildcard(
+ "sender",
+ formatted_term.clone(),
+ true,
+ ));
+ participant_queries.push(QueryType::wildcard(
+ "cc",
+ formatted_term.clone(),
+ true,
+ ));
+ participant_queries.push(QueryType::wildcard(
+ "bcc",
+ formatted_term.clone(),
+ true,
+ ));
+ participant_queries.push(QueryType::wildcard(
+ "recipients",
+ formatted_term.clone(),
+ true,
+ ));
+ }
+
+ for participant_query in participant_queries {
+ inner_bool_query.should(participant_query);
+ }
+ }
+
for must in term_must_array {
- bool_query.must(must);
+ inner_bool_query.should(must);
}
+ // Add in the inner bool query on content + owner to must of access bool query
+ access_bool_query.must(inner_bool_query.build().into());
+
// Add any ids to the should array if provided
if !self.ids.is_empty() {
- bool_query.should(QueryType::terms(T::ID_KEY.to_string(), self.ids.to_vec()));
+ access_bool_query
+ .should(QueryType::terms(T::ID_KEY.to_string(), self.ids.to_vec()));
}
// If we are not searching over the ids, we need to add the user_id to the should array
if !self.ids_only {
- bool_query.should(QueryType::term(
+ access_bool_query.should(QueryType::term(
T::USER_ID_KEY.to_string(),
self.user_id.clone(),
));
}
- bool_query.must(QueryType::term("_index", T::ENTITY_INDEX.as_ref()));
+ access_bool_query.must(QueryType::term("_index", T::ENTITY_INDEX.as_ref()));
- Some(bool_query)
+ Some(access_bool_query)
}
};
@@ -445,9 +498,6 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {
));
}
SearchOn::NameContent => unreachable!(),
- // SearchOn::NameContent => {
- // must_array.push(generate_name_content_query(&keys, &self.terms));
- // }
};
Ok(must_array)
diff --git a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs b/rust/cloud-storage/opensearch_client/src/search/builder/test.rs
index eb5d332f93..afd173b9a2 100644
--- a/rust/cloud-storage/opensearch_client/src/search/builder/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/builder/test.rs
@@ -191,11 +191,26 @@ fn test_build_bool_query() -> anyhow::Result<()> {
let expected = serde_json::json!({
"bool": {
"must": [
- {
- "match_phrase": {
- "content": "test"
- }
- },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "test_user_id": {
+ "value": "*test*",
+ "case_insensitive": true,
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ },
+ ],
+ }
+ },
{"term": {"_index": "documents"}},
],
"should": [
@@ -230,13 +245,28 @@ fn test_build_bool_query() -> anyhow::Result<()> {
let expected = serde_json::json!({
"bool": {
"must": [
- {
- "match_phrase_prefix": {
- "content": {
- "query": "test",
- }
- },
- },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "test_user_id": {
+ "value": "*test*",
+ "case_insensitive": true,
+ }
+ }
+ },
+ {
+ "match_phrase_prefix": {
+ "content": {
+ "query": "test",
+ }
+ }
+ },
+ ],
+ }
+ },
{"term": {"_index": "documents"}},
],
"should": [
@@ -252,74 +282,98 @@ fn test_build_bool_query() -> anyhow::Result<()> {
assert_eq!(query.build().to_json(), expected);
- // let builder = SearchQueryBuilder::<TestSearchConfig>::new(terms)
- // .match_type("partial")
- // .page_size(page_size)
- // .page(page)
- // .user_id(user_id)
- // .ids_only(true)
- // .search_on(SearchOn::NameContent)
- // .ids(ids.clone());
- //
- // let query = builder.build_bool_query(builder.build_content_and_name_bool_query()?)?;
- //
- // let expected = serde_json::json!({
- // "bool": {
- // "must": [
- // {
- // "bool": {
- // "minimum_should_match": 1,
- // "should": [
- // {
- // "match_phrase_prefix": {
- // "test_title": {
- // "boost": 1000.0,
- // "query": "test"
- // }
- // }
- // },
- // {
- // "match_phrase_prefix": {
- // "content": {
- // "boost": 900.0,
- // "query": "test"
- // }
- // }
- // },
- // {
- // "match": {
- // "test_title": {
- // "boost": 0.1,
- // "minimum_should_match": "80%",
- // "query": "test"
- // }
- // }
- // },
- // {
- // "match": {
- // "content": {
- // "boost": 0.09,
- // "minimum_should_match": "1",
- // "query": "test"
- // }
- // }
- // }
- // ]
- // }
- // }
- // ],
- // "should": [
- // {
- // "terms": {
- // "entity_id": ["id1", "id2"]
- // }
- // },
- // ],
- // "minimum_should_match": 1,
- // }
- // });
- //
- // assert_eq!(query.build().to_json(), expected);
+ let builder = SearchQueryBuilder::<TestSearchConfig>::new(terms)
+ .match_type("partial")
+ .page_size(page_size)
+ .page(page)
+ .user_id(user_id)
+ .ids_only(true)
+ .search_on(SearchOn::NameContent)
+ .ids(ids.clone());
+
+ let query = builder.build_bool_query(builder.build_content_and_name_bool_query()?)?;
+
+ let expected = serde_json::json!({
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "must": [
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "test_user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase_prefix": {
+ "content": {
+ "query": "test"
+ }
+ }
+ }
+ ]
+ }
+ },
+ {
+ "term": {
+ "_index": "documents"
+ }
+ }
+ ],
+ "should": [
+ {
+ "terms": {
+ "entity_id": ["id1", "id2"]
+ }
+ }
+ ]
+ }
+ },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "must": [
+ {
+ "match_phrase_prefix": {
+ "test_title": {
+ "query": "test"
+ }
+ }
+ },
+ {
+ "term": {
+ "_index": "names"
+ }
+ },
+ {
+ "term": {
+ "entity_type": "documents"
+ }
+ }
+ ],
+ "should": [
+ {
+ "terms": {
+ "entity_id": ["id1", "id2"]
+ }
+ }
+ ]
+ }
+ }
+ ]
+ }
+ });
+
+ assert_eq!(query.build().to_json(), expected);
Ok(())
}
diff --git a/rust/cloud-storage/opensearch_client/src/search/channels/test.rs b/rust/cloud-storage/opensearch_client/src/search/channels/test.rs
index 5599702c7d..536f17d91e 100644
--- a/rust/cloud-storage/opensearch_client/src/search/channels/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/channels/test.rs
@@ -18,53 +18,92 @@ fn test_build_search_request() -> anyhow::Result<()> {
let result = builder.build_search_request()?;
let expected = serde_json::json!({
- "from": 20,
- "size": 20,
- "collapse": {
- "field": "entity_id"
+ "collapse": {
+ "field": "entity_id"
+ },
+ "from": 20,
+ "highlight": {
+ "fields": {
+ "content": {
+ "number_of_fragments": 500,
+ "post_tags": ["</macro_em>"],
+ "pre_tags": ["<macro_em>"],
+ "type": "plain"
+ }
},
- "sort": ChannelMessageSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
- "highlight": ChannelMessageSearchConfig::default_highlight().to_json(),
- "query": {
- "bool": {
- "must": [
- {
- "match_phrase": {
- "content": "test"
- }
- },
- {"term": {"_index": "channels"}},
- {
- "terms": {
- "thread_id": ["thread1", "thread2"]
- }
- },
- {
- "terms": {
- "mentions": ["mention1", "mention2"]
- }
- },
- {
- "terms": {
- "sender_id": ["sender1", "sender2"]
- },
- },
- ],
+ "require_field_match": true
+ },
+ "query": {
+ "bool": {
+ "minimum_should_match": 1,
+ "must": [
+ {
+ "bool": {
+ "minimum_should_match": 1,
"should": [
- {
- "terms": {
- "entity_id": ["id1", "id2"]
- }
- },
- {
- "term": {
- "sender_id": "user123"
- }
+ {
+ "wildcard": {
+ "sender_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
}
- ],
- "minimum_should_match": 1,
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
+ }
+ },
+ {
+ "term": {
+ "_index": "channels"
+ }
+ },
+ {
+ "terms": {
+ "thread_id": ["thread1", "thread2"]
+ }
+ },
+ {
+ "terms": {
+ "mentions": ["mention1", "mention2"]
+ }
+ },
+ {
+ "terms": {
+ "sender_id": ["sender1", "sender2"]
+ }
+ }
+ ],
+ "should": [
+ {
+ "terms": {
+ "entity_id": ["id1", "id2"]
+ }
+ },
+ {
+ "term": {
+ "sender_id": "user123"
+ }
}
+ ]
+ }
+ },
+ "size": 20,
+ "sort": [
+ {
+ "_score": "desc"
+ },
+ {
+ "entity_id": "asc"
+ },
+ {
+ "message_id": "asc"
}
+ ]
});
assert_eq!(result.to_json(), expected);
diff --git a/rust/cloud-storage/opensearch_client/src/search/chats/test.rs b/rust/cloud-storage/opensearch_client/src/search/chats/test.rs
index eea4c5bd0f..a5c70a83ff 100644
--- a/rust/cloud-storage/opensearch_client/src/search/chats/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/chats/test.rs
@@ -26,11 +26,26 @@ fn test_build_search_request() -> anyhow::Result<()> {
"query": {
"bool": {
"must": [
- {
- "match_phrase": {
- "content": "test"
- }
- },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "value": "*test*",
+ "case_insensitive": true,
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
+ }
+ },
{"term": {"_index": "chats"}},
{
"bool": {
diff --git a/rust/cloud-storage/opensearch_client/src/search/documents/test.rs b/rust/cloud-storage/opensearch_client/src/search/documents/test.rs
index 4cc35a838d..76f0a976bf 100644
--- a/rust/cloud-storage/opensearch_client/src/search/documents/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/documents/test.rs
@@ -26,8 +26,23 @@ fn test_build_search_request() -> anyhow::Result<()> {
"bool": {
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "owner_id": {
+ "value": "*test*",
+ "case_insensitive": true,
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{"term": {"_index": "documents"}},
diff --git a/rust/cloud-storage/opensearch_client/src/search/emails/test.rs b/rust/cloud-storage/opensearch_client/src/search/emails/test.rs
index e7ad6154c4..5e265ae022 100644
--- a/rust/cloud-storage/opensearch_client/src/search/emails/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/emails/test.rs
@@ -20,104 +20,155 @@ fn test_build_search_request() -> anyhow::Result<()> {
let result = builder.build_search_request()?;
let expected = serde_json::json!({
- "from": 20,
- "size": 20,
- "collapse": {
- "field": "entity_id"
- },
- "sort": EmailSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
- "highlight": EmailSearchConfig::default_highlight().to_json(),
- "query": {
+ "from": 20,
+ "size": 20,
+ "collapse": {
+ "field": "entity_id"
+ },
+ "sort": EmailSearchConfig::default_sort_types().iter().map(|s| s.to_json()).collect::<Vec<_>>(),
+ "highlight": EmailSearchConfig::default_highlight().to_json(),
+ "query": {
+ "bool": {
+ "minimum_should_match": 1,
+ "must": [
+ {
"bool": {
- "minimum_should_match": 1,
- "must": [
- {
- "match_phrase": {
- "content": "test"
- }
- },
- {"term": {"_index": "emails"}},
- {
- "terms": {
- "link_id": ["link1", "link2"]
- }
- },
- {
- "bool": {
- "minimum_should_match": 1,
- "should": [
- {
- "wildcard": {
- "sender": {
- "case_insensitive": true,
- "value": "*[email protected]*"
- }
- }
- }
- ]
- }
- },
- {
- "bool": {
- "minimum_should_match": 1,
- "should": [
- {
- "wildcard": {
- "cc": {
- "case_insensitive": true,
- "value": "*[email protected]*"
- }
- }
- }
- ]
- }
- },
- {
- "bool": {
- "minimum_should_match": 1,
- "should": [
- {
- "wildcard": {
- "bcc": {
- "case_insensitive": true,
- "value": "*[email protected]*"
- }
- }
- }
- ]
- }
- },
- {
- "bool": {
- "minimum_should_match": 1,
- "should": [
- {
- "wildcard": {
- "recipients": {
- "case_insensitive": true,
- "value": "*[email protected]*"
- }
- }
- }
- ]
- }
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
}
- ],
- "should": [
- {
- "terms": {
- "entity_id": ["thread1", "thread2"]
- }
- },
- {
- "term": {
- "user_id": "user123"
- }
+ }
+ },
+ {
+ "wildcard": {
+ "sender": {
+ "case_insensitive": true,
+ "value": "*test*"
}
- ]
+ }
+ },
+ {
+ "wildcard": {
+ "cc": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "bcc": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "recipients": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
+ }
+ },
+ {
+ "term": {
+ "_index": "emails"
+ }
+ },
+ {
+ "terms": {
+ "link_id": ["link1", "link2"]
+ }
+ },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "sender": {
+ "case_insensitive": true,
+ "value": "*[email protected]*"
+ }
+ }
+ }
+ ]
+ }
+ },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "cc": {
+ "case_insensitive": true,
+ "value": "*[email protected]*"
+ }
+ }
+ }
+ ]
+ }
+ },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "bcc": {
+ "case_insensitive": true,
+ "value": "*[email protected]*"
+ }
+ }
+ }
+ ]
+ }
+ },
+ {
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "recipients": {
+ "case_insensitive": true,
+ "value": "*[email protected]*"
+ }
+ }
+ }
+ ]
+ }
+ }
+ ],
+ "should": [
+ {
+ "terms": {
+ "entity_id": ["thread1", "thread2"]
+ }
+ },
+ {
+ "term": {
+ "user_id": "user123"
}
- }
- });
+ }
+ ]
+ }
+ },
+ });
assert_eq!(result.to_json(), expected);
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 8c7ea59555..113f877081 100644
--- a/rust/cloud-storage/opensearch_client/src/search/unified/test.rs
+++ b/rust/cloud-storage/opensearch_client/src/search/unified/test.rs
@@ -450,7 +450,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
let result = build_unified_search_request(&unified_search_args)?;
let expected = serde_json::json!(
- {
+ {
"collapse": {
"field": "entity_id"
},
@@ -459,12 +459,8 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"fields": {
"content": {
"number_of_fragments": 500,
- "post_tags": [
- "</macro_em>"
- ],
- "pre_tags": [
- "<macro_em>"
- ],
+ "post_tags": ["</macro_em>"],
+ "pre_tags": ["<macro_em>"],
"type": "plain"
}
},
@@ -479,8 +475,23 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "owner_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -492,10 +503,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"should": [
{
"terms": {
- "entity_id": [
- "id1",
- "id2"
- ]
+ "entity_id": ["id1", "id2"]
}
},
{
@@ -511,8 +519,55 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "sender": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "cc": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "bcc": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "recipients": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -522,10 +577,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
},
{
"terms": {
- "link_id": [
- "id1",
- "id2"
- ]
+ "link_id": ["id1", "id2"]
}
},
{
@@ -624,10 +676,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"should": [
{
"terms": {
- "entity_id": [
- "id1",
- "id2"
- ]
+ "entity_id": ["id1", "id2"]
}
},
{
@@ -643,8 +692,23 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "sender_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -654,36 +718,24 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
},
{
"terms": {
- "thread_id": [
- "id1",
- "id2"
- ]
+ "thread_id": ["id1", "id2"]
}
},
{
"terms": {
- "mentions": [
- "id1",
- "id2"
- ]
+ "mentions": ["id1", "id2"]
}
},
{
"terms": {
- "sender_id": [
- "id1",
- "id2"
- ]
+ "sender_id": ["id1", "id2"]
}
}
],
"should": [
{
"terms": {
- "entity_id": [
- "id1",
- "id2"
- ]
+ "entity_id": ["id1", "id2"]
}
}
]
@@ -694,8 +746,23 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -730,10 +797,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
"should": [
{
"terms": {
- "entity_id": [
- "id1",
- "id2"
- ]
+ "entity_id": ["id1", "id2"]
}
},
{
@@ -743,7 +807,7 @@ fn test_build_unified_search_request_content() -> anyhow::Result<()> {
}
]
}
- },
+ }
]
}
},
@@ -1063,46 +1127,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
let result = build_unified_search_request(&unified_search_args)?;
let expected = serde_json::json!(
- {
- "collapse": {
- "field": "entity_id"
- },
- "from": 20,
- "highlight": {
- "fields": {
- "content": {
- "number_of_fragments": 1,
- "post_tags": [
- "</macro_em>"
- ],
- "pre_tags": [
- "<macro_em>"
- ],
- "type": "plain"
- },
- "name": {
- "number_of_fragments": 1,
- "post_tags": [
- "</macro_em>"
- ],
- "pre_tags": [
- "<macro_em>"
- ],
- "type": "plain"
- },
- "project_name": {
- "number_of_fragments": 1,
- "post_tags": [
- "</macro_em>"
- ],
- "pre_tags": [
- "<macro_em>"
- ],
- "type": "plain"
- }
- },
- "require_field_match": false
- },
+ {
"query": {
"bool": {
"minimum_should_match": 1,
@@ -1116,8 +1141,23 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "owner_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -1192,8 +1232,55 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "sender": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "cc": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "bcc": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "wildcard": {
+ "recipients": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -1368,8 +1455,23 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "sender_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -1458,8 +1560,23 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -1557,8 +1674,23 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "user_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -1622,6 +1754,7 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
]
}
},
+ "from": 20,
"size": 20,
"sort": [
{
@@ -1630,8 +1763,47 @@ fn test_build_unified_search_request_name_content() -> anyhow::Result<()> {
{
"entity_id": "desc"
}
- ]
- });
+ ],
+ "highlight": {
+ "require_field_match": false,
+ "fields": {
+ "content": {
+ "type": "plain",
+ "number_of_fragments": 1,
+ "pre_tags": [
+ "<macro_em>"
+ ],
+ "post_tags": [
+ "</macro_em>"
+ ]
+ },
+ "name": {
+ "type": "plain",
+ "number_of_fragments": 1,
+ "pre_tags": [
+ "<macro_em>"
+ ],
+ "post_tags": [
+ "</macro_em>"
+ ]
+ },
+ "project_name": {
+ "type": "plain",
+ "number_of_fragments": 1,
+ "pre_tags": [
+ "<macro_em>"
+ ],
+ "post_tags": [
+ "</macro_em>"
+ ]
+ }
+ }
+ },
+ "collapse": {
+ "field": "entity_id"
+ }
+ }
+ );
assert_eq!(result.to_json(), expected);
@@ -1658,26 +1830,8 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {
};
let result = build_unified_search_request(&unified_search_args)?;
- let expected = serde_json::json!({
- "collapse": {
- "field": "entity_id"
- },
- "from": 20,
- "highlight": {
- "fields": {
- "content": {
- "number_of_fragments": 500,
- "post_tags": [
- "</macro_em>"
- ],
- "pre_tags": [
- "<macro_em>"
- ],
- "type": "plain"
- }
- },
- "require_field_match": true
- },
+ let expected = serde_json::json!(
+ {
"query": {
"bool": {
"minimum_should_match": 1,
@@ -1687,8 +1841,23 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {
"minimum_should_match": 1,
"must": [
{
- "match_phrase": {
- "content": "test"
+ "bool": {
+ "minimum_should_match": 1,
+ "should": [
+ {
+ "wildcard": {
+ "owner_id": {
+ "case_insensitive": true,
+ "value": "*test*"
+ }
+ }
+ },
+ {
+ "match_phrase": {
+ "content": "test"
+ }
+ }
+ ]
}
},
{
@@ -1713,10 +1882,11 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {
}
]
}
- },
+ }
]
}
},
+ "from": 20,
"size": 20,
"sort": [
{
@@ -1725,8 +1895,27 @@ fn test_build_unified_search_request_single_index() -> anyhow::Result<()> {
{
"entity_id": "desc"
}
- ]
- });
+ ],
+ "highlight": {
+ "require_field_match": true,
+ "fields": {
+ "content": {
+ "type": "plain",
+ "number_of_fragments": 500,
+ "pre_tags": [
+ "<macro_em>"
+ ],
+ "post_tags": [
+ "</macro_em>"
+ ]
+ }
+ }
+ },
+ "collapse": {
+ "field": "entity_id"
+ }
+ }
+ );
assert_eq!(result.to_json(), expected);