mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-23 18:45:06 +08:00
Fix PR comments
This commit is contained in:
parent
2be755ce75
commit
ed6db19681
@ -1,4 +1,4 @@
|
|||||||
use std::collections::HashSet;
|
use std::collections::BTreeSet;
|
||||||
use std::convert::Infallible;
|
use std::convert::Infallible;
|
||||||
use std::error::Error as StdError;
|
use std::error::Error as StdError;
|
||||||
use std::{fmt, io, str};
|
use std::{fmt, io, str};
|
||||||
@ -58,10 +58,10 @@ pub enum UserError {
|
|||||||
CriterionError(CriterionError),
|
CriterionError(CriterionError),
|
||||||
DocumentLimitReached,
|
DocumentLimitReached,
|
||||||
InvalidDocumentId { document_id: Value },
|
InvalidDocumentId { document_id: Value },
|
||||||
InvalidFacetsDistribution { invalid_facets_name: HashSet<String> },
|
InvalidFacetsDistribution { invalid_facets_name: BTreeSet<String> },
|
||||||
InvalidFilter(FilterError),
|
InvalidFilter(FilterError),
|
||||||
InvalidGeoField { document_id: Value, object: Value },
|
InvalidGeoField { document_id: Value, object: Value },
|
||||||
InvalidSortableAttribute { field: String, valid_fields: HashSet<String> },
|
InvalidSortableAttribute { field: String, valid_fields: BTreeSet<String> },
|
||||||
SortRankingRuleMissing,
|
SortRankingRuleMissing,
|
||||||
InvalidStoreFile,
|
InvalidStoreFile,
|
||||||
MaxDatabaseSizeReached,
|
MaxDatabaseSizeReached,
|
||||||
@ -76,7 +76,7 @@ pub enum UserError {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum FilterError {
|
pub enum FilterError {
|
||||||
InvalidAttribute { field: String, valid_fields: HashSet<String> },
|
InvalidAttribute { field: String, valid_fields: BTreeSet<String> },
|
||||||
ReservedKeyword { field: String, context: Option<String> },
|
ReservedKeyword { field: String, context: Option<String> },
|
||||||
Syntax(pest::error::Error<ParserRule>),
|
Syntax(pest::error::Error<ParserRule>),
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ impl FilterCondition {
|
|||||||
if !filterable_fields.contains("_geo") {
|
if !filterable_fields.contains("_geo") {
|
||||||
return Err(FilterError::InvalidAttribute {
|
return Err(FilterError::InvalidAttribute {
|
||||||
field: "_geo".to_string(),
|
field: "_geo".to_string(),
|
||||||
valid_fields: filterable_fields.clone(),
|
valid_fields: filterable_fields.into_iter().cloned().collect(),
|
||||||
}
|
}
|
||||||
.into());
|
.into());
|
||||||
}
|
}
|
||||||
@ -192,7 +192,7 @@ impl FilterCondition {
|
|||||||
if parameters.len() != 3 {
|
if parameters.len() != 3 {
|
||||||
return Err(FilterError::Syntax(PestError::new_from_span(
|
return Err(FilterError::Syntax(PestError::new_from_span(
|
||||||
ErrorVariant::CustomError {
|
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
|
// we want to point to the last parameters and if there was no parameters we
|
||||||
// point to the parenthesis
|
// point to the parenthesis
|
||||||
@ -599,7 +599,7 @@ fn field_id(
|
|||||||
if !filterable_fields.contains(key.as_str()) {
|
if !filterable_fields.contains(key.as_str()) {
|
||||||
return Err(FilterError::InvalidAttribute {
|
return Err(FilterError::InvalidAttribute {
|
||||||
field: key.as_str().to_string(),
|
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");
|
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius");
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
let error = result.unwrap_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
|
// georadius don't have any parameters
|
||||||
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius()");
|
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius()");
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
let error = result.unwrap_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
|
// georadius don't have enough parameters
|
||||||
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius(1, 2)");
|
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius(1, 2)");
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
let error = result.unwrap_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
|
// georadius have too many parameters
|
||||||
let result =
|
let result =
|
||||||
FilterCondition::from_str(&rtxn, &index, "_geoRadius(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)");
|
FilterCondition::from_str(&rtxn, &index, "_geoRadius(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)");
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
let error = result.unwrap_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
|
// georadius have a bad latitude
|
||||||
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius(-100, 150, 10)");
|
let result = FilterCondition::from_str(&rtxn, &index, "_geoRadius(-100, 150, 10)");
|
||||||
|
@ -151,13 +151,13 @@ impl<'a> Search<'a> {
|
|||||||
Member::Field(ref field) if !sortable_fields.contains(field) => {
|
Member::Field(ref field) if !sortable_fields.contains(field) => {
|
||||||
return Err(UserError::InvalidSortableAttribute {
|
return Err(UserError::InvalidSortableAttribute {
|
||||||
field: field.to_string(),
|
field: field.to_string(),
|
||||||
valid_fields: sortable_fields,
|
valid_fields: sortable_fields.into_iter().collect(),
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
Member::Geo(_) if !sortable_fields.contains("_geo") => {
|
Member::Geo(_) if !sortable_fields.contains("_geo") => {
|
||||||
return Err(UserError::InvalidSortableAttribute {
|
return Err(UserError::InvalidSortableAttribute {
|
||||||
field: "_geo".to_string(),
|
field: "_geo".to_string(),
|
||||||
valid_fields: sortable_fields,
|
valid_fields: sortable_fields.into_iter().collect(),
|
||||||
})?
|
})?
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
|
Loading…
Reference in New Issue
Block a user