{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/31700522","id":31700522,"diff_hunk":"@@ -217,4 +292,136 @@ public void doXContent(XContentBuilder builder, Params params) throws IOExceptio\n     public String queryId() {\n         return NAME;\n     }\n+\n+    @Override\n+    public Query toQuery(QueryParseContext parseContext) throws QueryParsingException, IOException {\n+        String field;\n+        FieldMapper mapper = parseContext.fieldMapper(fieldName);\n+        if (mapper != null) {\n+            field = mapper.names().indexName();\n+        } else {\n+            field = fieldName;\n+        }\n+\n+        Analyzer analyzerObj;\n+        if (analyzer == null) {\n+            if (mapper != null) {\n+                analyzerObj = parseContext.getSearchAnalyzer(mapper);\n+            } else {\n+                analyzerObj = parseContext.mapperService().searchAnalyzer();\n+            }\n+        } else {\n+            analyzerObj = parseContext.mapperService().analysisService().analyzer(analyzer);\n+            if (analyzerObj == null) {\n+                throw new IllegalArgumentException(\"No analyzer found for [\" + analyzer + \"]\");\n+            }\n+        }\n+        \n+        Occur highFreqOccur = highFreqOperator.equals(Operator.AND) ? Occur.MUST : Occur.SHOULD;\n+        Occur lowFreqOccur = lowFreqOperator.equals(Operator.AND) ? Occur.MUST : Occur.SHOULD;\n+\n+        ExtendedCommonTermsQuery commonsQuery = new ExtendedCommonTermsQuery(highFreqOccur, lowFreqOccur, cutoffFrequency, disableCoord, mapper);\n+        Query query = parseQueryString(commonsQuery, text, field, analyzerObj, lowFreqMinimumShouldMatch, highFreqMinimumShouldMatch);\n+\n+        query.setBoost(boost);\n+        if (queryName != null) {\n+            parseContext.addNamedQuery(queryName, query);\n+        }\n+        return query;\n+    }\n+    \n+    public static final Query parseQueryString(ExtendedCommonTermsQuery query, String queryString, String field, Analyzer analyzer, \n+                                         String lowFreqMinimumShouldMatch, String highFreqMinimumShouldMatch) throws IOException {\n+        // Logic similar to QueryParser#getFieldQuery\n+        int count = 0;\n+        try (TokenStream source = analyzer.tokenStream(field, queryString.toString())) {\n+            source.reset();\n+            CharTermAttribute termAtt = source.addAttribute(CharTermAttribute.class);\n+            BytesRefBuilder builder = new BytesRefBuilder();\n+            while (source.incrementToken()) {\n+                // UTF-8\n+                builder.copyChars(termAtt);\n+                query.add(new Term(field, builder.toBytesRef()));\n+                count++;\n+            }\n+        }\n+\n+        if (count == 0) {\n+            return null;\n+        }\n+        query.setLowFreqMinimumNumberShouldMatch(lowFreqMinimumShouldMatch);\n+        query.setHighFreqMinimumNumberShouldMatch(highFreqMinimumShouldMatch);\n+        return query;\n+    }\n+\n+    @Override\n+    public QueryValidationException validate() {\n+        QueryValidationException validationException = null;\n+        if (this.fieldName == null || this.fieldName.isEmpty()) {\n+            validationException = QueryValidationException.addValidationError(\"field name cannot be null or empty.\", validationException);\n+        }\n+        if (this.text == null || this.text.isEmpty()) {","path":"src/main/java/org/elasticsearch/index/query/CommonTermsQueryBuilder.java","position":324,"original_position":324,"commit_id":"3f67d9af7e19014dd680d931245fc79c3c77f1a1","original_commit_id":"3f67d9af7e19014dd680d931245fc79c3c77f1a1","user":{"login":"javanna","id":832460,"avatar_url":"https://avatars.githubusercontent.com/u/832460?v=3","gravatar_id":"","url":"https://api.github.com/users/javanna","html_url":"https://github.com/javanna","followers_url":"https://api.github.com/users/javanna/followers","following_url":"https://api.github.com/users/javanna/following{/other_user}","gists_url":"https://api.github.com/users/javanna/gists{/gist_id}","starred_url":"https://api.github.com/users/javanna/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/javanna/subscriptions","organizations_url":"https://api.github.com/users/javanna/orgs","repos_url":"https://api.github.com/users/javanna/repos","events_url":"https://api.github.com/users/javanna/events{/privacy}","received_events_url":"https://api.github.com/users/javanna/received_events","type":"User","site_admin":false},"body":"same as above","created_at":"2015-06-04T08:12:14Z","updated_at":"2015-06-04T08:12:14Z","html_url":"https://github.com/elastic/elasticsearch/pull/11345#discussion_r31700522","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/31700522"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/11345#discussion_r31700522"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345","id":36188020,"html_url":"https://github.com/elastic/elasticsearch/pull/11345","diff_url":"https://github.com/elastic/elasticsearch/pull/11345.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/11345.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11345","number":11345,"state":"open","locked":false,"title":"Refactors CommonTermsQuery","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":"Refactors CommonTermsQuery analogous to TermQueryBuilder. Still left to do are\r\nthe tests to compare between builder and actual Lucene query.\r\n\r\nRelates to #10217\r\n\r\nThis PR is against the query-refactoring branch.","created_at":"2015-05-26T10:19:02Z","updated_at":"2015-06-04T08:12:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5cd3898fbe3bad25ff517d6e0ade134d05c4eb1e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/11345/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/3f67d9af7e19014dd680d931245fc79c3c77f1a1","head":{"label":"alexksikes:feature/query-refactoring-common-terms","ref":"feature/query-refactoring-common-terms","sha":"3f67d9af7e19014dd680d931245fc79c3c77f1a1","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-03T23:49:39Z","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":111398,"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":"b1f6d1abd65735f6abee642212bb4b4569fe1aca","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-04T08:11:20Z","pushed_at":"2015-06-04T07:21:22Z","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":1901572,"stargazers_count":11471,"watchers_count":11471,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3628,"mirror_url":null,"open_issues_count":1099,"forks":3628,"open_issues":1099,"watchers":11471,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/11345"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/11345"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/11345/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/11345/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/3f67d9af7e19014dd680d931245fc79c3c77f1a1"}}}}