@@ -589,6 +589,38 @@ async fn get_timeseries(
589589 OkCors ( CollectionTimeseriesResponse { range, series } ) . into ( )
590590}
591591
592+ #[ derive( Debug , Deserialize , JsonSchema ) ]
593+ struct SearchQuery {
594+ /// Query
595+ ///
596+ /// at least two alphanumeric (+hyphen) characters must be present
597+ q : String ,
598+ }
599+ #[ derive( Debug , Serialize , JsonSchema ) ]
600+ struct SearchResponse {
601+ matches : Vec < NsidCount > ,
602+ }
603+ /// Search lexicons
604+ #[ endpoint {
605+ method = GET ,
606+ path = "/search"
607+ } ]
608+ async fn search_collections (
609+ ctx : RequestContext < Context > ,
610+ query : Query < SearchQuery > ,
611+ ) -> OkCorsResponse < SearchResponse > {
612+ let Context { storage, .. } = ctx. context ( ) ;
613+ let q = query. into_inner ( ) ;
614+ // TODO: query validation
615+ // TODO: also handle multi-space stuff (ufos-app tries to on client)
616+ let terms: Vec < String > = q. q . split ( ' ' ) . map ( Into :: into) . collect ( ) ;
617+ let matches = storage
618+ . search_collections ( terms)
619+ . await
620+ . map_err ( |e| HttpError :: for_internal_error ( format ! ( "oh ugh: {e:?}" ) ) ) ?;
621+ OkCors ( SearchResponse { matches } ) . into ( )
622+ }
623+
592624pub async fn serve ( storage : impl StoreReader + ' static ) -> Result < ( ) , String > {
593625 let log = ConfigLogging :: StderrTerminal {
594626 level : ConfigLoggingLevel :: Info ,
@@ -606,6 +638,7 @@ pub async fn serve(storage: impl StoreReader + 'static) -> Result<(), String> {
606638 api. register ( get_collections) . unwrap ( ) ;
607639 api. register ( get_prefix) . unwrap ( ) ;
608640 api. register ( get_timeseries) . unwrap ( ) ;
641+ api. register ( search_collections) . unwrap ( ) ;
609642
610643 let context = Context {
611644 spec : Arc :: new (
0 commit comments