From 15ff3df243c22f2eac16076cb457666be0157b51 Mon Sep 17 00:00:00 2001 From: Alex Brasetvik Date: Fri, 23 May 2014 17:06:41 +0200 Subject: [PATCH] Fix MatchQueryParser not parsing fuzzy_transpositions --- .../index/query/MatchQueryParser.java | 2 +- .../query/SimpleIndexQueryParserTests.java | 20 +++++++++++++++++++ .../match-with-fuzzy-transpositions.json | 1 + .../match-without-fuzzy-transpositions.json | 1 + 4 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/elasticsearch/index/query/match-with-fuzzy-transpositions.json create mode 100644 src/test/java/org/elasticsearch/index/query/match-without-fuzzy-transpositions.json diff --git a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java index eff80a12a93..a0f595a6626 100644 --- a/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java +++ b/src/main/java/org/elasticsearch/index/query/MatchQueryParser.java @@ -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()); diff --git a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java index a4c1603af83..ee5bb483c64 100644 --- a/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java +++ b/src/test/java/org/elasticsearch/index/query/SimpleIndexQueryParserTests.java @@ -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)); + } + + } diff --git a/src/test/java/org/elasticsearch/index/query/match-with-fuzzy-transpositions.json b/src/test/java/org/elasticsearch/index/query/match-with-fuzzy-transpositions.json new file mode 100644 index 00000000000..5f4fe8bcaca --- /dev/null +++ b/src/test/java/org/elasticsearch/index/query/match-with-fuzzy-transpositions.json @@ -0,0 +1 @@ +{ "match": { "body": { "query": "fuzzy", "fuzziness": 1, "fuzzy_transpositions": true }} } diff --git a/src/test/java/org/elasticsearch/index/query/match-without-fuzzy-transpositions.json b/src/test/java/org/elasticsearch/index/query/match-without-fuzzy-transpositions.json new file mode 100644 index 00000000000..06c77aafb33 --- /dev/null +++ b/src/test/java/org/elasticsearch/index/query/match-without-fuzzy-transpositions.json @@ -0,0 +1 @@ +{ "match": { "body": { "query": "fuzzy", "fuzziness": 1, "fuzzy_transpositions": false }} }