mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-04 20:37:15 +02:00
Rename MeiliDB into MeiliSearch
This commit is contained in:
parent
58eaf78dc4
commit
7cc096e0a2
94 changed files with 126 additions and 126 deletions
3
meilisearch-http/src/models/mod.rs
Normal file
3
meilisearch-http/src/models/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub mod schema;
|
||||
pub mod token;
|
||||
pub mod update_operation;
|
118
meilisearch-http/src/models/schema.rs
Normal file
118
meilisearch-http/src/models/schema.rs
Normal file
|
@ -0,0 +1,118 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use indexmap::IndexMap;
|
||||
use meilisearch_schema::{Schema, SchemaBuilder, SchemaProps};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum FieldProperties {
|
||||
Identifier,
|
||||
Indexed,
|
||||
Displayed,
|
||||
Ranked,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct SchemaBody(IndexMap<String, HashSet<FieldProperties>>);
|
||||
|
||||
impl From<Schema> for SchemaBody {
|
||||
fn from(value: Schema) -> SchemaBody {
|
||||
let mut map = IndexMap::new();
|
||||
for (name, _attr, props) in value.iter() {
|
||||
let old_properties = map.entry(name.to_owned()).or_insert(HashSet::new());
|
||||
if props.is_indexed() {
|
||||
old_properties.insert(FieldProperties::Indexed);
|
||||
}
|
||||
if props.is_displayed() {
|
||||
old_properties.insert(FieldProperties::Displayed);
|
||||
}
|
||||
if props.is_ranked() {
|
||||
old_properties.insert(FieldProperties::Ranked);
|
||||
}
|
||||
}
|
||||
let old_properties = map
|
||||
.entry(value.identifier_name().to_string())
|
||||
.or_insert(HashSet::new());
|
||||
old_properties.insert(FieldProperties::Identifier);
|
||||
old_properties.insert(FieldProperties::Displayed);
|
||||
SchemaBody(map)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Schema> for SchemaBody {
|
||||
fn into(self) -> Schema {
|
||||
let mut identifier = "documentId".to_string();
|
||||
let mut attributes = IndexMap::new();
|
||||
for (field, properties) in self.0 {
|
||||
let mut indexed = false;
|
||||
let mut displayed = false;
|
||||
let mut ranked = false;
|
||||
for property in properties {
|
||||
match property {
|
||||
FieldProperties::Indexed => indexed = true,
|
||||
FieldProperties::Displayed => displayed = true,
|
||||
FieldProperties::Ranked => ranked = true,
|
||||
FieldProperties::Identifier => identifier = field.clone(),
|
||||
}
|
||||
}
|
||||
attributes.insert(
|
||||
field,
|
||||
SchemaProps {
|
||||
indexed,
|
||||
displayed,
|
||||
ranked,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let mut builder = SchemaBuilder::with_identifier(identifier);
|
||||
for (field, props) in attributes {
|
||||
builder.new_attribute(field, props);
|
||||
}
|
||||
builder.build()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_schema_body_conversion() {
|
||||
let schema_body = r#"
|
||||
{
|
||||
"id": ["identifier", "indexed", "displayed"],
|
||||
"title": ["indexed", "displayed"],
|
||||
"date": ["displayed"]
|
||||
}
|
||||
"#;
|
||||
|
||||
let schema_builder = r#"
|
||||
{
|
||||
"identifier": "id",
|
||||
"attributes": {
|
||||
"id": {
|
||||
"indexed": true,
|
||||
"displayed": true
|
||||
},
|
||||
"title": {
|
||||
"indexed": true,
|
||||
"displayed": true
|
||||
},
|
||||
"date": {
|
||||
"displayed": true
|
||||
}
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
let schema_body: SchemaBody = serde_json::from_str(schema_body).unwrap();
|
||||
let schema_builder: SchemaBuilder = serde_json::from_str(schema_builder).unwrap();
|
||||
|
||||
let schema_from_body: Schema = schema_body.into();
|
||||
let schema_from_builder: Schema = schema_builder.build();
|
||||
|
||||
assert_eq!(schema_from_body, schema_from_builder);
|
||||
}
|
||||
}
|
72
meilisearch-http/src/models/token.rs
Normal file
72
meilisearch-http/src/models/token.rs
Normal file
|
@ -0,0 +1,72 @@
|
|||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const TOKEN_PREFIX_KEY: &str = "_token_";
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum ACL {
|
||||
IndexesRead,
|
||||
IndexesWrite,
|
||||
DocumentsRead,
|
||||
DocumentsWrite,
|
||||
SettingsRead,
|
||||
SettingsWrite,
|
||||
Admin,
|
||||
#[serde(rename = "*")]
|
||||
All,
|
||||
}
|
||||
|
||||
pub type Wildcard = String;
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct Token {
|
||||
pub key: String,
|
||||
pub description: String,
|
||||
pub acl: Vec<ACL>,
|
||||
pub indexes: Vec<Wildcard>,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: DateTime<Utc>,
|
||||
pub expires_at: DateTime<Utc>,
|
||||
pub revoked: bool,
|
||||
}
|
||||
|
||||
fn cleanup_wildcard(input: &str) -> (bool, &str, bool) {
|
||||
let first = input.chars().next().filter(|&c| c == '*').is_some();
|
||||
let last = input.chars().last().filter(|&c| c == '*').is_some();
|
||||
let bound_last = std::cmp::max(input.len().saturating_sub(last as usize), first as usize);
|
||||
let output = input.get(first as usize..bound_last).unwrap();
|
||||
(first, output, last)
|
||||
}
|
||||
|
||||
pub fn match_wildcard(pattern: &str, input: &str) -> bool {
|
||||
let (first, pattern, last) = cleanup_wildcard(pattern);
|
||||
|
||||
match (first, last) {
|
||||
(false, false) => pattern == input,
|
||||
(true, false) => input.ends_with(pattern),
|
||||
(false, true) => input.starts_with(pattern),
|
||||
(true, true) => input.contains(pattern),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_match_wildcard() {
|
||||
assert!(match_wildcard("*", "qqq"));
|
||||
assert!(match_wildcard("*", ""));
|
||||
assert!(match_wildcard("*ab", "qqqab"));
|
||||
assert!(match_wildcard("*ab*", "qqqabqq"));
|
||||
assert!(match_wildcard("ab*", "abqqq"));
|
||||
assert!(match_wildcard("**", "ab"));
|
||||
assert!(match_wildcard("ab", "ab"));
|
||||
assert!(match_wildcard("ab*", "ab"));
|
||||
assert!(match_wildcard("*ab", "ab"));
|
||||
assert!(match_wildcard("*ab*", "ab"));
|
||||
assert!(match_wildcard("*😆*", "ab😆dsa"));
|
||||
}
|
||||
}
|
33
meilisearch-http/src/models/update_operation.rs
Normal file
33
meilisearch-http/src/models/update_operation.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
use std::fmt;
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug)]
|
||||
pub enum UpdateOperation {
|
||||
ClearAllDocuments,
|
||||
DocumentsAddition,
|
||||
DocumentsDeletion,
|
||||
SynonymsAddition,
|
||||
SynonymsDeletion,
|
||||
StopWordsAddition,
|
||||
StopWordsDeletion,
|
||||
Schema,
|
||||
Config,
|
||||
}
|
||||
|
||||
impl fmt::Display for UpdateOperation {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> std::fmt::Result {
|
||||
use UpdateOperation::*;
|
||||
|
||||
match self {
|
||||
ClearAllDocuments => write!(f, "ClearAllDocuments"),
|
||||
DocumentsAddition => write!(f, "DocumentsAddition"),
|
||||
DocumentsDeletion => write!(f, "DocumentsDeletion"),
|
||||
SynonymsAddition => write!(f, "SynonymsAddition"),
|
||||
SynonymsDeletion => write!(f, "SynonymsDelettion"),
|
||||
StopWordsAddition => write!(f, "StopWordsAddition"),
|
||||
StopWordsDeletion => write!(f, "StopWordsDeletion"),
|
||||
Schema => write!(f, "Schema"),
|
||||
Config => write!(f, "Config"),
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue