fix comments from review

This commit is contained in:
qdequele 2020-03-10 15:35:19 +01:00
parent b06e33f3d3
commit ef3bcd65ab
No known key found for this signature in database
GPG Key ID: B3F0A000EBF11745
5 changed files with 20 additions and 24 deletions

View File

@ -87,7 +87,7 @@ impl fmt::Display for Error {
match self {
Io(e) => write!(f, "{}", e),
IndexAlreadyExists => write!(f, "index already exists"),
MissingPrimaryKey => write!(f, "schema cannot be built without primary key"),
MissingPrimaryKey => write!(f, "schema cannot be built without a primary key"),
SchemaMissing => write!(f, "this index does not have a schema"),
WordIndexMissing => write!(f, "this index does not have a word index"),
MissingDocumentId => write!(f, "document id is missing"),

View File

@ -57,7 +57,7 @@ impl fmt::Display for SerializerError {
f.write_str("serialized document does not have an id according to the schema")
}
SerializerError::InvalidDocumentIdType => {
f.write_str("documents primary keys can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).")
f.write_str("a document primary key can be of type integer or string only composed of alphanumeric characters, hyphens (-) and underscores (_).")
}
SerializerError::Zlmdb(e) => write!(f, "heed related error: {}", e),
SerializerError::SerdeJson(e) => write!(f, "serde json error: {}", e),

View File

@ -149,12 +149,11 @@ async fn update_multiple_documents(mut ctx: Request<Data>, is_partial: bool) ->
},
};
if schema.set_primary_key(&id).is_ok() {
let mut writer = db.main_write_txn()?;
schema.set_primary_key(&id).map_err(ResponseError::bad_request)?;
index.main.put_schema(&mut writer, &schema)?;
writer.commit()?;
}
}
let mut document_addition = if is_partial {
index.documents_partial_addition()

View File

@ -180,11 +180,10 @@ pub async fn create_index(mut ctx: Request<Data>) -> SResult<Response> {
if let Some(id) = body.primary_key.clone() {
if let Some(mut schema) = created_index.main.schema(&mut writer)? {
if let Ok(_) = schema.set_primary_key(&id) {
schema.set_primary_key(&id).map_err(ResponseError::bad_request)?;
created_index.main.put_schema(&mut writer, &schema)?;
}
}
}
writer.commit()?;
@ -239,17 +238,18 @@ pub async fn update_index(mut ctx: Request<Data>) -> SResult<Response> {
match schema.primary_key() {
Some(_) => {
return Err(ResponseError::bad_request(
"The index primary key cannot be updated",
"The primary key cannot be updated",
));
}
None => {
if let Ok(_) = schema.set_primary_key(&id) {
schema
.set_primary_key(&id)
.map_err(ResponseError::bad_request)?;
index.main.put_schema(&mut writer, &schema)?;
}
}
}
}
}
index.main.put_updated_at(&mut writer)?;
writer.commit()?;

View File

@ -45,29 +45,26 @@ pub async fn get_all(ctx: Request<Data>) -> SResult<Response> {
let schema = index.main.schema(&reader)?;
let searchable_attributes = schema.clone().map(|s| {
let attrs = s
.indexed_name()
s.indexed_name()
.iter()
.map(|s| (*s).to_string())
.collect::<Vec<String>>();
Some(attrs)
.collect::<Vec<String>>()
});
let displayed_attributes = schema.clone().map(|s| {
let attrs = s
.displayed_name()
s.displayed_name()
.iter()
.map(|s| (*s).to_string())
.collect::<HashSet<String>>();
Some(attrs)
.collect::<HashSet<String>>()
});
let accept_new_fields = schema.map(|s| s.accept_new_fields());
let settings = Settings {
ranking_rules: Some(Some(ranking_rules)),
distinct_attribute: Some(distinct_attribute),
searchable_attributes,
displayed_attributes,
searchable_attributes: Some(searchable_attributes),
displayed_attributes: Some(displayed_attributes),
stop_words: Some(Some(stop_words)),
synonyms: Some(Some(synonyms)),
accept_new_fields: Some(accept_new_fields),