Update Meilisearch SDK (#53)

* Update Meilisearch SDK

* Run Formatter

* Fixes
This commit is contained in:
Geometrically
2020-08-27 17:53:40 -07:00
committed by GitHub
parent 017cf9e464
commit 2b1ed49e9a
4 changed files with 29 additions and 15 deletions

18
Cargo.lock generated
View File

@@ -34,6 +34,18 @@ dependencies = [
"trust-dns-resolver", "trust-dns-resolver",
] ]
[[package]]
name = "actix-cors"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a6206917d5c0fdd79d81cec9ef02d3e802df4abf276d96241e1f595d971e002"
dependencies = [
"actix-service",
"actix-web",
"derive_more",
"futures",
]
[[package]] [[package]]
name = "actix-files" name = "actix-files"
version = "0.2.2" version = "0.2.2"
@@ -1146,6 +1158,7 @@ dependencies = [
name = "labrinth" name = "labrinth"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"actix-cors",
"actix-files", "actix-files",
"actix-multipart", "actix-multipart",
"actix-rt", "actix-rt",
@@ -1278,8 +1291,9 @@ dependencies = [
[[package]] [[package]]
name = "meilisearch-sdk" name = "meilisearch-sdk"
version = "0.1.4" version = "0.3.0"
source = "git+https://github.com/Aeledfyr/meilisearch-rust#ba1f1e530cb383f421273f6863378bc9bc222f7b" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3a9e61da1ebd3d15e0aaa978d3f1f080e3793494ddea0bc6703da4b330ea1ffc"
dependencies = [ dependencies = [
"log", "log",
"reqwest", "reqwest",

View File

@@ -18,6 +18,8 @@ actix-files = "0.2.2"
actix-multipart = "0.2.0" actix-multipart = "0.2.0"
actix-cors = "0.2.0" actix-cors = "0.2.0"
meilisearch-sdk = "0.3.0"
reqwest = {version="0.10.6", features=["json"]} reqwest = {version="0.10.6", features=["json"]}
serde_json = "1.0" serde_json = "1.0"
@@ -50,8 +52,3 @@ git = "https://github.com/launchbadge/sqlx/"
branch = "master" branch = "master"
default-features = false default-features = false
features = ["runtime-actix", "postgres", "chrono", "offline"] features = ["runtime-actix", "postgres", "chrono", "offline"]
[dependencies.meilisearch-sdk]
# Temp fork with some patches
git = "https://github.com/Aeledfyr/meilisearch-rust"
branch = "master"

View File

@@ -1,6 +1,6 @@
use actix_web::middleware::Logger;
use actix_cors::Cors; use actix_cors::Cors;
use actix_web::{web, App, HttpServer, http}; use actix_web::middleware::Logger;
use actix_web::{http, web, App, HttpServer};
use env_logger::Env; use env_logger::Env;
use gumdrop::Options; use gumdrop::Options;
use log::{info, warn}; use log::{info, warn};
@@ -178,7 +178,7 @@ async fn main() -> std::io::Result<()> {
.allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT]) .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
.allowed_header(http::header::CONTENT_TYPE) .allowed_header(http::header::CONTENT_TYPE)
.max_age(3600) .max_age(3600)
.finish() .finish(),
) )
.wrap(Logger::default()) .wrap(Logger::default())
.wrap(Logger::new("%a %{User-Agent}i")) .wrap(Logger::new("%a %{User-Agent}i"))

View File

@@ -129,9 +129,10 @@ async fn update_index<'a>(
) -> Result<Index<'a>, IndexingError> { ) -> Result<Index<'a>, IndexingError> {
let index = match client.get_index(name).await { let index = match client.get_index(name).await {
Ok(index) => index, Ok(index) => index,
Err(meilisearch_sdk::errors::Error::IndexNotFound) => { Err(meilisearch_sdk::errors::Error::MeiliSearchError {
client.create_index(name, Some("mod_id")).await? error_code: meilisearch_sdk::errors::ErrorCode::IndexNotFound,
} ..
}) => client.create_index(name, Some("mod_id")).await?,
Err(e) => { Err(e) => {
return Err(IndexingError::IndexDBError(e)); return Err(IndexingError::IndexDBError(e));
} }
@@ -150,7 +151,10 @@ async fn create_index<'a>(
match client.get_index(name).await { match client.get_index(name).await {
// TODO: update index settings on startup (or delete old indices on startup) // TODO: update index settings on startup (or delete old indices on startup)
Ok(index) => Ok(index), Ok(index) => Ok(index),
Err(meilisearch_sdk::errors::Error::IndexNotFound) => { Err(meilisearch_sdk::errors::Error::MeiliSearchError {
error_code: meilisearch_sdk::errors::ErrorCode::IndexNotFound,
..
}) => {
// Only create index and set settings if the index doesn't already exist // Only create index and set settings if the index doesn't already exist
let index = client.create_index(name, Some("mod_id")).await?; let index = client.create_index(name, Some("mod_id")).await?;
@@ -260,7 +264,6 @@ fn default_settings() -> Settings {
Settings::new() Settings::new()
.with_displayed_attributes(displayed_attributes) .with_displayed_attributes(displayed_attributes)
.with_searchable_attributes(searchable_attributes) .with_searchable_attributes(searchable_attributes)
.with_accept_new_fields(true)
.with_stop_words(vec![]) .with_stop_words(vec![])
.with_synonyms(HashMap::new()) .with_synonyms(HashMap::new())
.with_attributes_for_faceting(vec![String::from("categories"), String::from("host")]) .with_attributes_for_faceting(vec![String::from("categories"), String::from("host")])