use actix_web::{get, post, web, HttpResponse}; use crate::error::ResponseError; use crate::helpers::Authentication; use crate::routes::IndexParam; use crate::Data; use crate::data::SearchQuery; pub fn services(cfg: &mut web::ServiceConfig) { cfg.service(search_with_post).service(search_with_url_query); } //#[derive(Serialize, Deserialize)] //#[serde(rename_all = "camelCase", deny_unknown_fields)] //pub struct SearchQuery { //q: Option, //offset: Option, //limit: Option, //attributes_to_retrieve: Option, //attributes_to_crop: Option, //crop_length: Option, //attributes_to_highlight: Option, //filters: Option, //matches: Option, //facet_filters: Option, //facets_distribution: Option, //} #[get("/indexes/{index_uid}/search", wrap = "Authentication::Public")] async fn search_with_url_query( _data: web::Data, _path: web::Path, _params: web::Query, ) -> Result { todo!() } #[post("/indexes/{index_uid}/search", wrap = "Authentication::Public")] async fn search_with_post( data: web::Data, path: web::Path, params: web::Json, ) -> Result { let search_result = data.search(&path.index_uid, params.into_inner()); match search_result { Ok(docs) => { let docs = serde_json::to_string(&docs).unwrap(); Ok(HttpResponse::Ok().body(docs)) } Err(e) => { Ok(HttpResponse::BadRequest().body(serde_json::json!({ "error": e.to_string() }))) } } }