Skip to content

Commit 35c9b8a

Browse files
tsdk02hyperswitch-bot[bot]Abhitator216
authored
feat(globalsearch): Added search_tags based filter for global search in dashboard (#5341)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com> Co-authored-by: Abhishek Kanojia <[email protected]>
1 parent 96edf52 commit 35c9b8a

File tree

5 files changed

+50
-8
lines changed

5 files changed

+50
-8
lines changed

api-reference/openapi_spec.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9515,11 +9515,11 @@
95159515
"nullable": true
95169516
},
95179517
"search_tags": {
9518-
"allOf": [
9519-
{
9520-
"$ref": "#/components/schemas/RedirectResponse"
9521-
}
9522-
],
9518+
"type": "array",
9519+
"items": {
9520+
"type": "string"
9521+
},
9522+
"description": "Additional tags to be used for global search",
95239523
"nullable": true
95249524
}
95259525
}

crates/analytics/src/search.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,24 @@ pub async fn msearch_results(
6666
.switch()?;
6767
}
6868
};
69+
if let Some(search_tags) = filters.search_tags {
70+
if !search_tags.is_empty() {
71+
query_builder
72+
.add_filter_clause(
73+
"feature_metadata.search_tags.keyword".to_string(),
74+
search_tags
75+
.iter()
76+
.filter_map(|search_tag| {
77+
// TODO: Add trait based inputs instead of converting this to strings
78+
serde_json::to_value(search_tag)
79+
.ok()
80+
.and_then(|a| a.as_str().map(|a| a.to_string()))
81+
})
82+
.collect(),
83+
)
84+
.switch()?;
85+
}
86+
};
6987
};
7088

7189
let response_text: OpenMsearchOutput = client
@@ -173,6 +191,24 @@ pub async fn search_results(
173191
.switch()?;
174192
}
175193
};
194+
if let Some(search_tags) = filters.search_tags {
195+
if !search_tags.is_empty() {
196+
query_builder
197+
.add_filter_clause(
198+
"feature_metadata.search_tags.keyword".to_string(),
199+
search_tags
200+
.iter()
201+
.filter_map(|search_tag| {
202+
// TODO: Add trait based inputs instead of converting this to strings
203+
serde_json::to_value(search_tag)
204+
.ok()
205+
.and_then(|a| a.as_str().map(|a| a.to_string()))
206+
})
207+
.collect(),
208+
)
209+
.switch()?;
210+
}
211+
};
176212
};
177213
query_builder
178214
.set_offset_n_count(search_req.offset, search_req.count)

crates/api_models/src/analytics/search.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use common_utils::hashing::HashedString;
2+
use masking::WithType;
23
use serde_json::Value;
34

45
#[derive(Clone, Debug, Default, serde::Deserialize, serde::Serialize)]
@@ -7,6 +8,7 @@ pub struct SearchFilters {
78
pub currency: Option<Vec<String>>,
89
pub status: Option<Vec<String>>,
910
pub customer_email: Option<Vec<HashedString<common_utils::pii::EmailStrategy>>>,
11+
pub search_tags: Option<Vec<HashedString<WithType>>>,
1012
}
1113

1214
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize)]

crates/api_models/src/payments.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ use common_utils::{
99
consts::default_payments_list_limit,
1010
crypto,
1111
ext_traits::{ConfigExt, Encode},
12+
hashing::HashedString,
1213
id_type,
1314
pii::{self, Email},
1415
types::{MinorUnit, StringMajorUnit},
1516
};
16-
use masking::{PeekInterface, Secret};
17+
use masking::{PeekInterface, Secret, WithType};
1718
use router_derive::Setter;
1819
use serde::{
1920
de::{self, Unexpected, Visitor},
@@ -4987,11 +4988,12 @@ pub struct PaymentsStartRequest {
49874988
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, ToSchema)]
49884989
pub struct FeatureMetadata {
49894990
/// Redirection response coming in request as metadata field only for redirection scenarios
4991+
#[schema(value_type = Option<RedirectResponse>)]
49904992
pub redirect_response: Option<RedirectResponse>,
49914993
// TODO: Convert this to hashedstrings to avoid PII sensitive data
49924994
/// Additional tags to be used for global search
4993-
#[schema(value_type = Option<RedirectResponse>)]
4994-
pub search_tags: Option<Vec<Secret<String>>>,
4995+
#[schema(value_type = Option<Vec<String>>)]
4996+
pub search_tags: Option<Vec<HashedString<WithType>>>,
49954997
}
49964998

49974999
///frm message is an object sent inside the payments response...when frm is invoked, its value is Some(...), else its None

crates/masking/src/strategy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ pub trait Strategy<T> {
77
}
88

99
/// Debug with type
10+
#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
11+
#[derive(Debug, Copy, Clone)]
1012
pub enum WithType {}
1113

1214
impl<T> Strategy<T> for WithType {

0 commit comments

Comments
 (0)