meilisearch/src/index_controller/mod.rs

106 lines
2.7 KiB
Rust
Raw Normal View History

2021-02-26 16:10:04 +08:00
pub mod actor_index_controller;
2021-02-02 02:51:47 +08:00
mod updates;
2021-01-14 00:50:36 +08:00
use std::collections::HashMap;
2021-01-28 21:12:34 +08:00
use std::num::NonZeroUsize;
2021-01-14 00:50:36 +08:00
use anyhow::Result;
2021-02-04 00:44:20 +08:00
use chrono::{DateTime, Utc};
2021-02-09 23:08:13 +08:00
use milli::update::{IndexDocumentsMethod, UpdateFormat, DocumentAdditionResult};
use serde::{Serialize, Deserialize, de::Deserializer};
use uuid::Uuid;
2021-02-02 02:51:47 +08:00
pub use updates::{Processed, Processing, Failed};
pub type UpdateStatus = updates::UpdateStatus<UpdateMeta, UpdateResult, String>;
2021-01-28 21:12:34 +08:00
2021-02-04 00:44:20 +08:00
#[derive(Debug, Serialize, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IndexMetadata {
uuid: Uuid,
created_at: DateTime<Utc>,
updated_at: DateTime<Utc>,
2021-02-04 22:28:52 +08:00
primary_key: Option<String>,
2021-02-04 00:44:20 +08:00
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(tag = "type")]
pub enum UpdateMeta {
2021-02-13 19:22:59 +08:00
DocumentsAddition {
method: IndexDocumentsMethod,
format: UpdateFormat,
primary_key: Option<String>,
},
ClearDocuments,
2021-02-13 00:39:14 +08:00
DeleteDocuments,
Settings(Settings),
Facets(Facets),
2021-01-14 00:50:36 +08:00
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Facets {
pub level_group_size: Option<NonZeroUsize>,
pub min_level_size: Option<NonZeroUsize>,
2021-01-14 00:50:36 +08:00
}
fn deserialize_some<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where T: Deserialize<'de>,
D: Deserializer<'de>
{
Deserialize::deserialize(deserializer).map(Some)
2021-01-14 00:50:36 +08:00
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
#[serde(rename_all = "camelCase")]
pub struct Settings {
#[serde(
default,
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none",
)]
pub displayed_attributes: Option<Option<Vec<String>>>,
#[serde(
default,
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none",
)]
pub searchable_attributes: Option<Option<Vec<String>>>,
#[serde(default)]
pub faceted_attributes: Option<Option<HashMap<String, String>>>,
#[serde(
default,
deserialize_with = "deserialize_some",
skip_serializing_if = "Option::is_none",
)]
pub criteria: Option<Option<Vec<String>>>,
2021-01-14 00:50:36 +08:00
}
impl Settings {
pub fn cleared() -> Self {
Self {
displayed_attributes: Some(None),
searchable_attributes: Some(None),
faceted_attributes: Some(None),
criteria: Some(None),
2021-01-14 00:50:36 +08:00
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum UpdateResult {
2021-01-28 21:12:34 +08:00
DocumentsAddition(DocumentAdditionResult),
2021-02-13 00:39:14 +08:00
DocumentDeletion { deleted: usize },
Other,
}
2021-01-14 00:50:36 +08:00
2021-02-09 23:08:13 +08:00
#[derive(Clone, Debug)]
pub struct IndexSettings {
pub name: Option<String>,
pub primary_key: Option<String>,
}