last review edits + fmt

This commit is contained in:
mpostma
2021-03-15 18:11:10 +01:00
parent c29b86849b
commit dd324807f9
46 changed files with 764 additions and 589 deletions

View File

@ -7,9 +7,9 @@ use std::sync::Arc;
use sha2::Digest;
use crate::index_controller::{IndexMetadata, IndexSettings};
use crate::index_controller::IndexController;
use crate::index::Settings;
use crate::index_controller::IndexController;
use crate::index_controller::{IndexMetadata, IndexSettings};
use crate::option::Opt;
#[derive(Clone)]
@ -72,7 +72,11 @@ impl Data {
api_keys.generate_missing_api_keys();
let inner = DataInner { index_controller, options, api_keys };
let inner = DataInner {
index_controller,
options,
api_keys,
};
let inner = Arc::new(inner);
Ok(Data { inner })
@ -90,7 +94,11 @@ impl Data {
self.index_controller.get_index(uid).await
}
pub async fn create_index(&self, uid: String, primary_key: Option<String>) -> anyhow::Result<IndexMetadata> {
pub async fn create_index(
&self,
uid: String,
primary_key: Option<String>,
) -> anyhow::Result<IndexMetadata> {
let settings = IndexSettings {
uid: Some(uid),
primary_key,

View File

@ -1,7 +1,7 @@
use serde_json::{Map, Value};
use crate::index::{SearchQuery, SearchResult};
use super::Data;
use crate::index::{SearchQuery, SearchResult};
impl Data {
pub async fn search(
@ -19,7 +19,9 @@ impl Data {
limit: usize,
attributes_to_retrieve: Option<Vec<String>>,
) -> anyhow::Result<Vec<Map<String, Value>>> {
self.index_controller.documents(index, offset, limit, attributes_to_retrieve).await
self.index_controller
.documents(index, offset, limit, attributes_to_retrieve)
.await
}
pub async fn retrieve_document(
@ -27,8 +29,9 @@ impl Data {
index: String,
document_id: String,
attributes_to_retrieve: Option<Vec<String>>,
) -> anyhow::Result<Map<String, Value>>
{
self.index_controller.document(index, document_id, attributes_to_retrieve).await
) -> anyhow::Result<Map<String, Value>> {
self.index_controller
.document(index, document_id, attributes_to_retrieve)
.await
}
}

View File

@ -1,10 +1,9 @@
use milli::update::{IndexDocumentsMethod, UpdateFormat};
use actix_web::web::Payload;
use milli::update::{IndexDocumentsMethod, UpdateFormat};
use crate::index_controller::{IndexMetadata, IndexSettings, UpdateStatus};
use crate::index::Settings;
use super::Data;
use crate::index::Settings;
use crate::index_controller::{IndexMetadata, IndexSettings, UpdateStatus};
impl Data {
pub async fn add_documents(
@ -14,9 +13,11 @@ impl Data {
format: UpdateFormat,
stream: Payload,
primary_key: Option<String>,
) -> anyhow::Result<UpdateStatus>
{
let update_status = self.index_controller.add_documents(index, method, format, stream, primary_key).await?;
) -> anyhow::Result<UpdateStatus> {
let update_status = self
.index_controller
.add_documents(index, method, format, stream, primary_key)
.await?;
Ok(update_status)
}
@ -26,14 +27,14 @@ impl Data {
settings: Settings,
create: bool,
) -> anyhow::Result<UpdateStatus> {
let update = self.index_controller.update_settings(index, settings, create).await?;
let update = self
.index_controller
.update_settings(index, settings, create)
.await?;
Ok(update)
}
pub async fn clear_documents(
&self,
index: String,
) -> anyhow::Result<UpdateStatus> {
pub async fn clear_documents(&self, index: String) -> anyhow::Result<UpdateStatus> {
let update = self.index_controller.clear_documents(index).await?;
Ok(update)
}
@ -43,14 +44,14 @@ impl Data {
index: String,
document_ids: Vec<String>,
) -> anyhow::Result<UpdateStatus> {
let update = self.index_controller.delete_documents(index, document_ids).await?;
let update = self
.index_controller
.delete_documents(index, document_ids)
.await?;
Ok(update)
}
pub async fn delete_index(
&self,
index: String,
) -> anyhow::Result<()> {
pub async fn delete_index(&self, index: String) -> anyhow::Result<()> {
self.index_controller.delete_index(index).await?;
Ok(())
}
@ -67,7 +68,7 @@ impl Data {
&self,
uid: String,
primary_key: Option<String>,
new_uid: Option<String>
new_uid: Option<String>,
) -> anyhow::Result<IndexMetadata> {
let settings = IndexSettings {
uid: new_uid,