feat: add search document indexing handler
This commit is contained in:
parent
ffeaa97feb
commit
5c58d7d870
@ -1,3 +1,17 @@
|
|||||||
pub fn index_new_document() {
|
use axum::
|
||||||
println!("index_new_document");
|
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,
|
||||||
}
|
}
|
@ -1,17 +1,24 @@
|
|||||||
|
use axum::routing::post;
|
||||||
use axum::{
|
use axum::{
|
||||||
routing::get,
|
routing::get,
|
||||||
Router,
|
Router,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use rustysearch::search::engine::SearchEngine;
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
// initialize tracing
|
// initialize tracing
|
||||||
tracing_subscriber::fmt::init();
|
tracing_subscriber::fmt::init();
|
||||||
|
|
||||||
|
// initialize our search engine
|
||||||
|
let mut search_engine = SearchEngine::new(1.5, 0.75);
|
||||||
|
|
||||||
// build our application with a route
|
// build our application with a route
|
||||||
let app = Router::new()
|
let app = Router::new()
|
||||||
// `GET /` goes to `root`
|
// `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
|
// run our app with hyper, listening globally on port 3000
|
||||||
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user