diff --git a/src/handler/search.rs b/src/handler/search.rs index d41703d..57691f3 100644 --- a/src/handler/search.rs +++ b/src/handler/search.rs @@ -1,3 +1,17 @@ -pub fn index_new_document() { - println!("index_new_document"); +use axum:: + Json +; +use serde::Deserialize; + +use crate::search::engine::SearchEngine; + +pub fn index_new_document(mut engine: SearchEngine, Json(payload): Json) { + engine.index(&payload.url, &payload.content); +} + +// the input to our `create_user` handler +#[derive(Deserialize)] +pub struct IndexNewDocument { + url: String, + content: String, } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 8f332be..7f0d002 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,17 +1,24 @@ +use axum::routing::post; use axum::{ routing::get, Router, }; +use rustysearch::search::engine::SearchEngine; + #[tokio::main] async fn main() { // initialize tracing tracing_subscriber::fmt::init(); + // initialize our search engine + let mut search_engine = SearchEngine::new(1.5, 0.75); + // build our application with a route let app = Router::new() // `GET /` goes to `root` - .route("/", get(rustysearch::handler::hello::say_hello)); + .route("/", get(rustysearch::handler::hello::say_hello)) + .route("/search/add", post(rustysearch::handler::search::index_new_document)); // run our app with hyper, listening globally on port 3000 let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();