From b630e32c6af73317ba06072e628db0b538caebaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Tue, 18 Jun 2019 13:40:46 +0200 Subject: [PATCH] fix: Remove tide as it break compilation on the latest nightly --- meilidb/Cargo.toml | 7 ++- meilidb/examples/create-database.rs | 6 +-- meilidb/examples/query-database.rs | 2 +- meilidb/src/main.rs | 75 ----------------------------- 4 files changed, 7 insertions(+), 83 deletions(-) delete mode 100644 meilidb/src/main.rs diff --git a/meilidb/Cargo.toml b/meilidb/Cargo.toml index 5c80a6d26..8ba89f212 100644 --- a/meilidb/Cargo.toml +++ b/meilidb/Cargo.toml @@ -8,10 +8,6 @@ authors = ["Kerollmops "] meilidb-core = { path = "../meilidb-core", version = "0.1.0" } meilidb-data = { path = "../meilidb-data", version = "0.1.0" } meilidb-schema = { path = "../meilidb-schema", version = "0.1.0" } -serde = { version = "1.0.91" , features = ["derive"] } -serde_json = "1.0.39" -tempfile = "3.0.7" -tide = "0.2.0" [dev-dependencies] csv = "1.0.7" @@ -22,6 +18,9 @@ meilidb-core = { path = "../meilidb-core", version = "0.1.0" } quickcheck = "0.8.2" rand = "0.6.5" rand_xorshift = "0.1.1" +serde = { version = "1.0.91" , features = ["derive"] } +serde_json = "1.0.39" structopt = "0.2.15" sysinfo = "0.8.4" +tempfile = "3.0.7" termcolor = "1.0.4" diff --git a/meilidb/examples/create-database.rs b/meilidb/examples/create-database.rs index 5623fe4bb..ed07e3742 100644 --- a/meilidb/examples/create-database.rs +++ b/meilidb/examples/create-database.rs @@ -2,7 +2,7 @@ static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc; use std::collections::{HashMap, HashSet}; -use std::io::{self, Write, BufRead, BufReader}; +use std::io::{self, BufRead, BufReader}; use std::path::{Path, PathBuf}; use std::time::Instant; use std::error::Error; @@ -51,7 +51,7 @@ fn index( csv_data_path: &Path, update_group_size: Option, stop_words: &HashSet, -) -> Result> +) -> Result> { let database = Database::start_default(database_path)?; @@ -124,7 +124,7 @@ fn retrieve_stop_words(path: &Path) -> io::Result> { Ok(words) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let _ = env_logger::init(); let opt = Opt::from_args(); diff --git a/meilidb/examples/query-database.rs b/meilidb/examples/query-database.rs index 599dc8fa6..1da6ebf0a 100644 --- a/meilidb/examples/query-database.rs +++ b/meilidb/examples/query-database.rs @@ -133,7 +133,7 @@ fn crop_text( (text, matches) } -fn main() -> Result<(), Box> { +fn main() -> Result<(), Box> { let _ = env_logger::init(); let opt = Opt::from_args(); diff --git a/meilidb/src/main.rs b/meilidb/src/main.rs deleted file mode 100644 index dd074b956..000000000 --- a/meilidb/src/main.rs +++ /dev/null @@ -1,75 +0,0 @@ -#![feature(async_await)] - -use std::collections::HashMap; - -use meilidb_data::Database; -use meilidb_schema::Schema; -use serde::{Deserialize, Serialize}; -use serde_json::Value; -use tide::http::status::StatusCode; -use tide::querystring::ExtractQuery; -use tide::{error::ResultExt, response, App, Context, EndpointResult}; - -#[derive(Debug, Serialize, Deserialize, Clone)] -struct SearchQuery { - q: String, -} - -async fn create_index(mut cx: Context) -> EndpointResult<()> { - let index: String = cx.param("index").client_err()?; - let schema = cx.body_bytes().await.client_err()?; - let schema = Schema::from_toml(schema.as_slice()).unwrap(); - - let database = cx.app_data(); - database.create_index(&index, schema).unwrap(); - - Ok(()) -} - -async fn update_documents(mut cx: Context) -> EndpointResult<()> { - let index: String = cx.param("index").client_err()?; - let document: HashMap = cx.body_json().await.client_err()?; - - let database = cx.app_data(); - let index = match database.open_index(&index).unwrap() { - Some(index) => index, - None => Err(StatusCode::NOT_FOUND)?, - }; - - let mut addition = index.documents_addition(); - addition.update_document(document).unwrap(); - addition.finalize().unwrap(); - - Ok(()) -} - -async fn search_index(cx: Context) -> EndpointResult { - let index: String = cx.param("index").client_err()?; - let query: SearchQuery = cx.url_query()?; - - let database = cx.app_data(); - - let index = match database.open_index(&index).unwrap() { - Some(index) => index, - None => Err(StatusCode::NOT_FOUND)?, - }; - - let documents_ids = index.query_builder().query(&query.q, 0..100).unwrap(); - let documents: Vec = documents_ids - .into_iter() - .filter_map(|x| index.document(None, x.id).unwrap()) - .collect(); - - Ok(response::json(documents)) -} - -fn main() -> std::io::Result<()> { - let tmp_dir = tempfile::tempdir().unwrap(); - let database = Database::start_default(&tmp_dir).unwrap(); - let mut app = App::new(database); - - app.at("/:index").post(create_index).put(update_documents); - app.at("/:index/search").get(search_index); - - app.serve("127.0.0.1:8000") -}