{"action":"created","comment":{"url":"https://api.github.com/repos/apache/couchdb-mango/pulls/comments/43590604","id":43590604,"diff_hunk":"@@ -283,6 +283,23 @@ indexable_fields(Fields, {op_and, Args}) when is_list(Args) ->\n     lists:foldl(fun(Arg, Fields0) -> indexable_fields(Fields0, Arg) end,\n         Fields, Args);\n \n+%% For queries that use array element access or $in operations, two\n+%% fields get generated by mango_selector_text:convert. At index\n+%% definition time, only one field gets defined. In this situation, we\n+%% remove the extra generated field so that the index can be used. For\n+%% all other situations, we include the fields as normal.\n+indexable_fields(Fields, {op_or, [{op_field, Field0},\n+        {op_field, {[Name | _], _}} = Field1]}) ->\n+    case lists:member(<<\"[]\">>, Name) of\n+        true ->\n+            indexable_fields(Fields, Field1);\n+        false ->\n+            Fields1 = indexable_fields(Fields, Field0),\n+            indexable_fields(Fields1, Field1)\n+    end;\n+indexable_fields(Fields, {op_or, Args}) when is_list(Args) ->","path":"src/mango_idx_text.erl","position":18,"original_position":18,"commit_id":"62362de9a2d46f392315a4399d8a7bb5e1c499e0","original_commit_id":"62362de9a2d46f392315a4399d8a7bb5e1c499e0","user":{"login":"kxepal","id":785983,"avatar_url":"https://avatars.githubusercontent.com/u/785983?v=3","gravatar_id":"","url":"https://api.github.com/users/kxepal","html_url":"https://github.com/kxepal","followers_url":"https://api.github.com/users/kxepal/followers","following_url":"https://api.github.com/users/kxepal/following{/other_user}","gists_url":"https://api.github.com/users/kxepal/gists{/gist_id}","starred_url":"https://api.github.com/users/kxepal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kxepal/subscriptions","organizations_url":"https://api.github.com/users/kxepal/orgs","repos_url":"https://api.github.com/users/kxepal/repos","events_url":"https://api.github.com/users/kxepal/events{/privacy}","received_events_url":"https://api.github.com/users/kxepal/received_events","type":"User","site_admin":false},"body":"@tonysun83 I actually mean that lines 300-302 duplicates lines 303-305 (:","created_at":"2015-11-02T00:13:53Z","updated_at":"2015-11-02T00:13:53Z","html_url":"https://github.com/apache/couchdb-mango/pull/25#discussion_r43590604","pull_request_url":"https://api.github.com/repos/apache/couchdb-mango/pulls/25","_links":{"self":{"href":"https://api.github.com/repos/apache/couchdb-mango/pulls/comments/43590604"},"html":{"href":"https://github.com/apache/couchdb-mango/pull/25#discussion_r43590604"},"pull_request":{"href":"https://api.github.com/repos/apache/couchdb-mango/pulls/25"}}},"pull_request":{"url":"https://api.github.com/repos/apache/couchdb-mango/pulls/25","id":49328683,"html_url":"https://github.com/apache/couchdb-mango/pull/25","diff_url":"https://github.com/apache/couchdb-mango/pull/25.diff","patch_url":"https://github.com/apache/couchdb-mango/pull/25.patch","issue_url":"https://api.github.com/repos/apache/couchdb-mango/issues/25","number":25,"state":"open","locked":false,"title":"Fix User Defined Index Selection","user":{"login":"tonysun83","id":6991573,"avatar_url":"https://avatars.githubusercontent.com/u/6991573?v=3","gravatar_id":"","url":"https://api.github.com/users/tonysun83","html_url":"https://github.com/tonysun83","followers_url":"https://api.github.com/users/tonysun83/followers","following_url":"https://api.github.com/users/tonysun83/following{/other_user}","gists_url":"https://api.github.com/users/tonysun83/gists{/gist_id}","starred_url":"https://api.github.com/users/tonysun83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tonysun83/subscriptions","organizations_url":"https://api.github.com/users/tonysun83/orgs","repos_url":"https://api.github.com/users/tonysun83/repos","events_url":"https://api.github.com/users/tonysun83/events{/privacy}","received_events_url":"https://api.github.com/users/tonysun83/received_events","type":"User","site_admin":false},"body":"Users were complaining that certain operators such as $in and $size were throwing a \"no usable index\" error. It turns out that when a user defines their own set of fields to be indexed, we weren't correctly selecting the indexes because of our field generator. Example, when a user did\r\n\r\n{\"selector\": \"favorites\": {\"$in\": [\"Ruby\"]}}\r\n\r\nWe actually create two fields underneath the covers: favorites.[]:string, and favorites:string. We need these extra fields to correctly perform certain searches such as $in.\r\n\r\nWhen users use the operator $size, we also create favorites.[]:length.\r\n\r\nWhen users index an array, they usually just index one field, i.e favorites.[]:string. When selecting an index, we make sure the fields from the selector are a subset of the user-defined fields. Unfortunately, because we generate extra fields, this throws the \"no usable_index error\". \r\n\r\nThis fix modifies indexable_fields to remove extraneous fields (only for the fields check, not from the actual selector) that are created by the mango_selector_text:convert function so that\r\nthe index can now be used when accessing arrays, $in operations, and\r\n$size operations.\r\n","created_at":"2015-10-30T22:15:58Z","updated_at":"2015-11-02T00:13:53Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e2f937863e23fa58ab19628f154c93d88c2e41f9","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/couchdb-mango/pulls/25/commits","review_comments_url":"https://api.github.com/repos/apache/couchdb-mango/pulls/25/comments","review_comment_url":"https://api.github.com/repos/apache/couchdb-mango/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/couchdb-mango/issues/25/comments","statuses_url":"https://api.github.com/repos/apache/couchdb-mango/statuses/62362de9a2d46f392315a4399d8a7bb5e1c499e0","head":{"label":"apache:2835-fix-index-selection","ref":"2835-fix-index-selection","sha":"62362de9a2d46f392315a4399d8a7bb5e1c499e0","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":30287956,"name":"couchdb-mango","full_name":"apache/couchdb-mango","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/couchdb-mango","description":"Mirror of Apache CouchDB Mango","fork":false,"url":"https://api.github.com/repos/apache/couchdb-mango","forks_url":"https://api.github.com/repos/apache/couchdb-mango/forks","keys_url":"https://api.github.com/repos/apache/couchdb-mango/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/couchdb-mango/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/couchdb-mango/teams","hooks_url":"https://api.github.com/repos/apache/couchdb-mango/hooks","issue_events_url":"https://api.github.com/repos/apache/couchdb-mango/issues/events{/number}","events_url":"https://api.github.com/repos/apache/couchdb-mango/events","assignees_url":"https://api.github.com/repos/apache/couchdb-mango/assignees{/user}","branches_url":"https://api.github.com/repos/apache/couchdb-mango/branches{/branch}","tags_url":"https://api.github.com/repos/apache/couchdb-mango/tags","blobs_url":"https://api.github.com/repos/apache/couchdb-mango/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/couchdb-mango/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/couchdb-mango/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/couchdb-mango/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/couchdb-mango/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/couchdb-mango/languages","stargazers_url":"https://api.github.com/repos/apache/couchdb-mango/stargazers","contributors_url":"https://api.github.com/repos/apache/couchdb-mango/contributors","subscribers_url":"https://api.github.com/repos/apache/couchdb-mango/subscribers","subscription_url":"https://api.github.com/repos/apache/couchdb-mango/subscription","commits_url":"https://api.github.com/repos/apache/couchdb-mango/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/couchdb-mango/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/couchdb-mango/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/couchdb-mango/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/couchdb-mango/contents/{+path}","compare_url":"https://api.github.com/repos/apache/couchdb-mango/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/couchdb-mango/merges","archive_url":"https://api.github.com/repos/apache/couchdb-mango/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/couchdb-mango/downloads","issues_url":"https://api.github.com/repos/apache/couchdb-mango/issues{/number}","pulls_url":"https://api.github.com/repos/apache/couchdb-mango/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/couchdb-mango/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/couchdb-mango/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/couchdb-mango/labels{/name}","releases_url":"https://api.github.com/repos/apache/couchdb-mango/releases{/id}","created_at":"2015-02-04T08:00:05Z","updated_at":"2015-09-03T09:29:41Z","pushed_at":"2015-10-30T22:15:59Z","git_url":"git://github.com/apache/couchdb-mango.git","ssh_url":"git@github.com:apache/couchdb-mango.git","clone_url":"https://github.com/apache/couchdb-mango.git","svn_url":"https://github.com/apache/couchdb-mango","homepage":null,"size":885,"stargazers_count":18,"watchers_count":18,"language":"Erlang","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":"git://git.apache.org/couchdb-mango.git","open_issues_count":3,"forks":5,"open_issues":3,"watchers":18,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"090dc67501d5beff6820f7fd8c77a18e46cd58ee","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":30287956,"name":"couchdb-mango","full_name":"apache/couchdb-mango","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/couchdb-mango","description":"Mirror of Apache CouchDB Mango","fork":false,"url":"https://api.github.com/repos/apache/couchdb-mango","forks_url":"https://api.github.com/repos/apache/couchdb-mango/forks","keys_url":"https://api.github.com/repos/apache/couchdb-mango/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/couchdb-mango/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/couchdb-mango/teams","hooks_url":"https://api.github.com/repos/apache/couchdb-mango/hooks","issue_events_url":"https://api.github.com/repos/apache/couchdb-mango/issues/events{/number}","events_url":"https://api.github.com/repos/apache/couchdb-mango/events","assignees_url":"https://api.github.com/repos/apache/couchdb-mango/assignees{/user}","branches_url":"https://api.github.com/repos/apache/couchdb-mango/branches{/branch}","tags_url":"https://api.github.com/repos/apache/couchdb-mango/tags","blobs_url":"https://api.github.com/repos/apache/couchdb-mango/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/couchdb-mango/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/couchdb-mango/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/couchdb-mango/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/couchdb-mango/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/couchdb-mango/languages","stargazers_url":"https://api.github.com/repos/apache/couchdb-mango/stargazers","contributors_url":"https://api.github.com/repos/apache/couchdb-mango/contributors","subscribers_url":"https://api.github.com/repos/apache/couchdb-mango/subscribers","subscription_url":"https://api.github.com/repos/apache/couchdb-mango/subscription","commits_url":"https://api.github.com/repos/apache/couchdb-mango/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/couchdb-mango/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/couchdb-mango/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/couchdb-mango/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/couchdb-mango/contents/{+path}","compare_url":"https://api.github.com/repos/apache/couchdb-mango/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/couchdb-mango/merges","archive_url":"https://api.github.com/repos/apache/couchdb-mango/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/couchdb-mango/downloads","issues_url":"https://api.github.com/repos/apache/couchdb-mango/issues{/number}","pulls_url":"https://api.github.com/repos/apache/couchdb-mango/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/couchdb-mango/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/couchdb-mango/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/couchdb-mango/labels{/name}","releases_url":"https://api.github.com/repos/apache/couchdb-mango/releases{/id}","created_at":"2015-02-04T08:00:05Z","updated_at":"2015-09-03T09:29:41Z","pushed_at":"2015-10-30T22:15:59Z","git_url":"git://github.com/apache/couchdb-mango.git","ssh_url":"git@github.com:apache/couchdb-mango.git","clone_url":"https://github.com/apache/couchdb-mango.git","svn_url":"https://github.com/apache/couchdb-mango","homepage":null,"size":885,"stargazers_count":18,"watchers_count":18,"language":"Erlang","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":5,"mirror_url":"git://git.apache.org/couchdb-mango.git","open_issues_count":3,"forks":5,"open_issues":3,"watchers":18,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/couchdb-mango/pulls/25"},"html":{"href":"https://github.com/apache/couchdb-mango/pull/25"},"issue":{"href":"https://api.github.com/repos/apache/couchdb-mango/issues/25"},"comments":{"href":"https://api.github.com/repos/apache/couchdb-mango/issues/25/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/couchdb-mango/pulls/25/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/couchdb-mango/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/couchdb-mango/pulls/25/commits"},"statuses":{"href":"https://api.github.com/repos/apache/couchdb-mango/statuses/62362de9a2d46f392315a4399d8a7bb5e1c499e0"}}}}