feat: add search document indexing handler

This commit is contained in:
Alex Wellnitz 2024-02-11 17:52:46 +01:00
parent ffeaa97feb
commit 5c58d7d870
2 changed files with 24 additions and 3 deletions

View File

@ -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<IndexNewDocument>) {
engine.index(&payload.url, &payload.content);
}
// the input to our `create_user` handler
#[derive(Deserialize)]
pub struct IndexNewDocument {
url: String,
content: String,
}

View File

@ -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();