-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
extend FuzzyTermQuery to support json field #2173
Changes from 3 commits
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 |
---|---|---|
|
@@ -6,7 +6,7 @@ pub use phrase_prefix_query::PhrasePrefixQuery; | |
pub use phrase_prefix_scorer::PhrasePrefixScorer; | ||
pub use phrase_prefix_weight::PhrasePrefixWeight; | ||
|
||
fn prefix_end(prefix_start: &[u8]) -> Option<Vec<u8>> { | ||
pub(crate) fn prefix_end(prefix_start: &[u8]) -> Option<Vec<u8>> { | ||
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 don't understand the 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 referred to the phrasePrefixQuery implementation, which also filters the term based on the term value prefix. 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 believe it attempts to find the next larger prefix. Typically, this involves incrementing the last u8 value by 1. However, there is an edge case to consider when the last u8 value is u8::MAX. |
||
let mut res = prefix_start.to_owned(); | ||
while !res.is_empty() { | ||
let end = res.len() - 1; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -397,6 +397,15 @@ where B: AsRef<[u8]> | |
Some(Ipv6Addr::from_u128(ip_u128)) | ||
} | ||
|
||
/// Returns the json path type. | ||
/// | ||
/// Returns `None` if the value is not JSON. | ||
pub fn json_path_type(&self) -> Option<Type> { | ||
let json_value_bytes = self.as_json_value_bytes()?; | ||
|
||
Some(json_value_bytes.typ()) | ||
} | ||
|
||
/// Returns the json path (without non-human friendly separators), | ||
/// and the encoded ValueBytes after the json path. | ||
/// | ||
|
@@ -413,6 +422,21 @@ where B: AsRef<[u8]> | |
Some((json_path, ValueBytes::wrap(&term[1..]))) | ||
} | ||
|
||
/// Returns the json path bytes (including the JSON_END_OF_PATH byte) | ||
/// | ||
/// Returns `None` if the value is not JSON. | ||
pub(crate) fn as_json_path_bytes(&self) -> Option<&[u8]> { | ||
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 don't think we need an extra method, 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. The json_path_bytes are used here
Two reasons for this new method
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.
FYI it is used in debug_value_bytes. |
||
if self.typ() != Type::Json { | ||
return None; | ||
} | ||
|
||
let bytes = self.value_bytes(); | ||
let pos = bytes.iter().cloned().position(|b| b == JSON_END_OF_PATH)?; | ||
// split at pos + 1, so that json_path_bytes includes the JSON_END_OF_PATH byte. | ||
let (json_path_bytes, _) = bytes.split_at(pos+1); | ||
Some(json_path_bytes) | ||
} | ||
|
||
/// Returns the encoded ValueBytes after the json path. | ||
/// | ||
/// Returns `None` if the value is not JSON. | ||
|
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.
nit: drop
return
and semicolon