Skip to content
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

Change default value to true for transpositions parameter of fuzzy query #26901

Merged
merged 2 commits into from
Oct 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i
public static final int DEFAULT_MAX_EXPANSIONS = FuzzyQuery.defaultMaxExpansions;

/** Default as to whether transpositions should be treated as a primitive edit operation,
* instead of classic Levenshtein algorithm. Defaults to false. */
public static final boolean DEFAULT_TRANSPOSITIONS = false;
* instead of classic Levenshtein algorithm. Defaults to true. */
public static final boolean DEFAULT_TRANSPOSITIONS = FuzzyQuery.defaultTranspositions;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a small test in FuzzyQueryBuilderTests that setting transpositions to true/false works ?
You can also remove the comment below:

//LUCENE 4 UPGRADE ...

private static final ParseField TERM_FIELD = new ParseField("term");
private static final ParseField VALUE_FIELD = new ParseField("value");
Expand All @@ -74,7 +74,6 @@ public class FuzzyQueryBuilder extends AbstractQueryBuilder<FuzzyQueryBuilder> i

private int maxExpansions = DEFAULT_MAX_EXPANSIONS;

//LUCENE 4 UPGRADE we need a testcase for this + documentation
private boolean transpositions = DEFAULT_TRANSPOSITIONS;

private String rewrite;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public void testFromJson() throws IOException {
checkGeneratedJson(json, parsed);
assertEquals(json, 42.0, parsed.boost(), 0.00001);
assertEquals(json, 2, parsed.fuzziness().asFloat(), 0f);
assertEquals(json, false, parsed.transpositions());
}

public void testParseFailsWithMultipleFields() throws IOException {
Expand Down Expand Up @@ -290,4 +291,19 @@ public void testParseFailsWithValueArray() {
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(query));
assertEquals("[fuzzy] unexpected token [START_ARRAY] after [value]", e.getMessage());
}

public void testToQueryWithTranspositions() throws Exception {
assumeTrue("test runs only when at least a type is registered", getCurrentTypes().length > 0);
Query query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
assertEquals(FuzzyQuery.defaultTranspositions, ((FuzzyQuery)query).getTranspositions());

query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").transpositions(true).toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
assertEquals(true, ((FuzzyQuery)query).getTranspositions());

query = new FuzzyQueryBuilder(STRING_FIELD_NAME, "text").transpositions(false).toQuery(createShardContext());
assertThat(query, instanceOf(FuzzyQuery.class));
assertEquals(false, ((FuzzyQuery)query).getTranspositions());
}
}
6 changes: 5 additions & 1 deletion docs/reference/migration/migrate_7_0/search.asciidoc
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[[breaking_70_search_changes]]
=== Search changes
=== Search and Query DSL changes

==== Changes to queries
* The default value for `transpositions` parameter of `fuzzy` query
has been changed to `true`.

==== Adaptive replica selection enabled by default

Expand Down
5 changes: 3 additions & 2 deletions docs/reference/query-dsl/fuzzy-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ GET /_search
"boost" : 1.0,
"fuzziness" : 2,
"prefix_length" : 0,
"max_expansions": 100
"max_expansions": 100,
"transpositions": false
}
}
}
Expand Down Expand Up @@ -66,7 +67,7 @@ GET /_search
`transpositions`::

Whether fuzzy transpositions (`ab` -> `ba`) are supported.
Default is `false`.
Default is `true`.

WARNING: This query can be very heavy if `prefix_length` is set to `0` and if
`max_expansions` is set to a high number. It could result in every term in the
Expand Down