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
chore(opensearch_client): bump opensearch_query_builder to v0.2.1 (#259)
Will Hutchinson348b6da25952
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lockindex 626f714b3f..c214043045 100644--- a/rust/cloud-storage/Cargo.lock+++ b/rust/cloud-storage/Cargo.lock@@ -5756,9 +5756,9 @@ dependencies = [[[package]]name = "opensearch_query_builder"-version = "0.1.0"+version = "0.2.1"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "2729a66d99a0d14cbda2d04888b5315c2312980558021e924a1a4690fdaa36b0"+checksum = "fad14f01f6fddacf5c28f40c08384e206f68ecb135e253b01bcb5fd3af531472"dependencies = ["serde","serde_json",diff --git a/rust/cloud-storage/opensearch_client/Cargo.toml b/rust/cloud-storage/opensearch_client/Cargo.tomlindex e1286b8788..4ce21c6329 100644--- a/rust/cloud-storage/opensearch_client/Cargo.toml+++ b/rust/cloud-storage/opensearch_client/Cargo.toml@@ -15,7 +15,7 @@ uuid = { workspace = true }[dependencies]anyhow = { workspace = true }opensearch = { version = "2.3.0" }-opensearch_query_builder = { version = "0.1.0", default-features = false }+opensearch_query_builder = { version = "0.2.1", default-features = false }serde = { workspace = true }serde_json = { workspace = true }thiserror = { workspace = true }diff --git a/rust/cloud-storage/opensearch_client/src/search/builder.rs b/rust/cloud-storage/opensearch_client/src/search/builder.rsindex 67e637dd4f..ba7a82ba83 100644--- a/rust/cloud-storage/opensearch_client/src/search/builder.rs+++ b/rust/cloud-storage/opensearch_client/src/search/builder.rs@@ -58,7 +58,7 @@ pub trait SearchQueryConfig {/// Returns the default sort types that are used on the search query./// Override this method if you need custom sort logic- fn default_sort_types() -> Vec<SortType> {+ fn default_sort_types() -> Vec<SortType<'static>> {vec![SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),SortType::Field(FieldSort::new(Self::ID_KEY, SortOrder::Asc)),@@ -66,7 +66,7 @@ pub trait SearchQueryConfig {}/// Override this method if you need custom highlight logic- fn default_highlight() -> Highlight {+ fn default_highlight() -> Highlight<'static> {Highlight::new().require_field_match(true).field("content",HighlightField::new()@@ -173,14 +173,14 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {}/// Builds the core bool query which contains all core "should" and "must" clauses- pub fn build_bool_query(&self) -> Result<BoolQueryBuilder> {+ pub fn build_bool_query(&self) -> Result<BoolQueryBuilder<'static>> {let mut 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_idbool_query.minimum_should_match(1);- let term_must_array: Vec<QueryType> = self.build_must_term_query()?;+ let term_must_array: Vec<QueryType<'static>> = self.build_must_term_query()?;tracing::trace!("term_must_array: {:?}", term_must_array);@@ -191,12 +191,15 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {// Add any ids to the should array if providedif !self.ids.is_empty() {- bool_query.should(QueryType::terms(T::ID_KEY, self.ids.to_vec()));+ 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 arrayif !self.ids_only {- bool_query.should(QueryType::term(T::USER_ID_KEY, self.user_id.clone()));+ bool_query.should(QueryType::term(+ T::USER_ID_KEY.to_string(),+ self.user_id.clone(),+ ));}Ok(bool_query)@@ -205,7 +208,10 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {/// Builds the search request with the provided main bool query/// This will automatically wrap the bool query in a function score if/// SearchOn::NameContent is used- pub fn build_search_request(&self, query_object: BoolQuery) -> Result<SearchRequest> {+ pub fn build_search_request(+ &self,+ query_object: BoolQuery<'static>,+ ) -> Result<SearchRequest<'static>> {let mut search_request = SearchRequestBuilder::new();// Collapse on the ID_KEY if collapse is true@@ -248,7 +254,7 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {};search_request.highlight(highlight);- search_request.set_sorts(T::default_sort_types());+ search_request.set_sorts(T::default_sort_types().into());search_request.from(self.page * self.page_size);search_request.size(self.page_size);@@ -265,10 +271,10 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {function_score_query.function(ScoreFunction {function: ScoreFunctionType::Gauss(DecayFunction {- field: "updated_at_seconds".to_string(),+ field: "updated_at_seconds".into(),origin: Some("now".into()),- scale: "21d".to_string(),- offset: Some("3d".to_string()),+ scale: "21d".into(),+ offset: Some("3d".into()),decay: Some(0.5),}),filter: None,@@ -298,7 +304,7 @@ impl<T: SearchQueryConfig> SearchQueryBuilder<T> {}/// Generates a vec of term queries to be put inside of the bool must query- pub fn build_must_term_query(&self) -> Result<Vec<QueryType>> {+ pub fn build_must_term_query(&self) -> Result<Vec<QueryType<'static>>> {let keys = Keys {title_key: T::TITLE_KEY,content_key: T::CONTENT_KEY,diff --git a/rust/cloud-storage/opensearch_client/src/search/channels.rs b/rust/cloud-storage/opensearch_client/src/search/channels.rsindex 57f03c3bef..41284ed86b 100644--- a/rust/cloud-storage/opensearch_client/src/search/channels.rs+++ b/rust/cloud-storage/opensearch_client/src/search/channels.rs@@ -56,7 +56,7 @@ impl SearchQueryConfig for ChannelMessageSearchConfig {const USER_ID_KEY: &'static str = "sender_id";const TITLE_KEY: &'static str = "channel_name";- fn default_sort_types() -> Vec<SortType> {+ fn default_sort_types() -> Vec<SortType<'static>> {vec![SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),SortType::Field(FieldSort::new(Self::ID_KEY, SortOrder::Asc)),@@ -110,7 +110,7 @@ impl ChannelMessageQueryBuilder {}/// Builds the main bool query for the index- pub fn build_bool_query(&self) -> Result<BoolQueryBuilder> {+ pub fn build_bool_query(&self) -> Result<BoolQueryBuilder<'static>> {// Build the main bool query containing all terms and any other filterslet mut bool_query = self.inner.build_bool_query()?;@@ -135,7 +135,7 @@ impl ChannelMessageQueryBuilder {Ok(bool_query)}- fn build_search_request(&self) -> Result<SearchRequest> {+ fn build_search_request(&self) -> Result<SearchRequest<'static>> {let bool_query = self.build_bool_query()?;// Build the search request with the bool querydiff --git a/rust/cloud-storage/opensearch_client/src/search/chats.rs b/rust/cloud-storage/opensearch_client/src/search/chats.rsindex f8d0519460..a26c689437 100644--- a/rust/cloud-storage/opensearch_client/src/search/chats.rs+++ b/rust/cloud-storage/opensearch_client/src/search/chats.rs@@ -46,7 +46,7 @@ impl SearchQueryConfig for ChatSearchConfig {const USER_ID_KEY: &'static str = "user_id";const TITLE_KEY: &'static str = "title";- fn default_sort_types() -> Vec<SortType> {+ fn default_sort_types() -> Vec<SortType<'static>> {vec![SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),SortType::Field(FieldSort::new(Self::ID_KEY, SortOrder::Asc)),@@ -87,7 +87,7 @@ impl ChatQueryBuilder {self}- pub fn build_bool_query(&self) -> Result<BoolQueryBuilder> {+ pub fn build_bool_query(&self) -> Result<BoolQueryBuilder<'static>> {let mut bool_query = self.inner.build_bool_query()?;// CUSTOM ATTRIBUTES SECTION@@ -103,7 +103,7 @@ impl ChatQueryBuilder {Ok(bool_query)}- fn build_search_request(&self) -> Result<SearchRequest> {+ fn build_search_request(&self) -> Result<SearchRequest<'static>> {let bool_query = self.build_bool_query()?;// Build the search request with the bool querydiff --git a/rust/cloud-storage/opensearch_client/src/search/documents.rs b/rust/cloud-storage/opensearch_client/src/search/documents.rsindex c308f7532b..3d06b9696a 100644--- a/rust/cloud-storage/opensearch_client/src/search/documents.rs+++ b/rust/cloud-storage/opensearch_client/src/search/documents.rs@@ -23,7 +23,7 @@ impl SearchQueryConfig for DocumentSearchConfig {const USER_ID_KEY: &'static str = "owner_id";const TITLE_KEY: &'static str = "document_name";- fn default_sort_types() -> Vec<SortType> {+ fn default_sort_types() -> Vec<SortType<'static>> {vec![SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),SortType::Field(FieldSort::new(Self::ID_KEY, SortOrder::Asc)),@@ -56,11 +56,11 @@ impl DocumentQueryBuilder {fn disable_recency(disable_recency: bool) -> Self;}- pub fn build_bool_query(&self) -> Result<BoolQueryBuilder> {+ pub fn build_bool_query(&self) -> Result<BoolQueryBuilder<'static>> {self.inner.build_bool_query()}- fn build_search_request(self) -> Result<SearchRequest> {+ fn build_search_request(self) -> Result<SearchRequest<'static>> {// Build the search request with the bool query// This will automatically wrap the bool query in a function score if// SearchOn::NameContent is useddiff --git a/rust/cloud-storage/opensearch_client/src/search/emails.rs b/rust/cloud-storage/opensearch_client/src/search/emails.rsindex 3cd4d7ef16..cac555ac4d 100644--- a/rust/cloud-storage/opensearch_client/src/search/emails.rs+++ b/rust/cloud-storage/opensearch_client/src/search/emails.rs@@ -25,7 +25,7 @@ impl SearchQueryConfig for EmailSearchConfig {const USER_ID_KEY: &'static str = "user_id";const TITLE_KEY: &'static str = "subject";- fn default_sort_types() -> Vec<SortType> {+ fn default_sort_types() -> Vec<SortType<'static>> {vec![SortType::ScoreWithOrder(ScoreWithOrderSort::new(SortOrder::Desc)),SortType::Field(FieldSort::new(Self::ID_KEY, SortOrder::Asc)),@@ -97,7 +97,7 @@ impl EmailQueryBuilder {self}- pub fn build_bool_query(&self) -> Result<BoolQueryBuilder> {+ pub fn build_bool_query(&self) -> Result<BoolQueryBuilder<'static>> {// Build the main bool query containing all terms and any other filterslet mut bool_query = self.inner.build_bool_query()?;@@ -136,7 +136,7 @@ impl EmailQueryBuilder {Ok(bool_query)}- fn build_search_request(&self) -> Result<SearchRequest> {+ fn build_search_request(&self) -> Result<SearchRequest<'static>> {// Build the search request with the bool query// This will automatically wrap the bool query in a function score if// SearchOn::NameContent is useddiff --git a/rust/cloud-storage/opensearch_client/src/search/projects.rs b/rust/cloud-storage/opensearch_client/src/search/projects.rsindex 003f578ca5..737330db05 100644--- a/rust/cloud-storage/opensearch_client/src/search/projects.rs+++ b/rust/cloud-storage/opensearch_client/src/search/projects.rs@@ -22,7 +22,7 @@ impl SearchQueryConfig for ProjectSearchConfig {const TITLE_KEY: &'static str = "project_name";// Projects have no "content" to highlight match on, so match on the TITLE_KEY instead- fn default_highlight() -> opensearch_query_builder::Highlight {+ fn default_highlight() -> opensearch_query_builder::Highlight<'static> {opensearch_query_builder::Highlight::new().require_field_match(true).field(@@ -61,11 +61,11 @@ impl ProjectQueryBuilder {fn disable_recency(disable_recency: bool) -> Self;}- pub fn build_bool_query(&self) -> Result<BoolQueryBuilder> {+ pub fn build_bool_query(&self) -> Result<BoolQueryBuilder<'static>> {self.inner.build_bool_query()}- fn build_search_request(&self) -> Result<SearchRequest> {+ fn build_search_request(&self) -> Result<SearchRequest<'static>> {// Build the search request with the bool query// This will automatically wrap the bool query in a function score if// SearchOn::NameContent is useddiff --git a/rust/cloud-storage/opensearch_client/src/search/query.rs b/rust/cloud-storage/opensearch_client/src/search/query.rsindex c160584d24..dea0c0813a 100644--- a/rust/cloud-storage/opensearch_client/src/search/query.rs+++ b/rust/cloud-storage/opensearch_client/src/search/query.rs@@ -43,7 +43,7 @@ impl QueryKey {}/// Creates a query given a field and term- pub fn create_query(&self, field: &str, term: &str) -> QueryType {+ pub fn create_query(&self, field: &str, term: &str) -> QueryType<'static> {// Fixes https://linear.app/macro-eng/issue/M-5094/unified-search-match-prefix-on-phrase-should-not-constrain-terms// We need to create a more complex combo query if the last word in a term is less than 3 characters.let mut terms = term.split(' ').collect::<Vec<_>>();@@ -57,21 +57,25 @@ impl QueryKey {let last_part_of_term = terms.pop().unwrap();let first_part_of_term = terms.join(" ");+ let wildcard_pattern = format!("*{}*", last_part_of_term.to_lowercase());// build the first term querylet first_term_query = match self {- Self::MatchPhrase => {- QueryType::MatchPhrase(MatchPhraseQuery::new(field, &first_part_of_term))- }+ Self::MatchPhrase => QueryType::MatchPhrase(MatchPhraseQuery::new(+ field.to_string(),+ first_part_of_term,+ )),Self::MatchPhrasePrefix => QueryType::MatchPhrasePrefix(- MatchPhrasePrefixQuery::new(field, &first_part_of_term),+ MatchPhrasePrefixQuery::new(field.to_string(), first_part_of_term),),- Self::Regexp => QueryType::Regexp(RegexpQuery::new(field, &first_part_of_term)),+ Self::Regexp => {+ QueryType::Regexp(RegexpQuery::new(field.to_string(), first_part_of_term))+ }};let second_term_query = QueryType::WildCard(WildcardQuery::new(- field,- &format!("*{}*", last_part_of_term.to_lowercase()),+ field.to_string(),+ wildcard_pattern,true,));@@ -84,11 +88,16 @@ impl QueryKey {}match self {- Self::MatchPhrase => QueryType::MatchPhrase(MatchPhraseQuery::new(field, term)),- Self::MatchPhrasePrefix => {- QueryType::MatchPhrasePrefix(MatchPhrasePrefixQuery::new(field, term))+ Self::MatchPhrase => {+ QueryType::MatchPhrase(MatchPhraseQuery::new(field.to_string(), term.to_string()))+ }+ Self::MatchPhrasePrefix => QueryType::MatchPhrasePrefix(MatchPhrasePrefixQuery::new(+ field.to_string(),+ term.to_string(),+ )),+ Self::Regexp => {+ QueryType::Regexp(RegexpQuery::new(field.to_string(), term.to_string()))}- Self::Regexp => QueryType::Regexp(RegexpQuery::new(field, term)),}}}@@ -98,7 +107,7 @@ pub(crate) fn generate_terms_must_query(query_key: QueryKey,fields: &[&str],terms: &[String],-) -> QueryType {+) -> QueryType<'static> {let mut terms_must_query = BoolQueryBuilder::new();terms_must_query.minimum_should_match(1);@@ -106,7 +115,11 @@ pub(crate) fn generate_terms_must_query(// Map terms to querieslet queries: Vec<_> = fields.iter()- .flat_map(|field| terms.iter().map(|term| query_key.create_query(field, term)))+ .flat_map(|field| {+ terms+ .iter()+ .map(|term| query_key.create_query(field, term.as_str()))+ }).collect();// If we only have 1 query returned, we can just return that singular query@@ -125,7 +138,7 @@ pub(crate) fn generate_terms_must_query(}/// Generates the term queries SearchOn::NameContent-pub(crate) fn generate_name_content_query(keys: &Keys, terms: &[String]) -> QueryType {+pub(crate) fn generate_name_content_query(keys: &Keys, terms: &[String]) -> QueryType<'static> {let mut terms_must_query = BoolQueryBuilder::new();terms_must_query.minimum_should_match(1);@@ -138,23 +151,24 @@ pub(crate) fn generate_name_content_query(keys: &Keys, terms: &[String]) -> Querbool_query.minimum_should_match(1);bool_query.should(QueryType::MatchPhrasePrefix(- MatchPhrasePrefixQuery::new(keys.title_key, term).boost(1000.0),+ MatchPhrasePrefixQuery::new(keys.title_key.to_string(), term.clone()).boost(1000.0),));bool_query.should(QueryType::MatchPhrasePrefix(- MatchPhrasePrefixQuery::new(keys.content_key, term).boost(900.0),+ MatchPhrasePrefixQuery::new(keys.content_key.to_string(), term.clone())+ .boost(900.0),));bool_query.should(QueryType::Match(- MatchQuery::new(keys.title_key, term)+ MatchQuery::new(keys.title_key.to_string(), term.clone()).boost(0.1).minimum_should_match("80%"), // TODO: we may need to play around with this to get the best highlight match));bool_query.should(QueryType::Match(- MatchQuery::new(keys.content_key, term)+ MatchQuery::new(keys.content_key.to_string(), term.clone()).boost(0.09)- .minimum_should_match(&term.split(' ').count().to_string()), // TODO: we may need to play around with this to get the best highlight match+ .minimum_should_match(term.split(' ').count().to_string()), // TODO: we may need to play around with this to get the best highlight match));bool_query.build().into()diff --git a/rust/cloud-storage/opensearch_client/src/search/unified.rs b/rust/cloud-storage/opensearch_client/src/search/unified.rsindex 69f970f65c..c4b0d3da42 100644--- a/rust/cloud-storage/opensearch_client/src/search/unified.rs+++ b/rust/cloud-storage/opensearch_client/src/search/unified.rs@@ -386,7 +386,7 @@ impl From<Hit<UnifiedSearchIndex>> for UnifiedSearchResponse {}#[tracing::instrument(skip(args), err)]-fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequest> {+fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequest<'static>> {if args.search_indices.is_empty() {return Err(OpensearchClientError::EmptySearchIndices);}@@ -460,7 +460,7 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequesif args.search_on == SearchOn::NameContent {search_request_builder.track_total_hits(true);search_request_builder.add_agg(- "total_uniques".to_string(),+ "total_uniques",AggregationType::Cardinality(CardinalityAggregation::new("entity_id")),);}@@ -547,10 +547,10 @@ fn build_unified_search_request(args: &UnifiedSearchArgs) -> Result<SearchRequesfunction_score_query.function(ScoreFunction {function: ScoreFunctionType::Gauss(DecayFunction {- field: "updated_at_seconds".to_string(),+ field: "updated_at_seconds".into(),origin: Some("now".into()),- scale: "21d".to_string(),- offset: Some("3d".to_string()),+ scale: "21d".into(),+ offset: Some("3d".into()),decay: Some(0.5),}),filter: None,diff --git a/rust/cloud-storage/opensearch_client/src/search/utils.rs b/rust/cloud-storage/opensearch_client/src/search/utils.rsindex b044c1c28a..a81d46d86d 100644--- a/rust/cloud-storage/opensearch_client/src/search/utils.rs+++ b/rust/cloud-storage/opensearch_client/src/search/utils.rs@@ -1,11 +1,17 @@use opensearch_query_builder::{BoolQueryBuilder, QueryType, WildcardQuery};-pub fn should_wildcard_field_query_builder(field: &str, values: &[String]) -> QueryType {+pub fn should_wildcard_field_query_builder(field: &str, values: &[String]) -> QueryType<'static> {let mut should_query = BoolQueryBuilder::new();should_query.minimum_should_match(1);let wildcard_queries: Vec<WildcardQuery> = values.iter()- .map(|value| WildcardQuery::new(field, &format!("*{}*", value.to_lowercase()), true))+ .map(|value| {+ WildcardQuery::new(+ field.to_string(),+ format!("*{}*", value.to_lowercase()),+ true,+ )+ }).collect();for query in wildcard_queries {should_query.should(QueryType::WildCard(query));