2021-08-30 21:37:13 +08:00
|
|
|
use std::collections::{BTreeMap, BTreeSet};
|
2021-05-10 23:30:09 +08:00
|
|
|
use std::marker::PhantomData;
|
2021-05-12 23:04:24 +08:00
|
|
|
use std::num::NonZeroUsize;
|
2021-03-04 18:56:32 +08:00
|
|
|
|
2021-06-23 16:41:55 +08:00
|
|
|
use log::{debug, info, trace};
|
2021-09-15 00:39:02 +08:00
|
|
|
use milli::documents::DocumentBatchReader;
|
|
|
|
use milli::update::{IndexDocumentsMethod, Setting, UpdateBuilder};
|
2021-05-12 23:04:24 +08:00
|
|
|
use serde::{Deserialize, Serialize, Serializer};
|
2021-09-15 00:39:02 +08:00
|
|
|
use uuid::Uuid;
|
2021-03-04 18:56:32 +08:00
|
|
|
|
2021-09-24 17:53:11 +08:00
|
|
|
use crate::index_controller::updates::status::{Failed, Processed, Processing, UpdateResult};
|
2021-09-29 04:22:59 +08:00
|
|
|
use crate::Update;
|
2021-05-11 02:22:18 +08:00
|
|
|
|
2021-09-24 17:53:11 +08:00
|
|
|
use super::error::{IndexError, Result};
|
2021-09-29 04:22:59 +08:00
|
|
|
use super::{Index, IndexMeta};
|
2021-05-11 02:48:06 +08:00
|
|
|
|
2021-06-15 03:26:35 +08:00
|
|
|
fn serialize_with_wildcard<S>(
|
2021-08-25 02:55:29 +08:00
|
|
|
field: &Setting<Vec<String>>,
|
2021-06-15 03:26:35 +08:00
|
|
|
s: S,
|
|
|
|
) -> std::result::Result<S::Ok, S::Error>
|
2021-05-12 23:04:24 +08:00
|
|
|
where
|
|
|
|
S: Serializer,
|
|
|
|
{
|
|
|
|
let wildcard = vec!["*".to_string()];
|
2021-08-25 02:55:29 +08:00
|
|
|
match field {
|
|
|
|
Setting::Set(value) => Some(value),
|
|
|
|
Setting::Reset => Some(&wildcard),
|
|
|
|
Setting::NotSet => None,
|
|
|
|
}
|
|
|
|
.serialize(s)
|
2021-05-12 23:04:24 +08:00
|
|
|
}
|
2021-03-04 18:56:32 +08:00
|
|
|
|
2021-06-02 02:15:51 +08:00
|
|
|
#[derive(Clone, Default, Debug, Serialize)]
|
2021-05-10 23:30:09 +08:00
|
|
|
pub struct Checked;
|
2021-08-25 02:55:29 +08:00
|
|
|
|
2021-06-02 02:15:51 +08:00
|
|
|
#[derive(Clone, Default, Debug, Serialize, Deserialize)]
|
2021-05-10 23:30:09 +08:00
|
|
|
pub struct Unchecked;
|
|
|
|
|
2021-09-22 21:07:04 +08:00
|
|
|
/// Holds all the settings for an index. `T` can either be `Checked` if they represents settings
|
|
|
|
/// whose validity is guaranteed, or `Unchecked` if they need to be validated. In the later case, a
|
|
|
|
/// call to `check` will return a `Settings<Checked>` from a `Settings<Unchecked>`.
|
2021-03-04 18:56:32 +08:00
|
|
|
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
|
|
|
#[serde(deny_unknown_fields)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
2021-06-02 02:15:51 +08:00
|
|
|
#[serde(bound(serialize = "T: Serialize", deserialize = "T: Deserialize<'static>"))]
|
2021-05-10 23:30:09 +08:00
|
|
|
pub struct Settings<T> {
|
2021-03-04 18:56:32 +08:00
|
|
|
#[serde(
|
|
|
|
default,
|
2021-05-12 23:04:24 +08:00
|
|
|
serialize_with = "serialize_with_wildcard",
|
2021-08-25 02:55:29 +08:00
|
|
|
skip_serializing_if = "Setting::is_not_set"
|
2021-03-04 18:56:32 +08:00
|
|
|
)]
|
2021-08-25 02:55:29 +08:00
|
|
|
pub displayed_attributes: Setting<Vec<String>>,
|
2021-03-04 18:56:32 +08:00
|
|
|
|
|
|
|
#[serde(
|
|
|
|
default,
|
2021-05-12 23:04:24 +08:00
|
|
|
serialize_with = "serialize_with_wildcard",
|
2021-08-25 02:55:29 +08:00
|
|
|
skip_serializing_if = "Setting::is_not_set"
|
2021-06-03 20:19:56 +08:00
|
|
|
)]
|
2021-08-25 02:55:29 +08:00
|
|
|
pub searchable_attributes: Setting<Vec<String>>,
|
|
|
|
|
|
|
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
2021-08-25 16:17:33 +08:00
|
|
|
pub filterable_attributes: Setting<BTreeSet<String>>,
|
2021-08-25 02:55:29 +08:00
|
|
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
2021-08-26 17:06:04 +08:00
|
|
|
pub sortable_attributes: Setting<BTreeSet<String>>,
|
2021-08-24 21:46:14 +08:00
|
|
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
2021-08-25 02:55:29 +08:00
|
|
|
pub ranking_rules: Setting<Vec<String>>,
|
|
|
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
|
|
|
pub stop_words: Setting<BTreeSet<String>>,
|
|
|
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
|
|
|
pub synonyms: Setting<BTreeMap<String, Vec<String>>>,
|
|
|
|
#[serde(default, skip_serializing_if = "Setting::is_not_set")]
|
|
|
|
pub distinct_attribute: Setting<String>,
|
2021-05-10 23:30:09 +08:00
|
|
|
|
|
|
|
#[serde(skip)]
|
|
|
|
pub _kind: PhantomData<T>,
|
2021-03-04 18:56:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-10 23:30:09 +08:00
|
|
|
impl Settings<Checked> {
|
|
|
|
pub fn cleared() -> Settings<Checked> {
|
|
|
|
Settings {
|
2021-08-25 02:55:29 +08:00
|
|
|
displayed_attributes: Setting::Reset,
|
|
|
|
searchable_attributes: Setting::Reset,
|
|
|
|
filterable_attributes: Setting::Reset,
|
2021-08-24 21:46:14 +08:00
|
|
|
sortable_attributes: Setting::Reset,
|
2021-08-25 02:55:29 +08:00
|
|
|
ranking_rules: Setting::Reset,
|
|
|
|
stop_words: Setting::Reset,
|
|
|
|
synonyms: Setting::Reset,
|
|
|
|
distinct_attribute: Setting::Reset,
|
2021-05-10 23:30:09 +08:00
|
|
|
_kind: PhantomData,
|
2021-03-04 18:56:32 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-27 20:30:20 +08:00
|
|
|
|
|
|
|
pub fn into_unchecked(self) -> Settings<Unchecked> {
|
|
|
|
let Self {
|
|
|
|
displayed_attributes,
|
|
|
|
searchable_attributes,
|
2021-06-04 05:47:16 +08:00
|
|
|
filterable_attributes,
|
2021-08-24 21:46:14 +08:00
|
|
|
sortable_attributes,
|
2021-05-27 20:30:20 +08:00
|
|
|
ranking_rules,
|
|
|
|
stop_words,
|
2021-06-03 20:19:56 +08:00
|
|
|
synonyms,
|
2021-05-27 20:30:20 +08:00
|
|
|
distinct_attribute,
|
|
|
|
..
|
|
|
|
} = self;
|
|
|
|
|
|
|
|
Settings {
|
|
|
|
displayed_attributes,
|
|
|
|
searchable_attributes,
|
2021-06-04 05:47:16 +08:00
|
|
|
filterable_attributes,
|
2021-08-24 21:46:14 +08:00
|
|
|
sortable_attributes,
|
2021-05-27 20:30:20 +08:00
|
|
|
ranking_rules,
|
|
|
|
stop_words,
|
2021-06-03 20:19:56 +08:00
|
|
|
synonyms,
|
2021-05-27 20:30:20 +08:00
|
|
|
distinct_attribute,
|
|
|
|
_kind: PhantomData,
|
|
|
|
}
|
|
|
|
}
|
2021-03-04 18:56:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-10 23:30:09 +08:00
|
|
|
impl Settings<Unchecked> {
|
2021-08-25 02:55:29 +08:00
|
|
|
pub fn check(self) -> Settings<Checked> {
|
|
|
|
let displayed_attributes = match self.displayed_attributes {
|
|
|
|
Setting::Set(fields) => {
|
2021-05-11 00:22:41 +08:00
|
|
|
if fields.iter().any(|f| f == "*") {
|
2021-08-25 02:55:29 +08:00
|
|
|
Setting::Reset
|
2021-05-11 00:22:41 +08:00
|
|
|
} else {
|
2021-08-25 02:55:29 +08:00
|
|
|
Setting::Set(fields)
|
2021-05-11 00:22:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
otherwise => otherwise,
|
|
|
|
};
|
|
|
|
|
2021-08-25 02:55:29 +08:00
|
|
|
let searchable_attributes = match self.searchable_attributes {
|
|
|
|
Setting::Set(fields) => {
|
2021-05-11 00:22:41 +08:00
|
|
|
if fields.iter().any(|f| f == "*") {
|
2021-08-25 02:55:29 +08:00
|
|
|
Setting::Reset
|
2021-05-11 00:22:41 +08:00
|
|
|
} else {
|
2021-08-25 02:55:29 +08:00
|
|
|
Setting::Set(fields)
|
2021-05-11 00:22:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
otherwise => otherwise,
|
|
|
|
};
|
|
|
|
|
|
|
|
Settings {
|
|
|
|
displayed_attributes,
|
|
|
|
searchable_attributes,
|
2021-06-04 05:47:16 +08:00
|
|
|
filterable_attributes: self.filterable_attributes,
|
2021-08-24 21:46:14 +08:00
|
|
|
sortable_attributes: self.sortable_attributes,
|
2021-05-11 00:22:41 +08:00
|
|
|
ranking_rules: self.ranking_rules,
|
|
|
|
stop_words: self.stop_words,
|
2021-06-03 20:19:56 +08:00
|
|
|
synonyms: self.synonyms,
|
2021-05-11 00:22:41 +08:00
|
|
|
distinct_attribute: self.distinct_attribute,
|
|
|
|
_kind: PhantomData,
|
|
|
|
}
|
2021-05-10 23:30:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-04 18:56:32 +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>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Index {
|
2021-09-24 17:53:11 +08:00
|
|
|
pub fn handle_update(&self, update: Processing) -> std::result::Result<Processed, Failed> {
|
2021-09-24 20:55:57 +08:00
|
|
|
let update_id = update.id();
|
|
|
|
let update_builder = self.update_handler.update_builder(update_id);
|
|
|
|
let result = (|| {
|
|
|
|
let mut txn = self.write_txn()?;
|
|
|
|
let result = match update.meta() {
|
2021-09-29 04:22:59 +08:00
|
|
|
Update::DocumentAddition {
|
|
|
|
primary_key,
|
|
|
|
content_uuid,
|
|
|
|
method,
|
|
|
|
} => self.update_documents(
|
|
|
|
&mut txn,
|
|
|
|
*method,
|
|
|
|
*content_uuid,
|
|
|
|
update_builder,
|
|
|
|
primary_key.as_deref(),
|
|
|
|
),
|
2021-09-29 02:20:13 +08:00
|
|
|
Update::Settings(settings) => {
|
2021-09-24 20:55:57 +08:00
|
|
|
let settings = settings.clone().check();
|
|
|
|
self.update_settings(&mut txn, &settings, update_builder)
|
2021-09-29 04:22:59 +08:00
|
|
|
}
|
2021-09-29 02:20:13 +08:00
|
|
|
Update::ClearDocuments => {
|
2021-09-24 21:21:07 +08:00
|
|
|
let builder = update_builder.clear_documents(&mut txn, self);
|
|
|
|
let _count = builder.execute()?;
|
|
|
|
Ok(UpdateResult::Other)
|
2021-09-29 04:22:59 +08:00
|
|
|
}
|
2021-09-29 02:20:13 +08:00
|
|
|
Update::DeleteDocuments(ids) => {
|
2021-09-24 21:21:07 +08:00
|
|
|
let mut builder = update_builder.delete_documents(&mut txn, self)?;
|
|
|
|
|
|
|
|
// We ignore unexisting document ids
|
|
|
|
ids.iter().for_each(|id| {
|
|
|
|
builder.delete_external_id(id);
|
|
|
|
});
|
|
|
|
|
|
|
|
let deleted = builder.execute()?;
|
|
|
|
Ok(UpdateResult::DocumentDeletion { deleted })
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
};
|
2021-09-30 17:08:41 +08:00
|
|
|
if result.is_ok() {
|
|
|
|
txn.commit()?;
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
result
|
|
|
|
})();
|
|
|
|
|
2021-09-29 18:02:27 +08:00
|
|
|
if let Update::DocumentAddition { content_uuid, .. } = update.from.meta() {
|
|
|
|
let _ = self.update_file_store.delete(*content_uuid);
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:55:57 +08:00
|
|
|
match result {
|
|
|
|
Ok(result) => Ok(update.process(result)),
|
|
|
|
Err(e) => Err(update.fail(e)),
|
|
|
|
}
|
2021-09-24 17:53:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn update_primary_key(&self, primary_key: Option<String>) -> Result<IndexMeta> {
|
|
|
|
match primary_key {
|
|
|
|
Some(primary_key) => {
|
|
|
|
let mut txn = self.write_txn()?;
|
|
|
|
if self.primary_key(&txn)?.is_some() {
|
|
|
|
return Err(IndexError::ExistingPrimaryKey);
|
|
|
|
}
|
|
|
|
let mut builder = UpdateBuilder::new(0).settings(&mut txn, self);
|
|
|
|
builder.set_primary_key(primary_key);
|
|
|
|
builder.execute(|_, _| ())?;
|
|
|
|
let meta = IndexMeta::new_txn(self, &txn)?;
|
|
|
|
txn.commit()?;
|
|
|
|
Ok(meta)
|
|
|
|
}
|
|
|
|
None => {
|
|
|
|
let meta = IndexMeta::new(self)?;
|
|
|
|
Ok(meta)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-24 20:55:57 +08:00
|
|
|
fn update_documents<'a, 'b>(
|
2021-05-12 22:21:37 +08:00
|
|
|
&'a self,
|
|
|
|
txn: &mut heed::RwTxn<'a, 'b>,
|
|
|
|
method: IndexDocumentsMethod,
|
2021-09-15 00:39:02 +08:00
|
|
|
content_uuid: Uuid,
|
2021-05-12 22:21:37 +08:00
|
|
|
update_builder: UpdateBuilder,
|
|
|
|
primary_key: Option<&str>,
|
2021-06-15 03:26:35 +08:00
|
|
|
) -> Result<UpdateResult> {
|
2021-06-23 16:41:55 +08:00
|
|
|
trace!("performing document addition");
|
2021-03-04 18:56:32 +08:00
|
|
|
|
|
|
|
// Set the primary key if not set already, ignore if already set.
|
2021-06-16 23:15:56 +08:00
|
|
|
if let (None, Some(primary_key)) = (self.primary_key(txn)?, primary_key) {
|
2021-07-30 00:14:36 +08:00
|
|
|
let mut builder = UpdateBuilder::new(0).settings(txn, self);
|
2021-06-16 23:15:56 +08:00
|
|
|
builder.set_primary_key(primary_key.to_string());
|
2021-06-17 20:36:32 +08:00
|
|
|
builder.execute(|_, _| ())?;
|
2021-03-04 18:56:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-31 22:40:59 +08:00
|
|
|
let indexing_callback =
|
2021-06-23 16:41:55 +08:00
|
|
|
|indexing_step, update_id| debug!("update {}: {:?}", update_id, indexing_step);
|
2021-05-25 22:33:09 +08:00
|
|
|
|
2021-09-15 00:39:02 +08:00
|
|
|
let content_file = self.update_file_store.get_update(content_uuid).unwrap();
|
|
|
|
let reader = DocumentBatchReader::from_reader(content_file).unwrap();
|
|
|
|
|
|
|
|
let mut builder = update_builder.index_documents(txn, self);
|
|
|
|
builder.index_documents_method(method);
|
|
|
|
let addition = builder.execute(reader, indexing_callback)?;
|
2021-03-04 18:56:32 +08:00
|
|
|
|
2021-05-12 22:21:37 +08:00
|
|
|
info!("document addition done: {:?}", addition);
|
2021-03-04 18:56:32 +08:00
|
|
|
|
2021-05-12 22:21:37 +08:00
|
|
|
Ok(UpdateResult::DocumentsAddition(addition))
|
2021-03-04 18:56:32 +08:00
|
|
|
}
|
|
|
|
|
2021-09-24 20:55:57 +08:00
|
|
|
fn update_settings<'a, 'b>(
|
|
|
|
&'a self,
|
|
|
|
txn: &mut heed::RwTxn<'a, 'b>,
|
|
|
|
settings: &Settings<Checked>,
|
|
|
|
update_builder: UpdateBuilder,
|
|
|
|
) -> Result<UpdateResult> {
|
|
|
|
// We must use the write transaction of the update here.
|
|
|
|
let mut builder = update_builder.settings(txn, self);
|
2021-09-15 00:39:02 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
apply_settings_to_builder(settings, &mut builder);
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
builder.execute(|indexing_step, update_id| {
|
|
|
|
debug!("update {}: {:?}", update_id, indexing_step)
|
|
|
|
})?;
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
Ok(UpdateResult::Other)
|
|
|
|
}
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-29 04:22:59 +08:00
|
|
|
pub fn apply_settings_to_builder(
|
|
|
|
settings: &Settings<Checked>,
|
|
|
|
builder: &mut milli::update::Settings,
|
|
|
|
) {
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.searchable_attributes {
|
|
|
|
Setting::Set(ref names) => builder.set_searchable_fields(names.clone()),
|
|
|
|
Setting::Reset => builder.reset_searchable_fields(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.displayed_attributes {
|
|
|
|
Setting::Set(ref names) => builder.set_displayed_fields(names.clone()),
|
|
|
|
Setting::Reset => builder.reset_displayed_fields(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.filterable_attributes {
|
|
|
|
Setting::Set(ref facets) => {
|
|
|
|
builder.set_filterable_fields(facets.clone().into_iter().collect())
|
2021-09-24 20:55:57 +08:00
|
|
|
}
|
2021-09-28 17:59:55 +08:00
|
|
|
Setting::Reset => builder.reset_filterable_fields(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.sortable_attributes {
|
2021-09-29 04:22:59 +08:00
|
|
|
Setting::Set(ref fields) => builder.set_sortable_fields(fields.iter().cloned().collect()),
|
2021-09-28 17:59:55 +08:00
|
|
|
Setting::Reset => builder.reset_sortable_fields(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.ranking_rules {
|
|
|
|
Setting::Set(ref criteria) => builder.set_criteria(criteria.clone()),
|
|
|
|
Setting::Reset => builder.reset_criteria(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.stop_words {
|
|
|
|
Setting::Set(ref stop_words) => builder.set_stop_words(stop_words.clone()),
|
|
|
|
Setting::Reset => builder.reset_stop_words(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
2021-09-24 20:55:57 +08:00
|
|
|
|
2021-09-28 17:59:55 +08:00
|
|
|
match settings.synonyms {
|
2021-09-29 04:22:59 +08:00
|
|
|
Setting::Set(ref synonyms) => builder.set_synonyms(synonyms.clone().into_iter().collect()),
|
2021-09-28 17:59:55 +08:00
|
|
|
Setting::Reset => builder.reset_synonyms(),
|
|
|
|
Setting::NotSet => (),
|
|
|
|
}
|
|
|
|
|
|
|
|
match settings.distinct_attribute {
|
|
|
|
Setting::Set(ref attr) => builder.set_distinct_field(attr.clone()),
|
|
|
|
Setting::Reset => builder.reset_distinct_field(),
|
|
|
|
Setting::NotSet => (),
|
2021-09-24 20:55:57 +08:00
|
|
|
}
|
2021-03-04 18:56:32 +08:00
|
|
|
}
|
2021-05-11 00:34:25 +08:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_setting_check() {
|
|
|
|
// test no changes
|
|
|
|
let settings = Settings {
|
2021-08-25 02:55:29 +08:00
|
|
|
displayed_attributes: Setting::Set(vec![String::from("hello")]),
|
|
|
|
searchable_attributes: Setting::Set(vec![String::from("hello")]),
|
|
|
|
filterable_attributes: Setting::NotSet,
|
2021-08-24 21:46:14 +08:00
|
|
|
sortable_attributes: Setting::NotSet,
|
2021-08-25 02:55:29 +08:00
|
|
|
ranking_rules: Setting::NotSet,
|
|
|
|
stop_words: Setting::NotSet,
|
|
|
|
synonyms: Setting::NotSet,
|
|
|
|
distinct_attribute: Setting::NotSet,
|
2021-05-11 00:34:25 +08:00
|
|
|
_kind: PhantomData::<Unchecked>,
|
|
|
|
};
|
|
|
|
|
|
|
|
let checked = settings.clone().check();
|
|
|
|
assert_eq!(settings.displayed_attributes, checked.displayed_attributes);
|
2021-05-12 23:04:24 +08:00
|
|
|
assert_eq!(
|
|
|
|
settings.searchable_attributes,
|
|
|
|
checked.searchable_attributes
|
|
|
|
);
|
2021-05-11 00:34:25 +08:00
|
|
|
|
|
|
|
// test wildcard
|
|
|
|
// test no changes
|
|
|
|
let settings = Settings {
|
2021-08-25 02:55:29 +08:00
|
|
|
displayed_attributes: Setting::Set(vec![String::from("*")]),
|
|
|
|
searchable_attributes: Setting::Set(vec![String::from("hello"), String::from("*")]),
|
|
|
|
filterable_attributes: Setting::NotSet,
|
2021-08-24 21:46:14 +08:00
|
|
|
sortable_attributes: Setting::NotSet,
|
2021-08-25 02:55:29 +08:00
|
|
|
ranking_rules: Setting::NotSet,
|
|
|
|
stop_words: Setting::NotSet,
|
|
|
|
synonyms: Setting::NotSet,
|
|
|
|
distinct_attribute: Setting::NotSet,
|
2021-05-11 00:34:25 +08:00
|
|
|
_kind: PhantomData::<Unchecked>,
|
|
|
|
};
|
|
|
|
|
|
|
|
let checked = settings.check();
|
2021-08-25 02:55:29 +08:00
|
|
|
assert_eq!(checked.displayed_attributes, Setting::Reset);
|
|
|
|
assert_eq!(checked.searchable_attributes, Setting::Reset);
|
2021-05-11 00:34:25 +08:00
|
|
|
}
|
|
|
|
}
|