move identifier from settings to index; fix #470

This commit is contained in:
qdequele 2020-02-12 17:00:14 +01:00
parent dc9ca2ebc9
commit 4986adc186
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
8 changed files with 193 additions and 69 deletions

View File

@ -357,7 +357,7 @@ mod tests {
use crate::criterion::{self, CriteriaBuilder}; use crate::criterion::{self, CriteriaBuilder};
use crate::update::{ProcessedUpdateResult, UpdateStatus}; use crate::update::{ProcessedUpdateResult, UpdateStatus};
use crate::settings::Settings; use crate::settings::{Settings, SettingsUpdate, UpdateState};
use crate::{Document, DocumentId}; use crate::{Document, DocumentId};
use serde::de::IgnoredAny; use serde::de::IgnoredAny;
use std::sync::mpsc; use std::sync::mpsc;
@ -377,10 +377,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description"], "searchableAttributes": ["name", "description"],
"displayedAttributes": ["name", "description"] "displayedAttributes": ["name", "description"]
} }
@ -437,10 +448,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description"], "searchableAttributes": ["name", "description"],
"displayedAttributes": ["name", "description"] "displayedAttributes": ["name", "description"]
} }
@ -496,10 +518,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name"], "searchableAttributes": ["name"],
"displayedAttributes": ["name"] "displayedAttributes": ["name"]
} }
@ -548,10 +581,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description"], "searchableAttributes": ["name", "description"],
"displayedAttributes": ["name", "description"] "displayedAttributes": ["name", "description"]
} }
@ -588,7 +632,6 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description", "age", "sex"], "searchableAttributes": ["name", "description", "age", "sex"],
"displayedAttributes": ["name", "description", "age", "sex"] "displayedAttributes": ["name", "description", "age", "sex"]
} }
@ -655,7 +698,6 @@ mod tests {
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description", "city", "age", "sex"], "searchableAttributes": ["name", "description", "city", "age", "sex"],
"displayedAttributes": ["name", "description", "city", "age", "sex"] "displayedAttributes": ["name", "description", "city", "age", "sex"]
} }
@ -691,10 +733,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description"], "searchableAttributes": ["name", "description"],
"displayedAttributes": ["name", "description"] "displayedAttributes": ["name", "description"]
} }
@ -768,10 +821,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description"], "searchableAttributes": ["name", "description"],
"displayedAttributes": ["name", "description", "id"] "displayedAttributes": ["name", "description", "id"]
} }
@ -904,10 +968,21 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
"identifier": "id",
"searchableAttributes": ["name", "description"], "searchableAttributes": ["name", "description"],
"displayedAttributes": ["name", "description"] "displayedAttributes": ["name", "description"]
} }
@ -968,6 +1043,18 @@ mod tests {
database.set_update_callback(Box::new(update_fn)); database.set_update_callback(Box::new(update_fn));
let settings_update = SettingsUpdate{
identifier: UpdateState::Update("id".to_string()),
..SettingsUpdate::default()
};
let mut writer = db.update_write_txn().unwrap();
let update_id = index.settings_update(&mut writer, settings_update).unwrap();
writer.commit().unwrap();
// block until the transaction is processed
let _ = receiver.iter().find(|id| *id == update_id);
let settings = { let settings = {
let data = r#" let data = r#"
{ {
@ -980,7 +1067,6 @@ mod tests {
"_exact", "_exact",
"dsc(release_date)" "dsc(release_date)"
], ],
"identifier": "id",
"searchableAttributes": ["name", "release_date"], "searchableAttributes": ["name", "release_date"],
"displayedAttributes": ["name", "release_date"] "displayedAttributes": ["name", "release_date"]
} }

View File

@ -89,7 +89,7 @@ pub fn apply_settings_update(
must_reindex = true; must_reindex = true;
}, },
UpdateState::Nothing => (), UpdateState::Nothing => (),
}; }
match settings.displayed_attributes.clone() { match settings.displayed_attributes.clone() {
UpdateState::Update(v) => schema.update_displayed(v)?, UpdateState::Update(v) => schema.update_displayed(v)?,
UpdateState::Clear => { UpdateState::Clear => {
@ -97,11 +97,6 @@ pub fn apply_settings_update(
schema.update_displayed(clear)?; schema.update_displayed(clear)?;
}, },
UpdateState::Nothing => (), UpdateState::Nothing => (),
};
if let UpdateState::Update(v) = settings.identifier.clone() {
schema.set_identifier(v.as_ref())?;
must_reindex = true;
} }
index.main.put_schema(writer, &schema)?; index.main.put_schema(writer, &schema)?;
@ -130,9 +125,6 @@ pub fn apply_settings_update(
reindex_all_documents(writer, index)?; reindex_all_documents(writer, index)?;
} }
if let UpdateState::Clear = settings.identifier {
index.main.delete_schema(writer)?;
}
Ok(()) Ok(())
} }

View File

@ -1,7 +1,7 @@
use std::collections::{BTreeSet, HashSet}; use std::collections::{BTreeSet, HashSet};
use indexmap::IndexMap; use indexmap::IndexMap;
use meilisearch_core::settings::Settings; use meilisearch_core::settings::{SettingsUpdate, UpdateState};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_json::Value; use serde_json::Value;
use tide::{Request, Response}; use tide::{Request, Response};
@ -145,11 +145,11 @@ async fn update_multiple_documents(mut ctx: Request<Data>, is_partial: bool) ->
None => return Err(ResponseError::bad_request("Could not infer a schema")), None => return Err(ResponseError::bad_request("Could not infer a schema")),
}, },
}; };
let settings = Settings { let settings_update = SettingsUpdate{
identifier: Some(Some(id)), identifier: UpdateState::Update(id),
..Settings::default() ..SettingsUpdate::default()
}; };
index.settings_update(&mut update_writer, settings.into_update()?)?; index.settings_update(&mut update_writer, settings_update)?;
} }
let mut document_addition = if is_partial { let mut document_addition = if is_partial {

View File

@ -40,11 +40,17 @@ pub async fn list_indexes(ctx: Request<Data>) -> SResult<Response> {
let created_at = index.main.created_at(&reader)?.into_internal_error()?; let created_at = index.main.created_at(&reader)?.into_internal_error()?;
let updated_at = index.main.updated_at(&reader)?.into_internal_error()?; let updated_at = index.main.updated_at(&reader)?.into_internal_error()?;
let identifier = match index.main.schema(&reader) {
Ok(Some(schema)) => Some(schema.identifier().to_owned()),
_ => None
};
let index_response = IndexResponse { let index_response = IndexResponse {
name, name,
uid: index_uid, uid: index_uid,
created_at, created_at,
updated_at, updated_at,
identifier,
}; };
response_body.push(index_response); response_body.push(index_response);
} }
@ -65,6 +71,7 @@ struct IndexResponse {
uid: String, uid: String,
created_at: DateTime<Utc>, created_at: DateTime<Utc>,
updated_at: DateTime<Utc>, updated_at: DateTime<Utc>,
identifier: Option<String>,
} }
pub async fn get_index(ctx: Request<Data>) -> SResult<Response> { pub async fn get_index(ctx: Request<Data>) -> SResult<Response> {
@ -80,11 +87,17 @@ pub async fn get_index(ctx: Request<Data>) -> SResult<Response> {
let created_at = index.main.created_at(&reader)?.into_internal_error()?; let created_at = index.main.created_at(&reader)?.into_internal_error()?;
let updated_at = index.main.updated_at(&reader)?.into_internal_error()?; let updated_at = index.main.updated_at(&reader)?.into_internal_error()?;
let identifier = match index.main.schema(&reader) {
Ok(Some(schema)) => Some(schema.identifier().to_owned()),
_ => None
};
let response_body = IndexResponse { let response_body = IndexResponse {
name, name,
uid, uid,
created_at, created_at,
updated_at, updated_at,
identifier
}; };
Ok(tide::Response::new(200).body_json(&response_body)?) Ok(tide::Response::new(200).body_json(&response_body)?)
@ -105,6 +118,7 @@ struct IndexCreateResponse {
uid: String, uid: String,
created_at: DateTime<Utc>, created_at: DateTime<Utc>,
updated_at: DateTime<Utc>, updated_at: DateTime<Utc>,
identifier: Option<String>,
} }
pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> { pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
@ -150,7 +164,7 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
.updated_at(&writer)? .updated_at(&writer)?
.into_internal_error()?; .into_internal_error()?;
if let Some(id) = body.identifier { if let Some(id) = body.identifier.clone() {
created_index created_index
.main .main
.put_schema(&mut writer, &Schema::with_identifier(&id))?; .put_schema(&mut writer, &Schema::with_identifier(&id))?;
@ -163,6 +177,7 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
uid, uid,
created_at, created_at,
updated_at, updated_at,
identifier: body.identifier,
}; };
Ok(tide::Response::new(201).body_json(&response_body)?) Ok(tide::Response::new(201).body_json(&response_body)?)
@ -171,7 +186,8 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase", deny_unknown_fields)] #[serde(rename_all = "camelCase", deny_unknown_fields)]
struct UpdateIndexRequest { struct UpdateIndexRequest {
name: String, name: Option<String>,
identifier: Option<String>,
} }
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
@ -181,6 +197,7 @@ struct UpdateIndexResponse {
uid: String, uid: String,
created_at: DateTime<Utc>, created_at: DateTime<Utc>,
updated_at: DateTime<Utc>, updated_at: DateTime<Utc>,
identifier: Option<String>,
} }
pub async fn update_index(mut ctx: Request<Data>) -> SResult<Response> { pub async fn update_index(mut ctx: Request<Data>) -> SResult<Response> {
@ -197,21 +214,36 @@ pub async fn update_index(mut ctx: Request<Data>) -> SResult<Response> {
let db = &ctx.state().db; let db = &ctx.state().db;
let mut writer = db.main_write_txn()?; let mut writer = db.main_write_txn()?;
index.main.put_name(&mut writer, &body.name)?; if let Some(name) = body.name {
index.main.put_name(&mut writer, &name)?;
}
if let Some(identifier) = body.identifier {
if let Ok(Some(_)) = index.main.schema(&writer) {
return Err(ResponseError::bad_request("The index identifier cannot be updated"));
}
index.main.put_schema(&mut writer, &Schema::with_identifier(&identifier))?;
}
index.main.put_updated_at(&mut writer)?; index.main.put_updated_at(&mut writer)?;
writer.commit()?; writer.commit()?;
let reader = db.main_read_txn()?;
let reader = db.main_read_txn()?;
let name = index.main.name(&reader)?.into_internal_error()?;
let created_at = index.main.created_at(&reader)?.into_internal_error()?; let created_at = index.main.created_at(&reader)?.into_internal_error()?;
let updated_at = index.main.updated_at(&reader)?.into_internal_error()?; let updated_at = index.main.updated_at(&reader)?.into_internal_error()?;
let identifier = match index.main.schema(&reader) {
Ok(Some(schema)) => Some(schema.identifier().to_owned()),
_ => None
};
let response_body = UpdateIndexResponse { let response_body = UpdateIndexResponse {
name: body.name, name,
uid: index_uid, uid: index_uid,
created_at, created_at,
updated_at, updated_at,
identifier
}; };
Ok(tide::Response::new(200).body_json(&response_body)?) Ok(tide::Response::new(200).body_json(&response_body)?)

View File

@ -54,21 +54,36 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
let schema = index.main.schema(&reader)?; let schema = index.main.schema(&reader)?;
let identifier = schema.clone().map(|s| s.identifier().to_owned()); let searchable_attributes = schema.clone().map(|s| {
let searchable_attributes = schema let attrs = s.indexed_name()
.clone() .iter()
.map(|s| s.indexed_name().iter().map(|s| (*s).to_string()).collect()); .map(|s| (*s).to_string())
let displayed_attributes = schema .collect::<Vec<String>>();
.clone() if attrs.is_empty() {
.map(|s| s.displayed_name().iter().map(|s| (*s).to_string()).collect()); None
} else {
Some(attrs)
}
});
let displayed_attributes = schema.clone().map(|s| {
let attrs = s.displayed_name()
.iter()
.map(|s| (*s).to_string())
.collect::<HashSet<String>>();
if attrs.is_empty() {
None
} else {
Some(attrs)
}
});
let index_new_fields = schema.map(|s| s.index_new_fields()); let index_new_fields = schema.map(|s| s.index_new_fields());
let settings = Settings { let settings = Settings {
ranking_rules: Some(ranking_rules), ranking_rules: Some(ranking_rules),
ranking_distinct: Some(ranking_distinct), ranking_distinct: Some(ranking_distinct),
identifier: Some(identifier), searchable_attributes: searchable_attributes,
searchable_attributes: Some(searchable_attributes), displayed_attributes: displayed_attributes,
displayed_attributes: Some(displayed_attributes),
stop_words: Some(stop_words), stop_words: Some(stop_words),
synonyms: Some(synonyms), synonyms: Some(synonyms),
index_new_fields: Some(index_new_fields), index_new_fields: Some(index_new_fields),
@ -100,7 +115,6 @@ pub async fn update_all(mut ctx: Request<Data>) -> SResult<Response> {
let settings = Settings { let settings = Settings {
ranking_rules: Some(settings_update.ranking_rules), ranking_rules: Some(settings_update.ranking_rules),
ranking_distinct: Some(settings_update.ranking_distinct), ranking_distinct: Some(settings_update.ranking_distinct),
identifier: Some(settings_update.identifier),
searchable_attributes: Some(settings_update.searchable_attributes), searchable_attributes: Some(settings_update.searchable_attributes),
displayed_attributes: Some(settings_update.displayed_attributes), displayed_attributes: Some(settings_update.displayed_attributes),
stop_words: Some(settings_update.stop_words), stop_words: Some(settings_update.stop_words),
@ -321,8 +335,12 @@ pub async fn displayed(ctx: Request<Data>) -> SResult<Response> {
let schema = index.main.schema(&reader)?; let schema = index.main.schema(&reader)?;
let displayed_attributes: Option<HashSet<String>> = let displayed_attributes: Option<HashSet<String>> = schema.map(|s| {
schema.map(|s| s.displayed_name().iter().map(|i| (*i).to_string()).collect()); s.displayed_name()
.iter()
.map(|i| (*i).to_string())
.collect()
});
Ok(tide::Response::new(200) Ok(tide::Response::new(200)
.body_json(&displayed_attributes) .body_json(&displayed_attributes)

View File

@ -64,7 +64,6 @@ pub fn enrich_server_with_movies_settings(
"dsc(vote_average)", "dsc(vote_average)",
], ],
"rankingDistinct": null, "rankingDistinct": null,
"identifier": "id",
"searchableAttributes": [ "searchableAttributes": [
"title", "title",
"tagline", "tagline",

View File

@ -30,7 +30,7 @@ fn create_index_with_name() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -54,7 +54,7 @@ fn create_index_with_name() {
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_array().unwrap().len(), 1); assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 4); assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
let r2_name = res2_value[0]["name"].as_str().unwrap(); let r2_name = res2_value[0]["name"].as_str().unwrap();
let r2_uid = res2_value[0]["uid"].as_str().unwrap(); let r2_uid = res2_value[0]["uid"].as_str().unwrap();
let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap(); let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap();
@ -90,7 +90,7 @@ fn create_index_with_uid() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -114,7 +114,7 @@ fn create_index_with_uid() {
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_array().unwrap().len(), 1); assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 4); assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
let r2_name = res2_value[0]["name"].as_str().unwrap(); let r2_name = res2_value[0]["name"].as_str().unwrap();
let r2_uid = res2_value[0]["uid"].as_str().unwrap(); let r2_uid = res2_value[0]["uid"].as_str().unwrap();
let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap(); let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap();
@ -151,7 +151,7 @@ fn create_index_with_name_and_uid() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -175,7 +175,7 @@ fn create_index_with_name_and_uid() {
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_array().unwrap().len(), 1); assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 4); assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
let r2_name = res2_value[0]["name"].as_str().unwrap(); let r2_name = res2_value[0]["name"].as_str().unwrap();
let r2_uid = res2_value[0]["uid"].as_str().unwrap(); let r2_uid = res2_value[0]["uid"].as_str().unwrap();
let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap(); let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap();
@ -210,7 +210,7 @@ fn rename_index() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -241,7 +241,7 @@ fn rename_index() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_object().unwrap().len(), 4); assert_eq!(res2_value.as_object().unwrap().len(), 5);
let r2_name = res2_value["name"].as_str().unwrap(); let r2_name = res2_value["name"].as_str().unwrap();
let r2_uid = res2_value["uid"].as_str().unwrap(); let r2_uid = res2_value["uid"].as_str().unwrap();
let r2_created_at = res2_value["createdAt"].as_str().unwrap(); let r2_created_at = res2_value["createdAt"].as_str().unwrap();
@ -265,7 +265,7 @@ fn rename_index() {
let res3_value: Value = serde_json::from_slice(&buf).unwrap(); let res3_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res3_value.as_array().unwrap().len(), 1); assert_eq!(res3_value.as_array().unwrap().len(), 1);
assert_eq!(res3_value[0].as_object().unwrap().len(), 4); assert_eq!(res3_value[0].as_object().unwrap().len(), 5);
let r3_name = res3_value[0]["name"].as_str().unwrap(); let r3_name = res3_value[0]["name"].as_str().unwrap();
let r3_uid = res3_value[0]["uid"].as_str().unwrap(); let r3_uid = res3_value[0]["uid"].as_str().unwrap();
let r3_created_at = res3_value[0]["createdAt"].as_str().unwrap(); let r3_created_at = res3_value[0]["createdAt"].as_str().unwrap();
@ -301,7 +301,7 @@ fn delete_index_and_recreate_it() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -325,7 +325,7 @@ fn delete_index_and_recreate_it() {
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_array().unwrap().len(), 1); assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 4); assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
let r2_name = res2_value[0]["name"].as_str().unwrap(); let r2_name = res2_value[0]["name"].as_str().unwrap();
let r2_uid = res2_value[0]["uid"].as_str().unwrap(); let r2_uid = res2_value[0]["uid"].as_str().unwrap();
let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap(); let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap();
@ -384,7 +384,7 @@ fn delete_index_and_recreate_it() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -408,7 +408,7 @@ fn delete_index_and_recreate_it() {
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_array().unwrap().len(), 1); assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 4); assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
let r2_name = res2_value[0]["name"].as_str().unwrap(); let r2_name = res2_value[0]["name"].as_str().unwrap();
let r2_uid = res2_value[0]["uid"].as_str().unwrap(); let r2_uid = res2_value[0]["uid"].as_str().unwrap();
let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap(); let r2_created_at = res2_value[0]["createdAt"].as_str().unwrap();
@ -444,7 +444,7 @@ fn check_multiples_indexes() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res1_value: Value = serde_json::from_slice(&buf).unwrap(); let res1_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res1_value.as_object().unwrap().len(), 4); assert_eq!(res1_value.as_object().unwrap().len(), 5);
let r1_name = res1_value["name"].as_str().unwrap(); let r1_name = res1_value["name"].as_str().unwrap();
let r1_uid = res1_value["uid"].as_str().unwrap(); let r1_uid = res1_value["uid"].as_str().unwrap();
let r1_created_at = res1_value["createdAt"].as_str().unwrap(); let r1_created_at = res1_value["createdAt"].as_str().unwrap();
@ -468,7 +468,7 @@ fn check_multiples_indexes() {
let res2_value: Value = serde_json::from_slice(&buf).unwrap(); let res2_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res2_value.as_array().unwrap().len(), 1); assert_eq!(res2_value.as_array().unwrap().len(), 1);
assert_eq!(res2_value[0].as_object().unwrap().len(), 4); assert_eq!(res2_value[0].as_object().unwrap().len(), 5);
let r2_0_name = res2_value[0]["name"].as_str().unwrap(); let r2_0_name = res2_value[0]["name"].as_str().unwrap();
let r2_0_uid = res2_value[0]["uid"].as_str().unwrap(); let r2_0_uid = res2_value[0]["uid"].as_str().unwrap();
let r2_0_created_at = res2_value[0]["createdAt"].as_str().unwrap(); let r2_0_created_at = res2_value[0]["createdAt"].as_str().unwrap();
@ -499,7 +499,7 @@ fn check_multiples_indexes() {
block_on(res.into_body().read_to_end(&mut buf)).unwrap(); block_on(res.into_body().read_to_end(&mut buf)).unwrap();
let res3_value: Value = serde_json::from_slice(&buf).unwrap(); let res3_value: Value = serde_json::from_slice(&buf).unwrap();
assert_eq!(res3_value.as_object().unwrap().len(), 4); assert_eq!(res3_value.as_object().unwrap().len(), 5);
let r3_name = res3_value["name"].as_str().unwrap(); let r3_name = res3_value["name"].as_str().unwrap();
let r3_uid = res3_value["uid"].as_str().unwrap(); let r3_uid = res3_value["uid"].as_str().unwrap();
let r3_created_at = res3_value["createdAt"].as_str().unwrap(); let r3_created_at = res3_value["createdAt"].as_str().unwrap();
@ -524,13 +524,13 @@ fn check_multiples_indexes() {
assert_eq!(res4_value.as_array().unwrap().len(), 2); assert_eq!(res4_value.as_array().unwrap().len(), 2);
assert_eq!(res4_value[0].as_object().unwrap().len(), 4); assert_eq!(res4_value[0].as_object().unwrap().len(), 5);
let r4_0_name = res4_value[0]["name"].as_str().unwrap(); let r4_0_name = res4_value[0]["name"].as_str().unwrap();
let r4_0_uid = res4_value[0]["uid"].as_str().unwrap(); let r4_0_uid = res4_value[0]["uid"].as_str().unwrap();
let r4_0_created_at = res4_value[0]["createdAt"].as_str().unwrap(); let r4_0_created_at = res4_value[0]["createdAt"].as_str().unwrap();
let r4_0_updated_at = res4_value[0]["updatedAt"].as_str().unwrap(); let r4_0_updated_at = res4_value[0]["updatedAt"].as_str().unwrap();
assert_eq!(res4_value[1].as_object().unwrap().len(), 4); assert_eq!(res4_value[1].as_object().unwrap().len(), 5);
let r4_1_name = res4_value[1]["name"].as_str().unwrap(); let r4_1_name = res4_value[1]["name"].as_str().unwrap();
let r4_1_uid = res4_value[1]["uid"].as_str().unwrap(); let r4_1_uid = res4_value[1]["uid"].as_str().unwrap();
let r4_1_created_at = res4_value[1]["createdAt"].as_str().unwrap(); let r4_1_created_at = res4_value[1]["createdAt"].as_str().unwrap();

View File

@ -26,6 +26,7 @@ fn write_all_and_delete() {
let body = json!({ let body = json!({
"uid": "movies", "uid": "movies",
"identifier": "id",
}) })
.to_string() .to_string()
.into_bytes(); .into_bytes();
@ -50,7 +51,6 @@ fn write_all_and_delete() {
"dsc(rank)", "dsc(rank)",
], ],
"rankingDistinct": "movie_id", "rankingDistinct": "movie_id",
"identifier": "id",
"searchableAttributes": [ "searchableAttributes": [
"id", "id",
"movie_id", "movie_id",
@ -128,12 +128,11 @@ fn write_all_and_delete() {
let json = json!({ let json = json!({
"rankingRules": null, "rankingRules": null,
"rankingDistinct": null, "rankingDistinct": null,
"identifier": null,
"searchableAttributes": null, "searchableAttributes": null,
"displayedAttributes": null, "displayedAttributes": null,
"stopWords": null, "stopWords": null,
"synonyms": null, "synonyms": null,
"indexNewFields": null, "indexNewFields": true,
}); });
assert_json_eq!(json, res_value, ordered: false); assert_json_eq!(json, res_value, ordered: false);
@ -155,6 +154,7 @@ fn write_all_and_update() {
let body = json!({ let body = json!({
"uid": "movies", "uid": "movies",
"identifier": "id",
}) })
.to_string() .to_string()
.into_bytes(); .into_bytes();
@ -179,7 +179,6 @@ fn write_all_and_update() {
"dsc(rank)", "dsc(rank)",
], ],
"rankingDistinct": "movie_id", "rankingDistinct": "movie_id",
"identifier": "uid",
"searchableAttributes": [ "searchableAttributes": [
"uid", "uid",
"movie_id", "movie_id",
@ -244,7 +243,6 @@ fn write_all_and_update() {
"_exact", "_exact",
"dsc(release_date)", "dsc(release_date)",
], ],
"identifier": "uid",
"searchableAttributes": [ "searchableAttributes": [
"title", "title",
"description", "description",
@ -299,7 +297,6 @@ fn write_all_and_update() {
"dsc(release_date)", "dsc(release_date)",
], ],
"rankingDistinct": null, "rankingDistinct": null,
"identifier": "uid",
"searchableAttributes": [ "searchableAttributes": [
"title", "title",
"description", "description",