-
-
Notifications
You must be signed in to change notification settings - Fork 698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a means to deal with malformed facet text representation for the query parser #1056
Changes from 1 commit
9c7affa
08e0bd6
e944f48
2a1bdba
29aaf00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ use crate::schema::{Field, Schema}; | |
use crate::schema::{FieldType, Term}; | ||
use crate::tokenizer::TokenizerManager; | ||
use crate::Score; | ||
use crate::TantivyError; | ||
use std::borrow::Cow; | ||
use std::collections::HashMap; | ||
use std::num::{ParseFloatError, ParseIntError}; | ||
|
@@ -68,6 +69,9 @@ pub enum QueryParserError { | |
/// The format for the date field is not RFC 3339 compliant. | ||
#[error("The date field has an invalid format")] | ||
DateFormatError(chrono::ParseError), | ||
/// The format for the facet field invalid. | ||
#[error("The facet field is malformed")] | ||
FacetFormatError(String), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While an additional entry in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the view point of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had another look and think
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having a specific error enum for the facet parser totally makes sense to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I just added an enum to facet as I wouldn't think extending |
||
} | ||
|
||
impl From<ParseIntError> for QueryParserError { | ||
|
@@ -358,10 +362,15 @@ impl QueryParser { | |
)) | ||
} | ||
} | ||
FieldType::HierarchicalFacet(_) => { | ||
let facet = Facet::from_text(phrase); | ||
Ok(vec![(0, Term::from_field_text(field, facet.encoded_str()))]) | ||
} | ||
FieldType::HierarchicalFacet(_) => match Facet::from_text(phrase) { | ||
Ok(facet) => Ok(vec![(0, Term::from_field_text(field, facet.encoded_str()))]), | ||
Err(e) => match e { | ||
TantivyError::InvalidArgument(path) => { | ||
Err(QueryParserError::FacetFormatError(path)) | ||
} | ||
_ => Err(QueryParserError::SyntaxError), | ||
}, | ||
}, | ||
FieldType::Bytes(_) => { | ||
let bytes = base64::decode(phrase).map_err(QueryParserError::ExpectedBase64)?; | ||
let term = Term::from_field_bytes(field, &bytes); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure, but I think this error should forward the original error message or the user would not see which part of the query failed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
like this
#[error("{0}")]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch :) I missed that. Thanks.