mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-22 21:04:27 +01:00
Format code with cargo fmt
This commit is contained in:
parent
d01a3944c1
commit
45ded0498b
@ -1,9 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::RankedMap;
|
||||
use heed::Result as ZResult;
|
||||
use chrono::{DateTime, Utc};
|
||||
use heed::types::{ByteSlice, OwnedType, SerdeBincode, Str};
|
||||
use heed::Result as ZResult;
|
||||
use meilidb_schema::Schema;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
|
||||
const CREATED_AT: &str = "created-at";
|
||||
@ -32,30 +32,35 @@ impl Main {
|
||||
self.main.clear(writer)
|
||||
}
|
||||
|
||||
pub fn name(self, reader: &heed::RoTxn) -> ZResult<Option<String>> {
|
||||
Ok(self.main.get::<Str, Str>(reader, NAME)?.map(|name| name.to_owned()))
|
||||
}
|
||||
|
||||
pub fn put_name(self, writer: &mut heed::RwTxn, name: &str) -> ZResult<()> {
|
||||
self.main.put::<Str, Str>(writer, NAME, name)
|
||||
}
|
||||
|
||||
pub fn name(self, reader: &heed::RoTxn) -> ZResult<Option<String>> {
|
||||
Ok(self
|
||||
.main
|
||||
.get::<Str, Str>(reader, NAME)?
|
||||
.map(|name| name.to_owned()))
|
||||
}
|
||||
|
||||
pub fn put_created_at(self, writer: &mut heed::RwTxn) -> ZResult<()> {
|
||||
self.main
|
||||
.put::<Str, SerdeDatetime>(writer, CREATED_AT, &Utc::now())
|
||||
}
|
||||
|
||||
pub fn created_at(self, reader: &heed::RoTxn) -> ZResult<Option<DateTime<Utc>>> {
|
||||
self.main.get::<Str, SerdeDatetime>(reader, CREATED_AT)
|
||||
}
|
||||
|
||||
pub fn put_created_at(self, writer: &mut heed::RwTxn) -> ZResult<()> {
|
||||
self.main.put::<Str, SerdeDatetime>(writer, CREATED_AT, &Utc::now())
|
||||
|
||||
pub fn put_updated_at(self, writer: &mut heed::RwTxn) -> ZResult<()> {
|
||||
self.main
|
||||
.put::<Str, SerdeDatetime>(writer, UPDATED_AT, &Utc::now())
|
||||
}
|
||||
|
||||
pub fn updated_at(self, reader: &heed::RoTxn) -> ZResult<Option<DateTime<Utc>>> {
|
||||
self.main.get::<Str, SerdeDatetime>(reader, UPDATED_AT)
|
||||
}
|
||||
|
||||
pub fn put_updated_at(self, writer: &mut heed::RwTxn) -> ZResult<()> {
|
||||
self.main.put::<Str, SerdeDatetime>(writer, UPDATED_AT, &Utc::now())
|
||||
}
|
||||
|
||||
pub fn put_words_fst(self, writer: &mut heed::RwTxn, fst: &fst::Set) -> ZResult<()> {
|
||||
let bytes = fst.as_fst().as_bytes();
|
||||
self.main.put::<Str, ByteSlice>(writer, WORDS_KEY, bytes)
|
||||
@ -148,7 +153,11 @@ impl Main {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put_fields_frequency(self, writer: &mut heed::RwTxn, fields_frequency: &FreqsMap) -> ZResult<()> {
|
||||
pub fn put_fields_frequency(
|
||||
self,
|
||||
writer: &mut heed::RwTxn,
|
||||
fields_frequency: &FreqsMap,
|
||||
) -> ZResult<()> {
|
||||
self.main
|
||||
.put::<Str, SerdeFreqsMap>(writer, FIELDS_FREQUENCY, fields_frequency)
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ use std::sync::Arc;
|
||||
use chrono::{DateTime, Utc};
|
||||
use heed::types::{SerdeBincode, Str};
|
||||
use log::*;
|
||||
use meilidb_core::{Database, MResult, Error as MError};
|
||||
use meilidb_core::{Database, Error as MError, MResult};
|
||||
use sysinfo::Pid;
|
||||
|
||||
use crate::option::Opt;
|
||||
@ -91,7 +91,10 @@ impl DataInner {
|
||||
.map(|(a, c)| (schema.attribute_name(a).to_owned(), c))
|
||||
.collect();
|
||||
|
||||
index.main.put_fields_frequency(&mut writer, &frequency).map_err(MError::Zlmdb)
|
||||
index
|
||||
.main
|
||||
.put_fields_frequency(&mut writer, &frequency)
|
||||
.map_err(MError::Zlmdb)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,11 +28,8 @@ fn generate_uid() -> String {
|
||||
|
||||
pub async fn list_indexes(ctx: Context<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(IndexesRead)?;
|
||||
|
||||
let indexes_uids = ctx
|
||||
.state()
|
||||
.db
|
||||
.indexes_uids();
|
||||
|
||||
let indexes_uids = ctx.state().db.indexes_uids();
|
||||
|
||||
let env = &ctx.state().db.env;
|
||||
let mut reader = env.read_txn().map_err(ResponseError::internal)?;
|
||||
@ -45,16 +42,22 @@ pub async fn list_indexes(ctx: Context<Data>) -> SResult<Response> {
|
||||
.db
|
||||
.open_index(&index_uid)
|
||||
.ok_or(ResponseError::internal(&index_uid))?;
|
||||
let name = index.main.name(&mut reader)
|
||||
let name = index
|
||||
.main
|
||||
.name(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Name not found"))?;
|
||||
let created_at = index.main.created_at(&mut reader)
|
||||
let created_at = index
|
||||
.main
|
||||
.created_at(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Created date not found"))?;
|
||||
let updated_at = index.main.updated_at(&mut reader)
|
||||
let updated_at = index
|
||||
.main
|
||||
.updated_at(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Updated date not found"))?;
|
||||
|
||||
|
||||
let index_reponse = IndexResponse {
|
||||
name,
|
||||
uid: index_uid,
|
||||
@ -85,13 +88,19 @@ pub async fn get_index(ctx: Context<Data>) -> SResult<Response> {
|
||||
let mut reader = env.read_txn().map_err(ResponseError::internal)?;
|
||||
|
||||
let uid = ctx.url_param("index")?.to_string();
|
||||
let name = index.main.name(&mut reader)
|
||||
let name = index
|
||||
.main
|
||||
.name(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Name not found"))?;
|
||||
let created_at = index.main.created_at(&mut reader)
|
||||
let created_at = index
|
||||
.main
|
||||
.created_at(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Created date not found"))?;
|
||||
let updated_at = index.main.updated_at(&mut reader)
|
||||
let updated_at = index
|
||||
.main
|
||||
.updated_at(&mut reader)
|
||||
.map_err(ResponseError::internal)?
|
||||
.ok_or(ResponseError::internal("Updated date not found"))?;
|
||||
|
||||
@ -165,7 +174,10 @@ struct IndexCreateResponse {
|
||||
pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
ctx.is_allowed(IndexesWrite)?;
|
||||
|
||||
let body = ctx.body_json::<IndexCreateRequest>().await.map_err(ResponseError::bad_request)?;
|
||||
let body = ctx
|
||||
.body_json::<IndexCreateRequest>()
|
||||
.await
|
||||
.map_err(ResponseError::bad_request)?;
|
||||
|
||||
let generated_uid = generate_uid();
|
||||
|
||||
@ -179,13 +191,16 @@ pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
let env = &db.env;
|
||||
let mut writer = env.write_txn().map_err(ResponseError::internal)?;
|
||||
|
||||
created_index.main
|
||||
created_index
|
||||
.main
|
||||
.put_name(&mut writer, &body.name)
|
||||
.map_err(ResponseError::internal)?;
|
||||
created_index.main
|
||||
created_index
|
||||
.main
|
||||
.put_created_at(&mut writer)
|
||||
.map_err(ResponseError::internal)?;
|
||||
created_index.main
|
||||
created_index
|
||||
.main
|
||||
.put_updated_at(&mut writer)
|
||||
.map_err(ResponseError::internal)?;
|
||||
|
||||
@ -193,8 +208,8 @@ pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
let mut response_update_id = None;
|
||||
if let Some(schema) = schema {
|
||||
let update_id = created_index
|
||||
.schema_update(&mut writer, schema.clone())
|
||||
.map_err(ResponseError::internal)?;
|
||||
.schema_update(&mut writer, schema.clone())
|
||||
.map_err(ResponseError::internal)?;
|
||||
response_update_id = Some(update_id)
|
||||
}
|
||||
|
||||
@ -210,8 +225,8 @@ pub async fn create_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
};
|
||||
|
||||
Ok(tide::response::json(response_body)
|
||||
.with_status(StatusCode::CREATED)
|
||||
.into_response())
|
||||
.with_status(StatusCode::CREATED)
|
||||
.into_response())
|
||||
}
|
||||
|
||||
pub async fn update_schema(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
|
@ -13,7 +13,8 @@ pub mod synonym;
|
||||
pub fn load_routes(app: &mut tide::App<Data>) {
|
||||
app.at("").nest(|router| {
|
||||
router.at("/indexes").nest(|router| {
|
||||
router.at("/")
|
||||
router
|
||||
.at("/")
|
||||
.get(index::list_indexes)
|
||||
.post(index::create_index);
|
||||
|
||||
|
@ -155,12 +155,7 @@ pub async fn search_multi_index(mut ctx: Context<Data>) -> SResult<Response> {
|
||||
|
||||
for index in index_list.clone() {
|
||||
if index == "*" {
|
||||
index_list = ctx
|
||||
.state()
|
||||
.db
|
||||
.indexes_uids()
|
||||
.into_iter()
|
||||
.collect();
|
||||
index_list = ctx.state().db.indexes_uids().into_iter().collect();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,15 +65,14 @@ pub async fn get_stats(ctx: Context<Data>) -> SResult<Response> {
|
||||
|
||||
let mut index_list = HashMap::new();
|
||||
|
||||
|
||||
let db = &ctx.state().db;
|
||||
let env = &db.env;
|
||||
let reader = env.read_txn().map_err(ResponseError::internal)?;
|
||||
let reader = env.read_txn().map_err(ResponseError::internal)?;
|
||||
|
||||
let indexes_set = ctx.state().db.indexes_uids();
|
||||
for index_uid in indexes_set {
|
||||
let index = db.open_index(&index_uid).unwrap();
|
||||
|
||||
|
||||
let number_of_documents = index
|
||||
.main
|
||||
.number_of_documents(&reader)
|
||||
|
Loading…
Reference in New Issue
Block a user