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
Fix FuzzyQuery to properly handle Object, number, dates or String. #12020
Fix FuzzyQuery to properly handle Object, number, dates or String. #12020
Conversation
Makes FuzzyQueryBuilder take a value as a number, date or String using exactly the same logic as TermQueryBuilder. Relates elastic#11865
I think we also wanted to change the parser to parse the value as an object instead of a string? |
Yep I wasn't sure of that, I'll fix this. |
public Query fuzzyQuery(String value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { | ||
long iValue = dateMathParser().parse(value, now()); | ||
public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { | ||
long iValue = dateMathParser().parse(value.toString(), now()); |
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.
Can you use parseValue(value) instead? It should behave as similarly to termQuery() as possible.
I left some comments. |
LGTM |
Query query = null; | ||
MappedFieldType fieldType = parseContext.fieldMapper(fieldName); | ||
if (fieldType != null) { | ||
query = fieldType.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions); | ||
} | ||
if (query == null) { | ||
query = new FuzzyQuery(new Term(fieldName, value), fuzziness.asDistance(value), prefixLength, maxExpansions, transpositions); | ||
query = new FuzzyQuery(new Term(fieldName, value.toString()), fuzziness.asDistance(value.toString()), prefixLength, maxExpansions, transpositions); |
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.
shouldn't we use BytesRefs.toBytesRef(value) here instead?
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.
Yep I was just updating the PR as you wrote this.
LGTM |
This makes FuzzyQueryBuilder and Parser take an Object as a value using the
same logic as termQuery, so that numbers, dates or Strings would be properly
handled.
Relates #11865