{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/addons-server/pulls/comments/62020210","id":62020210,"diff_hunk":"@@ -105,6 +112,72 @@ def filter_queryset(self, request, qs, view):\n             should=primary_should + secondary_should), functions=functions)\n \n \n+class SearchParameterFilter(BaseFilterBackend):\n+    \"\"\"\n+    A django-rest-framework filter backend that filters only items in an ES\n+    query that match a specific set of fields: app, platform and type.\n+    \"\"\"\n+    # FIXME: add appversion.\n+\n+    Filter = namedtuple(\n+        'Filter', ['query_param', 'valid_values', 'reverse', 'es_field'])\n+    available_filters = [\n+        Filter(query_param='app', valid_values=amo.APP_IDS,\n+               reverse=amo.APPS, es_field='app'),\n+        Filter(query_param='platform', valid_values=amo.PLATFORMS,\n+               reverse=amo.PLATFORM_DICT, es_field='platforms'),\n+        Filter(query_param='type', valid_values=amo.ADDON_SEARCH_TYPES,\n+               reverse=amo.ADDON_SEARCH_SLUGS, es_field='type'),\n+    ]\n+\n+    def filter_queryset(self, request, qs, view):\n+        must = []\n+\n+        for filter_instance in self.available_filters:\n+            operator = 'term'\n+            if filter_instance.query_param in request.GET:\n+                value = request.GET[filter_instance.query_param]\n+                try:\n+                    # Try the int first.\n+                    value = int(value)\n+                except ValueError:\n+                    # Fall back on the string, which needs to be in the reverse\n+                    # dict.\n+                    value = filter_instance.reverse.get(value.lower())\n+                    # If our reverse dict contains objects and not integers,\n+                    # like for platforms and apps, we need an extra step to\n+                    # find the integer value.\n+                    if hasattr(value, 'id'):\n+                        value = value.id\n+                if value in filter_instance.valid_values:\n+                    # Small hack to support the fact that an add-on with\n+                    # PLATFORM_ALL set supports any platform: when filtering\n+                    # by any platform, always include PLATFORM_ALL. This means\n+                    # we need to change the operator to use 'terms' instead of\n+                    # 'term'.\n+                    if (filter_instance.query_param == 'platform' and\n+                            value != amo.PLATFORM_ALL.id):\n+                        value = [value, amo.PLATFORM_ALL.id]\n+                        operator = 'terms'\n+                    must.append(\n+                        F(operator, **{filter_instance.es_field: value}))\n+","path":"src/olympia/search/filters.py","position":null,"original_position":71,"commit_id":"d32e7703d5651bb20ba7139f3472bf3968750158","original_commit_id":"bbc46120545dd60c08f01eba53c27f83ba9d5ed4","user":{"login":"EnTeQuAk","id":139033,"avatar_url":"https://avatars.githubusercontent.com/u/139033?v=3","gravatar_id":"","url":"https://api.github.com/users/EnTeQuAk","html_url":"https://github.com/EnTeQuAk","followers_url":"https://api.github.com/users/EnTeQuAk/followers","following_url":"https://api.github.com/users/EnTeQuAk/following{/other_user}","gists_url":"https://api.github.com/users/EnTeQuAk/gists{/gist_id}","starred_url":"https://api.github.com/users/EnTeQuAk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EnTeQuAk/subscriptions","organizations_url":"https://api.github.com/users/EnTeQuAk/orgs","repos_url":"https://api.github.com/users/EnTeQuAk/repos","events_url":"https://api.github.com/users/EnTeQuAk/events{/privacy}","received_events_url":"https://api.github.com/users/EnTeQuAk/received_events","type":"User","site_admin":false},"body":"I love it, thanks. Looks great now :+1: :cake: :beers: :star2:","created_at":"2016-05-04T10:49:15Z","updated_at":"2016-05-04T10:49:15Z","html_url":"https://github.com/mozilla/addons-server/pull/2548#discussion_r62020210","pull_request_url":"https://api.github.com/repos/mozilla/addons-server/pulls/2548","_links":{"self":{"href":"https://api.github.com/repos/mozilla/addons-server/pulls/comments/62020210"},"html":{"href":"https://github.com/mozilla/addons-server/pull/2548#discussion_r62020210"},"pull_request":{"href":"https://api.github.com/repos/mozilla/addons-server/pulls/2548"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/addons-server/pulls/2548","id":68723738,"html_url":"https://github.com/mozilla/addons-server/pull/2548","diff_url":"https://github.com/mozilla/addons-server/pull/2548.diff","patch_url":"https://github.com/mozilla/addons-server/pull/2548.patch","issue_url":"https://api.github.com/repos/mozilla/addons-server/issues/2548","number":2548,"state":"open","locked":false,"title":"Filter search API by type, application, platform, status (fix #2545)","user":{"login":"diox","id":187006,"avatar_url":"https://avatars.githubusercontent.com/u/187006?v=3","gravatar_id":"","url":"https://api.github.com/users/diox","html_url":"https://github.com/diox","followers_url":"https://api.github.com/users/diox/followers","following_url":"https://api.github.com/users/diox/following{/other_user}","gists_url":"https://api.github.com/users/diox/gists{/gist_id}","starred_url":"https://api.github.com/users/diox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diox/subscriptions","organizations_url":"https://api.github.com/users/diox/orgs","repos_url":"https://api.github.com/users/diox/repos","events_url":"https://api.github.com/users/diox/events{/privacy}","received_events_url":"https://api.github.com/users/diox/received_events","type":"User","site_admin":false},"body":"#2545","created_at":"2016-05-03T15:22:36Z","updated_at":"2016-05-04T10:49:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f0c4b20ceaadd2671716021bfffd0dae3c61c7a0","assignee":{"login":"EnTeQuAk","id":139033,"avatar_url":"https://avatars.githubusercontent.com/u/139033?v=3","gravatar_id":"","url":"https://api.github.com/users/EnTeQuAk","html_url":"https://github.com/EnTeQuAk","followers_url":"https://api.github.com/users/EnTeQuAk/followers","following_url":"https://api.github.com/users/EnTeQuAk/following{/other_user}","gists_url":"https://api.github.com/users/EnTeQuAk/gists{/gist_id}","starred_url":"https://api.github.com/users/EnTeQuAk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/EnTeQuAk/subscriptions","organizations_url":"https://api.github.com/users/EnTeQuAk/orgs","repos_url":"https://api.github.com/users/EnTeQuAk/repos","events_url":"https://api.github.com/users/EnTeQuAk/events{/privacy}","received_events_url":"https://api.github.com/users/EnTeQuAk/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/addons-server/pulls/2548/commits","review_comments_url":"https://api.github.com/repos/mozilla/addons-server/pulls/2548/comments","review_comment_url":"https://api.github.com/repos/mozilla/addons-server/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/addons-server/issues/2548/comments","statuses_url":"https://api.github.com/repos/mozilla/addons-server/statuses/d32e7703d5651bb20ba7139f3472bf3968750158","head":{"label":"diox:search-api-filtering-1","ref":"search-api-filtering-1","sha":"d32e7703d5651bb20ba7139f3472bf3968750158","user":{"login":"diox","id":187006,"avatar_url":"https://avatars.githubusercontent.com/u/187006?v=3","gravatar_id":"","url":"https://api.github.com/users/diox","html_url":"https://github.com/diox","followers_url":"https://api.github.com/users/diox/followers","following_url":"https://api.github.com/users/diox/following{/other_user}","gists_url":"https://api.github.com/users/diox/gists{/gist_id}","starred_url":"https://api.github.com/users/diox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diox/subscriptions","organizations_url":"https://api.github.com/users/diox/orgs","repos_url":"https://api.github.com/users/diox/repos","events_url":"https://api.github.com/users/diox/events{/privacy}","received_events_url":"https://api.github.com/users/diox/received_events","type":"User","site_admin":false},"repo":{"id":16844921,"name":"olympia","full_name":"diox/olympia","owner":{"login":"diox","id":187006,"avatar_url":"https://avatars.githubusercontent.com/u/187006?v=3","gravatar_id":"","url":"https://api.github.com/users/diox","html_url":"https://github.com/diox","followers_url":"https://api.github.com/users/diox/followers","following_url":"https://api.github.com/users/diox/following{/other_user}","gists_url":"https://api.github.com/users/diox/gists{/gist_id}","starred_url":"https://api.github.com/users/diox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/diox/subscriptions","organizations_url":"https://api.github.com/users/diox/orgs","repos_url":"https://api.github.com/users/diox/repos","events_url":"https://api.github.com/users/diox/events{/privacy}","received_events_url":"https://api.github.com/users/diox/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/diox/olympia","description":"AMO, reloaded.","fork":true,"url":"https://api.github.com/repos/diox/olympia","forks_url":"https://api.github.com/repos/diox/olympia/forks","keys_url":"https://api.github.com/repos/diox/olympia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/diox/olympia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/diox/olympia/teams","hooks_url":"https://api.github.com/repos/diox/olympia/hooks","issue_events_url":"https://api.github.com/repos/diox/olympia/issues/events{/number}","events_url":"https://api.github.com/repos/diox/olympia/events","assignees_url":"https://api.github.com/repos/diox/olympia/assignees{/user}","branches_url":"https://api.github.com/repos/diox/olympia/branches{/branch}","tags_url":"https://api.github.com/repos/diox/olympia/tags","blobs_url":"https://api.github.com/repos/diox/olympia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/diox/olympia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/diox/olympia/git/refs{/sha}","trees_url":"https://api.github.com/repos/diox/olympia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/diox/olympia/statuses/{sha}","languages_url":"https://api.github.com/repos/diox/olympia/languages","stargazers_url":"https://api.github.com/repos/diox/olympia/stargazers","contributors_url":"https://api.github.com/repos/diox/olympia/contributors","subscribers_url":"https://api.github.com/repos/diox/olympia/subscribers","subscription_url":"https://api.github.com/repos/diox/olympia/subscription","commits_url":"https://api.github.com/repos/diox/olympia/commits{/sha}","git_commits_url":"https://api.github.com/repos/diox/olympia/git/commits{/sha}","comments_url":"https://api.github.com/repos/diox/olympia/comments{/number}","issue_comment_url":"https://api.github.com/repos/diox/olympia/issues/comments{/number}","contents_url":"https://api.github.com/repos/diox/olympia/contents/{+path}","compare_url":"https://api.github.com/repos/diox/olympia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/diox/olympia/merges","archive_url":"https://api.github.com/repos/diox/olympia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/diox/olympia/downloads","issues_url":"https://api.github.com/repos/diox/olympia/issues{/number}","pulls_url":"https://api.github.com/repos/diox/olympia/pulls{/number}","milestones_url":"https://api.github.com/repos/diox/olympia/milestones{/number}","notifications_url":"https://api.github.com/repos/diox/olympia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/diox/olympia/labels{/name}","releases_url":"https://api.github.com/repos/diox/olympia/releases{/id}","deployments_url":"https://api.github.com/repos/diox/olympia/deployments","created_at":"2014-02-14T17:54:49Z","updated_at":"2014-12-16T18:15:35Z","pushed_at":"2016-05-04T10:44:37Z","git_url":"git://github.com/diox/olympia.git","ssh_url":"git@github.com:diox/olympia.git","clone_url":"https://github.com/diox/olympia.git","svn_url":"https://github.com/diox/olympia","homepage":"","size":488771,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"mozilla:master","ref":"master","sha":"816b6192368a1bb2f846898f96851a31be696dda","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":16416867,"name":"addons-server","full_name":"mozilla/addons-server","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/addons-server","description":"addons.mozilla.org Django app","fork":false,"url":"https://api.github.com/repos/mozilla/addons-server","forks_url":"https://api.github.com/repos/mozilla/addons-server/forks","keys_url":"https://api.github.com/repos/mozilla/addons-server/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/addons-server/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/addons-server/teams","hooks_url":"https://api.github.com/repos/mozilla/addons-server/hooks","issue_events_url":"https://api.github.com/repos/mozilla/addons-server/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/addons-server/events","assignees_url":"https://api.github.com/repos/mozilla/addons-server/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/addons-server/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/addons-server/tags","blobs_url":"https://api.github.com/repos/mozilla/addons-server/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/addons-server/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/addons-server/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/addons-server/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/addons-server/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/addons-server/languages","stargazers_url":"https://api.github.com/repos/mozilla/addons-server/stargazers","contributors_url":"https://api.github.com/repos/mozilla/addons-server/contributors","subscribers_url":"https://api.github.com/repos/mozilla/addons-server/subscribers","subscription_url":"https://api.github.com/repos/mozilla/addons-server/subscription","commits_url":"https://api.github.com/repos/mozilla/addons-server/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/addons-server/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/addons-server/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/addons-server/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/addons-server/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/addons-server/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/addons-server/merges","archive_url":"https://api.github.com/repos/mozilla/addons-server/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/addons-server/downloads","issues_url":"https://api.github.com/repos/mozilla/addons-server/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/addons-server/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/addons-server/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/addons-server/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/addons-server/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/addons-server/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/addons-server/deployments","created_at":"2014-01-31T18:44:15Z","updated_at":"2016-05-02T17:04:25Z","pushed_at":"2016-05-04T10:44:37Z","git_url":"git://github.com/mozilla/addons-server.git","ssh_url":"git@github.com:mozilla/addons-server.git","clone_url":"https://github.com/mozilla/addons-server.git","svn_url":"https://github.com/mozilla/addons-server","homepage":"https://addons.mozilla.org/","size":497926,"stargazers_count":96,"watchers_count":96,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":151,"mirror_url":null,"open_issues_count":283,"forks":151,"open_issues":283,"watchers":96,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/addons-server/pulls/2548"},"html":{"href":"https://github.com/mozilla/addons-server/pull/2548"},"issue":{"href":"https://api.github.com/repos/mozilla/addons-server/issues/2548"},"comments":{"href":"https://api.github.com/repos/mozilla/addons-server/issues/2548/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/addons-server/pulls/2548/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/addons-server/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/addons-server/pulls/2548/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/addons-server/statuses/d32e7703d5651bb20ba7139f3472bf3968750158"}}}}