{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/34264664","id":34264664,"diff_hunk":"@@ -19,71 +19,181 @@\n \n package org.elasticsearch.index.query;\n \n+import org.apache.lucene.search.Query;\n+import org.apache.lucene.search.spans.SpanNearQuery;\n+import org.apache.lucene.search.spans.SpanQuery;\n+import org.elasticsearch.common.io.stream.StreamInput;\n+import org.elasticsearch.common.io.stream.StreamOutput;\n import org.elasticsearch.common.xcontent.XContentBuilder;\n \n import java.io.IOException;\n import java.util.ArrayList;\n+import java.util.List;\n+import java.util.Objects;\n \n+/**\n+ * Matches spans which are near one another. One can specify slop, the maximum number\n+ * of intervening unmatched positions, as well as whether matches are required to be in-order.\n+ * The span near query maps to Lucene {@link SpanNearQuery}.\n+ */\n public class SpanNearQueryBuilder extends AbstractQueryBuilder<SpanNearQueryBuilder> implements SpanQueryBuilder<SpanNearQueryBuilder> {\n \n     public static final String NAME = \"span_near\";\n \n-    private ArrayList<SpanQueryBuilder> clauses = new ArrayList<>();\n+    /** Default for flag controlling whether matches are required to be in-order */\n+    public static boolean DEFAULT_IN_ORDER = true;\n+\n+    /** Default for flag controlling whether payload is collected */\n+    public static boolean DEFAULT_COLLECT_PAYLOADS = true;\n+\n+    private final ArrayList<SpanQueryBuilder> clauses = new ArrayList<>();\n \n-    private Integer slop = null;\n+    private final int slop;\n \n-    private Boolean inOrder;\n+    private boolean inOrder = DEFAULT_IN_ORDER;\n \n-    private Boolean collectPayloads;\n+    private boolean collectPayloads = DEFAULT_COLLECT_PAYLOADS;\n \n     static final SpanNearQueryBuilder PROTOTYPE = new SpanNearQueryBuilder();\n \n+    /**\n+     * @param slop controls the maximum number of intervening unmatched positions permitted\n+     */\n+    public SpanNearQueryBuilder(int slop) {\n+        this.slop = slop;\n+    }\n+\n+    /**\n+     * only used for prototype\n+     */\n+    private SpanNearQueryBuilder() {\n+        this.slop = 0;\n+    }\n+\n+    /**\n+     * @return the maximum number of intervening unmatched positions permitted\n+     */\n+    public int slop() {\n+        return this.slop;\n+    }\n+\n     public SpanNearQueryBuilder clause(SpanQueryBuilder clause) {\n-        clauses.add(clause);\n+        clauses.add(Objects.requireNonNull(clause));\n         return this;\n     }\n \n-    public SpanNearQueryBuilder slop(int slop) {\n-        this.slop = slop;\n-        return this;\n+    /**\n+     * @return the {@link SpanQueryBuilder} clauses that were set for this query\n+     */\n+    public List<SpanQueryBuilder> clauses() {\n+        return this.clauses;\n     }\n \n+    /**\n+     * When <code>inOrder</code> is true, the spans from each clause\n+     * must be in the same order as in <code>clauses</code> and must be non-overlapping.\n+     * Defaults to <code>true</code>\n+     */\n     public SpanNearQueryBuilder inOrder(boolean inOrder) {\n         this.inOrder = inOrder;\n         return this;\n     }\n \n+    /**\n+     * @see SpanNearQueryBuilder#inOrder(boolean))\n+     */\n+    public boolean inOrder() {\n+        return this.inOrder;\n+    }\n+\n+    /**\n+     * @param collectPayloads flag controlling whether payload is collected","path":"core/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java","position":100,"original_position":100,"commit_id":"c9dbd7a9011be40cd69ab7c8260ab7869f76bbc4","original_commit_id":"c9dbd7a9011be40cd69ab7c8260ab7869f76bbc4","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":"s/payload is/payloads are","created_at":"2015-07-09T15:02:18Z","updated_at":"2015-07-09T15:02:18Z","html_url":"https://github.com/elastic/elasticsearch/pull/12156#discussion_r34264664","pull_request_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156","_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments/34264664"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/12156#discussion_r34264664"},"pull_request":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156","id":39586483,"html_url":"https://github.com/elastic/elasticsearch/pull/12156","diff_url":"https://github.com/elastic/elasticsearch/pull/12156.diff","patch_url":"https://github.com/elastic/elasticsearch/pull/12156.patch","issue_url":"https://api.github.com/repos/elastic/elasticsearch/issues/12156","number":12156,"state":"open","locked":false,"title":"Query refactoring: SpanNearQueryBuilder and Parser","user":{"login":"cbuescher","id":10398885,"avatar_url":"https://avatars.githubusercontent.com/u/10398885?v=3","gravatar_id":"","url":"https://api.github.com/users/cbuescher","html_url":"https://github.com/cbuescher","followers_url":"https://api.github.com/users/cbuescher/followers","following_url":"https://api.github.com/users/cbuescher/following{/other_user}","gists_url":"https://api.github.com/users/cbuescher/gists{/gist_id}","starred_url":"https://api.github.com/users/cbuescher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbuescher/subscriptions","organizations_url":"https://api.github.com/users/cbuescher/orgs","repos_url":"https://api.github.com/users/cbuescher/repos","events_url":"https://api.github.com/users/cbuescher/events{/privacy}","received_events_url":"https://api.github.com/users/cbuescher/received_events","type":"User","site_admin":false},"body":"Moving the query building functionality from the parser to the builders\r\nnew toQuery() method analogous to other recent query refactorings.\r\n\r\nRelates to #10217 \r\n\r\nThis PR is agains the query refactoring branch.","created_at":"2015-07-09T14:05:50Z","updated_at":"2015-07-09T15:02:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"31dd8ab0fbc11fa93c54f3f2093960e1af4b1956","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156/commits","review_comments_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156/comments","review_comment_url":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/elasticsearch/issues/12156/comments","statuses_url":"https://api.github.com/repos/elastic/elasticsearch/statuses/c9dbd7a9011be40cd69ab7c8260ab7869f76bbc4","head":{"label":"cbuescher:feature/query-refactoring-spannear","ref":"feature/query-refactoring-spannear","sha":"c9dbd7a9011be40cd69ab7c8260ab7869f76bbc4","user":{"login":"cbuescher","id":10398885,"avatar_url":"https://avatars.githubusercontent.com/u/10398885?v=3","gravatar_id":"","url":"https://api.github.com/users/cbuescher","html_url":"https://github.com/cbuescher","followers_url":"https://api.github.com/users/cbuescher/followers","following_url":"https://api.github.com/users/cbuescher/following{/other_user}","gists_url":"https://api.github.com/users/cbuescher/gists{/gist_id}","starred_url":"https://api.github.com/users/cbuescher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbuescher/subscriptions","organizations_url":"https://api.github.com/users/cbuescher/orgs","repos_url":"https://api.github.com/users/cbuescher/repos","events_url":"https://api.github.com/users/cbuescher/events{/privacy}","received_events_url":"https://api.github.com/users/cbuescher/received_events","type":"User","site_admin":false},"repo":{"id":28811483,"name":"elasticsearch","full_name":"cbuescher/elasticsearch","owner":{"login":"cbuescher","id":10398885,"avatar_url":"https://avatars.githubusercontent.com/u/10398885?v=3","gravatar_id":"","url":"https://api.github.com/users/cbuescher","html_url":"https://github.com/cbuescher","followers_url":"https://api.github.com/users/cbuescher/followers","following_url":"https://api.github.com/users/cbuescher/following{/other_user}","gists_url":"https://api.github.com/users/cbuescher/gists{/gist_id}","starred_url":"https://api.github.com/users/cbuescher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cbuescher/subscriptions","organizations_url":"https://api.github.com/users/cbuescher/orgs","repos_url":"https://api.github.com/users/cbuescher/repos","events_url":"https://api.github.com/users/cbuescher/events{/privacy}","received_events_url":"https://api.github.com/users/cbuescher/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/cbuescher/elasticsearch","description":"Open Source, Distributed, RESTful Search Engine","fork":true,"url":"https://api.github.com/repos/cbuescher/elasticsearch","forks_url":"https://api.github.com/repos/cbuescher/elasticsearch/forks","keys_url":"https://api.github.com/repos/cbuescher/elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cbuescher/elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cbuescher/elasticsearch/teams","hooks_url":"https://api.github.com/repos/cbuescher/elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/cbuescher/elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/cbuescher/elasticsearch/events","assignees_url":"https://api.github.com/repos/cbuescher/elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/cbuescher/elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/cbuescher/elasticsearch/tags","blobs_url":"https://api.github.com/repos/cbuescher/elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cbuescher/elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cbuescher/elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/cbuescher/elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cbuescher/elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/cbuescher/elasticsearch/languages","stargazers_url":"https://api.github.com/repos/cbuescher/elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/cbuescher/elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/cbuescher/elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/cbuescher/elasticsearch/subscription","commits_url":"https://api.github.com/repos/cbuescher/elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/cbuescher/elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/cbuescher/elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/cbuescher/elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/cbuescher/elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/cbuescher/elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cbuescher/elasticsearch/merges","archive_url":"https://api.github.com/repos/cbuescher/elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cbuescher/elasticsearch/downloads","issues_url":"https://api.github.com/repos/cbuescher/elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/cbuescher/elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/cbuescher/elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/cbuescher/elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cbuescher/elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/cbuescher/elasticsearch/releases{/id}","created_at":"2015-01-05T12:21:34Z","updated_at":"2015-01-19T11:05:49Z","pushed_at":"2015-07-09T15:00:02Z","git_url":"git://github.com/cbuescher/elasticsearch.git","ssh_url":"git@github.com:cbuescher/elasticsearch.git","clone_url":"https://github.com/cbuescher/elasticsearch.git","svn_url":"https://github.com/cbuescher/elasticsearch","homepage":"http://elasticsearch.org","size":138522,"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":"6c79569caef4ec6de992b4a6997b86ddbeb15662","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-07-09T14:36:32Z","pushed_at":"2015-07-09T15:00:11Z","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":1903378,"stargazers_count":11928,"watchers_count":11928,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3797,"mirror_url":null,"open_issues_count":1127,"forks":3797,"open_issues":1127,"watchers":11928,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156"},"html":{"href":"https://github.com/elastic/elasticsearch/pull/12156"},"issue":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/12156"},"comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/issues/12156/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/elasticsearch/pulls/12156/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/elasticsearch/statuses/c9dbd7a9011be40cd69ab7c8260ab7869f76bbc4"}}}}