Fix MatchQueryParser not parsing fuzzy_transpositions

This commit is contained in:
Alex Brasetvik 2014-05-23 17:06:41 +02:00 committed by Simon Willnauer
parent 3f2f1f088d
commit 15ff3df243
4 changed files with 23 additions and 1 deletions

View File

@ -126,7 +126,7 @@ public class MatchQueryParser implements QueryParser {
matchQuery.setRewriteMethod(QueryParsers.parseRewriteMethod(parser.textOrNull(), null));
} else if ("fuzzy_rewrite".equals(currentFieldName) || "fuzzyRewrite".equals(currentFieldName)) {
matchQuery.setFuzzyRewriteMethod(QueryParsers.parseRewriteMethod(parser.textOrNull(), null));
} else if ("fuzzy_transpositions".equals(fieldName)) {
} else if ("fuzzy_transpositions".equals(currentFieldName)) {
matchQuery.setTranspositions(parser.booleanValue());
} else if ("lenient".equals(currentFieldName)) {
matchQuery.setLenient(parser.booleanValue());

View File

@ -2355,4 +2355,24 @@ public class SimpleIndexQueryParserTests extends ElasticsearchTestCase {
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(BooleanQuery.class));
}
@Test
public void testMatchWithFuzzyTranspositions() throws Exception {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/match-with-fuzzy-transpositions.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(FuzzyQuery.class));
assertThat( ((FuzzyQuery) parsedQuery).getTranspositions(), equalTo(true));
}
@Test
public void testMatchWithoutFuzzyTranspositions() throws Exception {
IndexQueryParserService queryParser = queryParser();
String query = copyToStringFromClasspath("/org/elasticsearch/index/query/match-without-fuzzy-transpositions.json");
Query parsedQuery = queryParser.parse(query).query();
assertThat(parsedQuery, instanceOf(FuzzyQuery.class));
assertThat( ((FuzzyQuery) parsedQuery).getTranspositions(), equalTo(false));
}
}

View File

@ -0,0 +1 @@
{ "match": { "body": { "query": "fuzzy", "fuzziness": 1, "fuzzy_transpositions": true }} }

View File

@ -0,0 +1 @@
{ "match": { "body": { "query": "fuzzy", "fuzziness": 1, "fuzzy_transpositions": false }} }