{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/33229530","id":33229530,"diff_hunk":"@@ -0,0 +1,145 @@\n+/*\n+ * Licensed to Elasticsearch under one or more contributor\n+ * license agreements. See the NOTICE file distributed with\n+ * this work for additional information regarding copyright\n+ * ownership. Elasticsearch licenses this file to you under\n+ * the Apache License, Version 2.0 (the \"License\"); you may\n+ * not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *    http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing,\n+ * software distributed under the License is distributed on an\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY\n+ * KIND, either express or implied.  See the License for the\n+ * specific language governing permissions and limitations\n+ * under the License.\n+ */\n+\n+package org.elasticsearch.index.query;\n+\n+import org.apache.lucene.index.Term;\n+import org.apache.lucene.search.FuzzyQuery;\n+import org.apache.lucene.search.MultiTermQuery;\n+import org.apache.lucene.search.Query;\n+import org.elasticsearch.common.unit.Fuzziness;\n+import org.elasticsearch.index.mapper.MappedFieldType;\n+import org.elasticsearch.index.query.support.QueryParsers;\n+import org.joda.time.DateTime;\n+import org.joda.time.DateTimeZone;\n+import org.junit.Test;\n+\n+import java.io.IOException;\n+\n+import static org.hamcrest.Matchers.equalTo;\n+import static org.hamcrest.Matchers.is;\n+\n+public class FuzzyQueryBuilderTest extends BaseQueryTestCase<FuzzyQueryBuilder> {\n+\n+    private static final String[] REWRITE_METHOD = new String[]{\"constant_score_auto\", \"scoring_boolean\", \"constant_score_boolean\",\n+            \"constant_score_filter\", \"top_terms_boost_1\", \"top_terms_1\"};\n+\n+    private static final String[] MAPPED_FIELD_NAME = new String[] { INT_FIELD_NAME, DOUBLE_FIELD_NAME, DATE_FIELD_NAME, STRING_FIELD_NAME };\n+    \n+    @Override\n+    protected FuzzyQueryBuilder createTestQueryBuilder() {\n+        FuzzyQueryBuilder query;\n+\n+        // mapped or unmapped field\n+        if (randomBoolean()) {\n+            Object text = randomAsciiOfLengthBetween(1, 50);\n+            String fieldName = randomFrom(MAPPED_FIELD_NAME);\n+            if (fieldName.equals(INT_FIELD_NAME)) {\n+                text = randomIntBetween(0, 10);\n+            } else if (fieldName.equals(DOUBLE_FIELD_NAME)) {\n+                text = randomDouble() * 10;\n+            } else if (fieldName.equals(DATE_FIELD_NAME)) {\n+                text = new DateTime(System.currentTimeMillis() - randomIntBetween(0, 1000000), DateTimeZone.UTC);\n+            }\n+            query = new FuzzyQueryBuilder(fieldName, text);\n+        } else {\n+            query = new FuzzyQueryBuilder(randomAsciiOfLengthBetween(1, 10), randomAsciiOfLengthBetween(1, 50));\n+        }\n+        if (randomBoolean()) {\n+            Fuzziness fuzziness;\n+            switch (randomIntBetween(0, 2)) {\n+                case 0:\n+                    fuzziness = Fuzziness.fromEdits(randomIntBetween(0, 2));\n+                    break;\n+                case 1:\n+                    fuzziness = Fuzziness.fromSimilarity(randomFloat());\n+                    break;\n+                default:\n+                    fuzziness = Fuzziness.AUTO;\n+            }\n+            query.fuzziness(fuzziness);\n+        }\n+        if (randomBoolean()) {\n+            query.prefixLength(randomIntBetween(0, 10));\n+        }\n+        if (randomBoolean()) {\n+            query.maxExpansions(randomIntBetween(1, 10));\n+        }\n+        if (randomBoolean()) {\n+            query.transpositions(randomBoolean());\n+        }\n+        if (randomBoolean()) {\n+            query.rewrite(randomFrom(REWRITE_METHOD));\n+        }\n+        if (randomBoolean()) {\n+            query.boost(2.0f / randomIntBetween(1, 20));\n+        }\n+        if (randomBoolean()) {\n+            query.queryName(randomAsciiOfLengthBetween(1, 10));\n+        }\n+        return query;\n+    }\n+\n+    @Override\n+    protected Query createExpectedQuery(FuzzyQueryBuilder queryBuilder, QueryParseContext context) throws IOException {","path":"core/src/test/java/org/elasticsearch/index/query/FuzzyQueryBuilderTest.java","position":100,"original_position":100,"commit_id":"a8f9d00b8c14f8d8fdd61135234a5ceb606ad427","original_commit_id":"a8f9d00b8c14f8d8fdd61135234a5ceb606ad427","user":{"login":"MaineC","id":70953,"avatar_url":"https://avatars.githubusercontent.com/u/70953?v=3","gravatar_id":"","url":"https://api.github.com/users/MaineC","html_url":"https://github.com/MaineC","followers_url":"https://api.github.com/users/MaineC/followers","following_url":"https://api.github.com/users/MaineC/following{/other_user}","gists_url":"https://api.github.com/users/MaineC/gists{/gist_id}","starred_url":"https://api.github.com/users/MaineC/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MaineC/subscriptions","organizations_url":"https://api.github.com/users/MaineC/orgs","repos_url":"https://api.github.com/users/MaineC/repos","events_url":"https://api.github.com/users/MaineC/events{/privacy}","received_events_url":"https://api.github.com/users/MaineC/received_events","type":"User","site_admin":false},"body":"Much like with the tests for SimpleQueryStringQuery this method is almost a copy of the original toQuery code in the QueryBuilder. Can we track the reasoning behind this type of testing here: https://github.com/elastic/dev/blob/master/design/queries/general-guidelines.md (I believe we've discussed it in multiple PR threads and face2face but have lost of all the specific arguments).","created_at":"2015-06-25T07:46:32Z","updated_at":"2015-06-25T07:46:32Z","html_url":"https://github.com/elastic/elasticsearch/pull/11865#discussion_r33229530","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/33229530"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/11865#discussion_r33229530"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865","id":38492673,"html_url":"https://github.com/elastic/elasticsearch/pull/11865","diff_url":"https://github.com/elastic/elasticsearch/pull/11865.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/11865.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11865","number":11865,"state":"open","locked":false,"title":"Refactoring of FuzzyQuery","user":{"login":"alexksikes","id":43475,"avatar_url":"https://avatars.githubusercontent.com/u/43475?v=3","gravatar_id":"","url":"https://api.github.com/users/alexksikes","html_url":"https://github.com/alexksikes","followers_url":"https://api.github.com/users/alexksikes/followers","following_url":"https://api.github.com/users/alexksikes/following{/other_user}","gists_url":"https://api.github.com/users/alexksikes/gists{/gist_id}","starred_url":"https://api.github.com/users/alexksikes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexksikes/subscriptions","organizations_url":"https://api.github.com/users/alexksikes/orgs","repos_url":"https://api.github.com/users/alexksikes/repos","events_url":"https://api.github.com/users/alexksikes/events{/privacy}","received_events_url":"https://api.github.com/users/alexksikes/received_events","type":"User","site_admin":false},"body":"Relates to #10217\r\n\r\nThis PR is against the query-refactoring branch.","created_at":"2015-06-24T22:01:12Z","updated_at":"2015-06-25T07:46:32Z","closed_at":null,"merged_at":null,"merge_commit_sha":"fee1c48724a7d24212981354f315127bfd71783a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11865/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/a8f9d00b8c14f8d8fdd61135234a5ceb606ad427","head":{"label":"alexksikes:feature/query-refactoring-fuzzy","ref":"feature/query-refactoring-fuzzy","sha":"a8f9d00b8c14f8d8fdd61135234a5ceb606ad427","user":{"login":"alexksikes","id":43475,"avatar_url":"https://avatars.githubusercontent.com/u/43475?v=3","gravatar_id":"","url":"https://api.github.com/users/alexksikes","html_url":"https://github.com/alexksikes","followers_url":"https://api.github.com/users/alexksikes/followers","following_url":"https://api.github.com/users/alexksikes/following{/other_user}","gists_url":"https://api.github.com/users/alexksikes/gists{/gist_id}","starred_url":"https://api.github.com/users/alexksikes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexksikes/subscriptions","organizations_url":"https://api.github.com/users/alexksikes/orgs","repos_url":"https://api.github.com/users/alexksikes/repos","events_url":"https://api.github.com/users/alexksikes/events{/privacy}","received_events_url":"https://api.github.com/users/alexksikes/received_events","type":"User","site_admin":false},"repo":{"id":15257781,"name":"elasticsearch","full_name":"alexksikes/elasticsearch","owner":{"login":"alexksikes","id":43475,"avatar_url":"https://avatars.githubusercontent.com/u/43475?v=3","gravatar_id":"","url":"https://api.github.com/users/alexksikes","html_url":"https://github.com/alexksikes","followers_url":"https://api.github.com/users/alexksikes/followers","following_url":"https://api.github.com/users/alexksikes/following{/other_user}","gists_url":"https://api.github.com/users/alexksikes/gists{/gist_id}","starred_url":"https://api.github.com/users/alexksikes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexksikes/subscriptions","organizations_url":"https://api.github.com/users/alexksikes/orgs","repos_url":"https://api.github.com/users/alexksikes/repos","events_url":"https://api.github.com/users/alexksikes/events{/privacy}","received_events_url":"https://api.github.com/users/alexksikes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alexksikes/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/alexksikes/elasticsearch","forks_url":"https://api.github.com/repos/alexksikes/elasticsearch/forks","keys_url":"https://api.github.com/repos/alexksikes/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alexksikes/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alexksikes/elasticsearch/teams","hooks_url":"https://api.github.com/repos/alexksikes/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/alexksikes/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/alexksikes/elasticsearch/events","assignees_url":"https://api.github.com/repos/alexksikes/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/alexksikes/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/alexksikes/elasticsearch/tags","blobs_url":"https://api.github.com/repos/alexksikes/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alexksikes/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alexksikes/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/alexksikes/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alexksikes/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/alexksikes/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/alexksikes/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/alexksikes/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/alexksikes/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/alexksikes/elasticsearch/subscription","commits_url":"https://api.github.com/repos/alexksikes/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/alexksikes/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/alexksikes/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/alexksikes/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/alexksikes/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/alexksikes/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alexksikes/elasticsearch/merges","archive_url":"https://api.github.com/repos/alexksikes/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alexksikes/elasticsearch/downloads","issues_url":"https://api.github.com/repos/alexksikes/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/alexksikes/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/alexksikes/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/alexksikes/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alexksikes/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/alexksikes/elasticsearch/releases{/id}","created_at":"2013-12-17T15:15:49Z","updated_at":"2015-03-10T00:44:52Z","pushed_at":"2015-06-24T23:34:31Z","git_url":"git://github.com/alexksikes/elasticsearch.git","ssh_url":"git@github.com:alexksikes/elasticsearch.git","clone_url":"https://github.com/alexksikes/elasticsearch.git","svn_url":"https://github.com/alexksikes/elasticsearch","homepage":"http://elasticsearch.org","size":120302,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:feature/query-refactoring","ref":"feature/query-refactoring","sha":"a2122fdc2b88861841ded9e1fd95c91ce2ad9e30","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":507775,"name":"elasticsearch","full_name":"elastic/elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":false,"url":"https://api.github.com/repos/elastic/elasticsearch","forks_url":"https://api.github.com/repos/elastic/elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/elasticsearch/releases{/id}","created_at":"2010-02-08T13:20:56Z","updated_at":"2015-06-25T07:23:36Z","pushed_at":"2015-06-25T07:45:28Z","git_url":"git://github.com/elastic/elasticsearch.git","ssh_url":"git@github.com:elastic/elasticsearch.git","clone_url":"https://github.com/elastic/elasticsearch.git","svn_url":"https://github.com/elastic/elasticsearch","homepage":"https://www.elastic.co/products/elasticsearch","size":1896685,"stargazers_count":11754,"watchers_count":11754,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3715,"mirror_url":null,"open_issues_count":1124,"forks":3715,"open_issues":1124,"watchers":11754,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/11865"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/11865"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/11865/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11865/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/a8f9d00b8c14f8d8fdd61135234a5ceb606ad427"}}}}