Fix PR comments

This commit is contained in:
many 2021-10-28 11:18:32 +02:00
parent 2be755ce75
commit ed6db19681
No known key found for this signature in database
GPG Key ID: 2CEF23B75189EACA
3 changed files with 21 additions and 13 deletions

View File

@ -1,4 +1,4 @@
use std::collections::HashSet;
use std::collections::BTreeSet;
use std::convert::Infallible;
use std::error::Error as StdError;
use std::{fmt, io, str};
@ -58,10 +58,10 @@ pub enum UserError {
CriterionError(CriterionError),
DocumentLimitReached,
InvalidDocumentId { document_id: Value },
InvalidFacetsDistribution { invalid_facets_name: HashSet<String> },
InvalidFacetsDistribution { invalid_facets_name: BTreeSet<String> },
InvalidFilter(FilterError),
InvalidGeoField { document_id: Value, object: Value },
InvalidSortableAttribute { field: String, valid_fields: HashSet<String> },
InvalidSortableAttribute { field: String, valid_fields: BTreeSet<String> },
SortRankingRuleMissing,
InvalidStoreFile,
MaxDatabaseSizeReached,
@ -76,7 +76,7 @@ pub enum UserError {
#[derive(Debug)]
pub enum FilterError {
InvalidAttribute { field: String, valid_fields: HashSet<String> },
InvalidAttribute { field: String, valid_fields: BTreeSet<String> },
ReservedKeyword { field: String, context: Option<String> },
Syntax(pest::error::Error<ParserRule>),
}

View File

@ -169,7 +169,7 @@ impl FilterCondition {
if !filterable_fields.contains("_geo") {
return Err(FilterError::InvalidAttribute {
field: "_geo".to_string(),
valid_fields: filterable_fields.clone(),
valid_fields: filterable_fields.into_iter().cloned().collect(),
}
.into());
}
@ -192,7 +192,7 @@ impl FilterCondition {
if parameters.len() != 3 {
return Err(FilterError::Syntax(PestError::new_from_span(
ErrorVariant::CustomError {
message: format!("The `_geoRadius` filter expect three arguments: `_geoRadius(latitude, longitude, radius)`"),
message: format!("The _geoRadius filter expect three arguments: _geoRadius(latitude, longitude, radius)"),
},
// we want to point to the last parameters and if there was no parameters we
// point to the parenthesis
@ -599,7 +599,7 @@ fn field_id(
if !filterable_fields.contains(key.as_str()) {
return Err(FilterError::InvalidAttribute {
field: key.as_str().to_string(),
valid_fields: filterable_fields.clone(),
valid_fields: filterable_fields.into_iter().cloned().collect(),
});
}
@ -829,26 +829,34 @@ mod tests {
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius");
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.to_string().contains("The `_geoRadius` filter expect three arguments: `_geoRadius(latitude, longitude, radius)`"));
assert!(error.to_string().contains(
"The _geoRadius filter expect three arguments: _geoRadius(latitude, longitude, radius)"
));
// georadius don't have any parameters
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius()");
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.to_string().contains("The `_geoRadius` filter expect three arguments: `_geoRadius(latitude, longitude, radius)`"));
assert!(error.to_string().contains(
"The _geoRadius filter expect three arguments: _geoRadius(latitude, longitude, radius)"
));
// georadius don't have enough parameters
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius(1, 2)");
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.to_string().contains("The `_geoRadius` filter expect three arguments: `_geoRadius(latitude, longitude, radius)`"));
assert!(error.to_string().contains(
"The _geoRadius filter expect three arguments: _geoRadius(latitude, longitude, radius)"
));
// georadius have too many parameters
let result =
FilterCondition::from_str(&rtxn, &index, "_geoRadius(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)");
assert!(result.is_err());
let error = result.unwrap_err();
assert!(error.to_string().contains("The `_geoRadius` filter expect three arguments: `_geoRadius(latitude, longitude, radius)`"));
assert!(error.to_string().contains(
"The _geoRadius filter expect three arguments: _geoRadius(latitude, longitude, radius)"
));
// georadius have a bad latitude
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius(-100, 150, 10)");

View File

@ -151,13 +151,13 @@ impl<'a> Search<'a> {
Member::Field(ref field) if !sortable_fields.contains(field) => {
return Err(UserError::InvalidSortableAttribute {
field: field.to_string(),
valid_fields: sortable_fields,
valid_fields: sortable_fields.into_iter().collect(),
})?
}
Member::Geo(_) if !sortable_fields.contains("_geo") => {
return Err(UserError::InvalidSortableAttribute {
field: "_geo".to_string(),
valid_fields: sortable_fields,
valid_fields: sortable_fields.into_iter().collect(),
})?
}
_ => (),