@@ -4,6 +4,7 @@ use crate::server::connector::get_connector_by_id;
44use crate :: server:: http_client:: HttpClient ;
55use crate :: server:: servers:: get_all_servers;
66use lazy_static:: lazy_static;
7+ use serde_json:: Value ;
78use std:: collections:: HashMap ;
89use std:: sync:: { Arc , RwLock } ;
910use tauri:: { AppHandle , Runtime } ;
@@ -12,7 +13,7 @@ use tauri::{AppHandle, Runtime};
1213pub struct GetDatasourcesByServerOptions {
1314 pub from : Option < u32 > ,
1415 pub size : Option < u32 > ,
15- pub query : Option < String > ,
16+ pub query : Option < serde_json :: Value > ,
1617}
1718
1819lazy_static ! {
@@ -32,7 +33,7 @@ pub fn save_datasource_to_cache(server_id: &str, datasources: Vec<DataSource>) {
3233#[ allow( dead_code) ]
3334pub fn get_datasources_from_cache ( server_id : & str ) -> Option < HashMap < String , DataSource > > {
3435 let cache = DATASOURCE_CACHE . read ( ) . unwrap ( ) ; // Acquire read lock
35- // dbg!("cache: {:?}", &cache);
36+ // dbg!("cache: {:?}", &cache);
3637 let server_cache = cache. get ( server_id) ?; // Get the server's cache
3738 Some ( server_cache. clone ( ) )
3839}
@@ -100,31 +101,14 @@ pub async fn datasource_search(
100101) -> Result < Vec < DataSource > , String > {
101102 let from = options. as_ref ( ) . and_then ( |opt| opt. from ) . unwrap_or ( 0 ) ;
102103 let size = options. as_ref ( ) . and_then ( |opt| opt. size ) . unwrap_or ( 10000 ) ;
103- let query = options
104- . and_then ( |opt| opt. query )
105- . unwrap_or ( String :: default ( ) ) ;
106104
107105 let mut body = serde_json:: json!( {
108106 "from" : from,
109107 "size" : size,
110108 } ) ;
111109
112- if !query. is_empty ( ) {
113- body[ "query" ] = serde_json:: json!( {
114- "bool" : {
115- "must" : [ {
116- "query_string" : {
117- "fields" : [ "combined_fulltext" ] ,
118- "query" : query,
119- "fuzziness" : "AUTO" ,
120- "fuzzy_prefix_length" : 2 ,
121- "fuzzy_max_expansions" : 10 ,
122- "fuzzy_transpositions" : true ,
123- "allow_leading_wildcard" : false
124- }
125- } ]
126- }
127- } ) ;
110+ if let Some ( q) = options. unwrap ( ) . query {
111+ body[ "query" ] = q;
128112 }
129113
130114 // Perform the async HTTP request outside the cache lock
@@ -134,12 +118,12 @@ pub async fn datasource_search(
134118 None ,
135119 Some ( reqwest:: Body :: from ( body. to_string ( ) ) ) ,
136120 )
137- . await
138- . map_err ( |e| format ! ( "Error fetching datasource: {}" , e) ) ?;
121+ . await
122+ . map_err ( |e| format ! ( "Error fetching datasource: {}" , e) ) ?;
139123
140124 // Parse the search results from the response
141125 let datasources: Vec < DataSource > = parse_search_results ( resp) . await . map_err ( |e| {
142- dbg ! ( "Error parsing search results: {}" , & e) ;
126+ // dbg!("Error parsing search results: {}", &e);
143127 e. to_string ( )
144128 } ) ?;
145129
@@ -152,35 +136,17 @@ pub async fn datasource_search(
152136#[ tauri:: command]
153137pub async fn mcp_server_search (
154138 id : & str ,
155- options : Option < GetDatasourcesByServerOptions > ,
139+ from : u32 ,
140+ size : u32 ,
141+ query : Option < HashMap < String , Value > > ,
156142) -> Result < Vec < DataSource > , String > {
157- let from = options. as_ref ( ) . and_then ( |opt| opt. from ) . unwrap_or ( 0 ) ;
158- let size = options. as_ref ( ) . and_then ( |opt| opt. size ) . unwrap_or ( 10000 ) ;
159- let query = options
160- . and_then ( |opt| opt. query )
161- . unwrap_or ( String :: default ( ) ) ;
162-
163143 let mut body = serde_json:: json!( {
164- "from" : from,
165- "size" : size,
144+ "from" : from,
145+ "size" : size,
166146 } ) ;
167147
168- if !query. is_empty ( ) {
169- body[ "query" ] = serde_json:: json!( {
170- "bool" : {
171- "must" : [ {
172- "query_string" : {
173- "fields" : [ "combined_fulltext" ] ,
174- "query" : query,
175- "fuzziness" : "AUTO" ,
176- "fuzzy_prefix_length" : 2 ,
177- "fuzzy_max_expansions" : 10 ,
178- "fuzzy_transpositions" : true ,
179- "allow_leading_wildcard" : false
180- }
181- } ]
182- }
183- } ) ;
148+ if let Some ( q) = query {
149+ body[ "query" ] = serde_json:: to_value ( q) . map_err ( |e| e. to_string ( ) ) ?;
184150 }
185151
186152 // Perform the async HTTP request outside the cache lock
@@ -190,12 +156,12 @@ pub async fn mcp_server_search(
190156 None ,
191157 Some ( reqwest:: Body :: from ( body. to_string ( ) ) ) ,
192158 )
193- . await
194- . map_err ( |e| format ! ( "Error fetching datasource: {}" , e) ) ?;
159+ . await
160+ . map_err ( |e| format ! ( "Error fetching datasource: {}" , e) ) ?;
195161
196162 // Parse the search results from the response
197163 let mcp_server: Vec < DataSource > = parse_search_results ( resp) . await . map_err ( |e| {
198- dbg ! ( "Error parsing search results: {}" , & e) ;
164+ // dbg!("Error parsing search results: {}", &e);
199165 e. to_string ( )
200166 } ) ?;
201167
0 commit comments