mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-27 04:25:06 +08:00
Merge pull request #161 from meilisearch/remove-tide
Remove tide as it break compilation on the latest nightly
This commit is contained in:
commit
25a5605b35
@ -8,10 +8,6 @@ authors = ["Kerollmops <renault.cle@gmail.com>"]
|
|||||||
meilidb-core = { path = "../meilidb-core", version = "0.1.0" }
|
meilidb-core = { path = "../meilidb-core", version = "0.1.0" }
|
||||||
meilidb-data = { path = "../meilidb-data", version = "0.1.0" }
|
meilidb-data = { path = "../meilidb-data", version = "0.1.0" }
|
||||||
meilidb-schema = { path = "../meilidb-schema", 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]
|
[dev-dependencies]
|
||||||
csv = "1.0.7"
|
csv = "1.0.7"
|
||||||
@ -22,6 +18,9 @@ meilidb-core = { path = "../meilidb-core", version = "0.1.0" }
|
|||||||
quickcheck = "0.8.2"
|
quickcheck = "0.8.2"
|
||||||
rand = "0.6.5"
|
rand = "0.6.5"
|
||||||
rand_xorshift = "0.1.1"
|
rand_xorshift = "0.1.1"
|
||||||
|
serde = { version = "1.0.91" , features = ["derive"] }
|
||||||
|
serde_json = "1.0.39"
|
||||||
structopt = "0.2.15"
|
structopt = "0.2.15"
|
||||||
sysinfo = "0.8.4"
|
sysinfo = "0.8.4"
|
||||||
|
tempfile = "3.0.7"
|
||||||
termcolor = "1.0.4"
|
termcolor = "1.0.4"
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
static ALLOC: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
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::path::{Path, PathBuf};
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
@ -51,7 +51,7 @@ fn index(
|
|||||||
csv_data_path: &Path,
|
csv_data_path: &Path,
|
||||||
update_group_size: Option<usize>,
|
update_group_size: Option<usize>,
|
||||||
stop_words: &HashSet<String>,
|
stop_words: &HashSet<String>,
|
||||||
) -> Result<Database, Box<Error>>
|
) -> Result<Database, Box<dyn Error>>
|
||||||
{
|
{
|
||||||
let database = Database::start_default(database_path)?;
|
let database = Database::start_default(database_path)?;
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ fn retrieve_stop_words(path: &Path) -> io::Result<HashSet<String>> {
|
|||||||
Ok(words)
|
Ok(words)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ fn crop_text(
|
|||||||
(text, matches)
|
(text, matches)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> Result<(), Box<Error>> {
|
fn main() -> Result<(), Box<dyn Error>> {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let opt = Opt::from_args();
|
let opt = Opt::from_args();
|
||||||
|
|
||||||
|
@ -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<Database>) -> 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<Database>) -> EndpointResult<()> {
|
|
||||||
let index: String = cx.param("index").client_err()?;
|
|
||||||
let document: HashMap<String, Value> = 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<Database>) -> 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<Value> = 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")
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user