diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-26 13:39:14 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-10-27 01:08:43 +0200 |
commit | 019803c0897e450cf72d16fd34c38db3778e0f92 (patch) | |
tree | ed9b6b5e17f0e9ff0c352daf1486c15adee29c07 | |
parent | Frontend: Add results field to the state and set dummy results (diff) | |
download | OSSE-019803c0897e450cf72d16fd34c38db3778e0f92.tar.gz OSSE-019803c0897e450cf72d16fd34c38db3778e0f92.tar.bz2 OSSE-019803c0897e450cf72d16fd34c38db3778e0f92.zip |
Indexer: Return json from the /search endpoint
-rw-r--r-- | Cargo.lock | 1 | ||||
-rw-r--r-- | indexer/Cargo.toml | 1 | ||||
-rw-r--r-- | indexer/src/main.rs | 11 |
3 files changed, 6 insertions, 7 deletions
diff --git a/Cargo.lock b/Cargo.lock index fe6eef3..8686540 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1102,6 +1102,7 @@ dependencies = [ "rand 0.7.3", "scraper", "serde", + "serde_json", ] [[package]] diff --git a/indexer/Cargo.toml b/indexer/Cargo.toml index f86c656..97b8497 100644 --- a/indexer/Cargo.toml +++ b/indexer/Cargo.toml @@ -11,6 +11,7 @@ serde = { version = "1.0", features = ["derive"] } scraper = "0.12.0" html2text = "0.4.3" rand = "0.7.3" +serde_json = "1.0.87" [[bin]] name = "indexer" diff --git a/indexer/src/main.rs b/indexer/src/main.rs index ba4e70c..44dbd1b 100644 --- a/indexer/src/main.rs +++ b/indexer/src/main.rs @@ -1,11 +1,11 @@ use actix_web::{get, post, web, App, HttpServer, Responder}; use rand::Rng; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use std::hash::{Hash, Hasher}; use std::sync::{Arc, Mutex}; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] struct CrawledResource { url: String, priority: u32, //how do we even calculate this @@ -101,7 +101,7 @@ async fn search(data: web::Data<AppState>, term: web::Path<String>) -> impl Resp let mut valid_results: Option<HashSet<CrawledResource>> = None; for w in query { let curr_word_results = match database.get(w) { - None => return format!("No results found for {:?}!", w), + None => return "[]".to_string(), Some(results) => results, }; @@ -119,10 +119,7 @@ async fn search(data: web::Data<AppState>, term: web::Path<String>) -> impl Resp } } - format!( - "Searching for: {term}\nResults: {:?}", - valid_results.unwrap() - ) + serde_json::to_string(&valid_results.unwrap()).unwrap() } //TODO! |