feat: add debug index function to api

This commit is contained in:
Alex Wellnitz 2024-02-12 23:15:44 +01:00
parent 655b2df151
commit ecdad1b553
3 changed files with 12 additions and 1 deletions

View File

@ -1,4 +1,4 @@
use actix_web::{web, HttpRequest, HttpResponse, Responder};
use actix_web::{web, HttpResponse, Responder};
use serde::Deserialize;
use crate::types::app_state::AppStateWithSearchEngine;
@ -35,4 +35,9 @@ pub async fn search(data: web::Data<AppStateWithSearchEngine>, req: web::Query<Q
let results = data.search_engine.lock().unwrap().search(&req.query);
HttpResponse::Ok().json(results)
}
pub async fn debug_index(data: web::Data<AppStateWithSearchEngine>) -> impl Responder {
data.search_engine.lock().unwrap().debug_index();
HttpResponse::Ok().json("Index debugged!")
}

View File

@ -39,6 +39,7 @@ async fn main() -> std::io::Result<()> {
web::get().to(search::get_number_of_documents),
)
.route("/search", web::get().to(search::search))
.route("/search/debug", web::get().to(search::debug_index))
})
.bind(("127.0.0.1", 8080))?
.run()

View File

@ -90,4 +90,9 @@ impl SearchEngine {
let keyword = normalize_string(keyword);
self.index.get(&keyword).cloned().unwrap_or(HashMap::new())
}
pub fn debug_index(&self) {
log::debug!("Index: {:?}", self.index);
log::debug!("Documents: {:?}", self.documents);
}
}