{"action":"created","comment":{"url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/comments/200258155","pull_request_review_id":134536088,"id":200258155,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwMDI1ODE1NQ==","diff_hunk":"@@ -0,0 +1,67 @@\n+from rest_framework import generics\n+from rest_framework import exceptions\n+from rest_framework.exceptions import ValidationError\n+\n+from readthedocs.projects.models import Project\n+from readthedocs.search.documents import PageDocument\n+from readthedocs.search.filters import SearchFilterBackend\n+from readthedocs.search.pagination import SearchPagination\n+from readthedocs.search.serializers import PageSearchSerializer\n+\n+\n+class PageSearchAPIView(generics.ListAPIView):\n+    pagination_class = SearchPagination\n+    filter_backends = [SearchFilterBackend]\n+    serializer_class = PageSearchSerializer\n+\n+    def get_queryset(self):\n+        \"\"\"\n+        Return Elasticsearch DSL Search object instead of Django Queryset.\n+\n+        Django Queryset and elasticsearch-dsl ``Search`` object is similar pattern.\n+        So for searching, its possible to return ``Search`` object instead of queryset.\n+        The ``filter_backends`` and ``pagination_class`` is compatible with ``Search``\n+        \"\"\"\n+        # Validate all the required params are there\n+        self.validate_query_params()\n+        query = self.request.query_params.get('query', '')\n+        queryset = PageDocument.simple_search(query=query)\n+        return queryset\n+\n+    def validate_query_params(self):\n+        required_query_params = {'query', 'project', 'version'}  # python `set` literal is `{}`\n+        request_params = set(self.request.query_params.keys())\n+        missing_params = required_query_params - request_params\n+        if missing_params:\n+            errors = {}\n+            for param in missing_params:\n+                errors[param] = [\"This query param is required\"]\n+\n+            raise ValidationError(errors)\n+\n+    def get_serializer_context(self):\n+        context = super(PageSearchAPIView, self).get_serializer_context()\n+        context['projects_info'] = self.get_projects_info()","path":"readthedocs/search/api.py","position":44,"original_position":44,"commit_id":"e2e8cbba9a368ea9c65e880cedd441bc7c540fa4","original_commit_id":"e2e8cbba9a368ea9c65e880cedd441bc7c540fa4","user":{"login":"ericholscher","id":25510,"node_id":"MDQ6VXNlcjI1NTEw","avatar_url":"https://avatars2.githubusercontent.com/u/25510?v=4","gravatar_id":"","url":"https://api.github.com/users/ericholscher","html_url":"https://github.com/ericholscher","followers_url":"https://api.github.com/users/ericholscher/followers","following_url":"https://api.github.com/users/ericholscher/following{/other_user}","gists_url":"https://api.github.com/users/ericholscher/gists{/gist_id}","starred_url":"https://api.github.com/users/ericholscher/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ericholscher/subscriptions","organizations_url":"https://api.github.com/users/ericholscher/orgs","repos_url":"https://api.github.com/users/ericholscher/repos","events_url":"https://api.github.com/users/ericholscher/events{/privacy}","received_events_url":"https://api.github.com/users/ericholscher/received_events","type":"User","site_admin":false},"body":"`projects_info` I think is a bad name. It seems like we're just getting the `docs_url` from it for now, so we should probably be more clear about that. Perhaps `context['project_urls']` or something? ","created_at":"2018-07-05T07:43:00Z","updated_at":"2018-07-05T07:44:12Z","html_url":"https://github.com/rtfd/readthedocs.org/pull/4309#discussion_r200258155","pull_request_url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/comments/200258155"},"html":{"href":"https://github.com/rtfd/readthedocs.org/pull/4309#discussion_r200258155"},"pull_request":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309"}}},"pull_request":{"url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309","id":197854715,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk3ODU0NzE1","html_url":"https://github.com/rtfd/readthedocs.org/pull/4309","diff_url":"https://github.com/rtfd/readthedocs.org/pull/4309.diff","patch_url":"https://github.com/rtfd/readthedocs.org/pull/4309.patch","issue_url":"https://api.github.com/repos/rtfd/readthedocs.org/issues/4309","number":4309,"state":"open","locked":false,"title":"[fix #4265] Port Document search API for Elasticsearch 6.x","user":{"login":"safwanrahman","id":7114151,"node_id":"MDQ6VXNlcjcxMTQxNTE=","avatar_url":"https://avatars0.githubusercontent.com/u/7114151?v=4","gravatar_id":"","url":"https://api.github.com/users/safwanrahman","html_url":"https://github.com/safwanrahman","followers_url":"https://api.github.com/users/safwanrahman/followers","following_url":"https://api.github.com/users/safwanrahman/following{/other_user}","gists_url":"https://api.github.com/users/safwanrahman/gists{/gist_id}","starred_url":"https://api.github.com/users/safwanrahman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safwanrahman/subscriptions","organizations_url":"https://api.github.com/users/safwanrahman/orgs","repos_url":"https://api.github.com/users/safwanrahman/repos","events_url":"https://api.github.com/users/safwanrahman/events{/privacy}","received_events_url":"https://api.github.com/users/safwanrahman/received_events","type":"User","site_admin":false},"body":"This is the first etaration of making a API for Documentation Search. Its not finalized yet and the work is not finished yet.\r\nNeed more work on highlighting as well as test.\r\nNeeded to do some refactor to keep it DRY.\r\n@ericholscher Can you look for a slight review?","created_at":"2018-06-27T21:11:05Z","updated_at":"2018-07-05T07:44:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b1b846da6a8469333fb8da668377b79357768da5","assignee":{"login":"safwanrahman","id":7114151,"node_id":"MDQ6VXNlcjcxMTQxNTE=","avatar_url":"https://avatars0.githubusercontent.com/u/7114151?v=4","gravatar_id":"","url":"https://api.github.com/users/safwanrahman","html_url":"https://github.com/safwanrahman","followers_url":"https://api.github.com/users/safwanrahman/followers","following_url":"https://api.github.com/users/safwanrahman/following{/other_user}","gists_url":"https://api.github.com/users/safwanrahman/gists{/gist_id}","starred_url":"https://api.github.com/users/safwanrahman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safwanrahman/subscriptions","organizations_url":"https://api.github.com/users/safwanrahman/orgs","repos_url":"https://api.github.com/users/safwanrahman/repos","events_url":"https://api.github.com/users/safwanrahman/events{/privacy}","received_events_url":"https://api.github.com/users/safwanrahman/received_events","type":"User","site_admin":false},"assignees":[{"login":"safwanrahman","id":7114151,"node_id":"MDQ6VXNlcjcxMTQxNTE=","avatar_url":"https://avatars0.githubusercontent.com/u/7114151?v=4","gravatar_id":"","url":"https://api.github.com/users/safwanrahman","html_url":"https://github.com/safwanrahman","followers_url":"https://api.github.com/users/safwanrahman/followers","following_url":"https://api.github.com/users/safwanrahman/following{/other_user}","gists_url":"https://api.github.com/users/safwanrahman/gists{/gist_id}","starred_url":"https://api.github.com/users/safwanrahman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safwanrahman/subscriptions","organizations_url":"https://api.github.com/users/safwanrahman/orgs","repos_url":"https://api.github.com/users/safwanrahman/repos","events_url":"https://api.github.com/users/safwanrahman/events{/privacy}","received_events_url":"https://api.github.com/users/safwanrahman/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309/commits","review_comments_url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309/comments","review_comment_url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rtfd/readthedocs.org/issues/4309/comments","statuses_url":"https://api.github.com/repos/rtfd/readthedocs.org/statuses/e2e8cbba9a368ea9c65e880cedd441bc7c540fa4","head":{"label":"safwanrahman:search_api","ref":"search_api","sha":"e2e8cbba9a368ea9c65e880cedd441bc7c540fa4","user":{"login":"safwanrahman","id":7114151,"node_id":"MDQ6VXNlcjcxMTQxNTE=","avatar_url":"https://avatars0.githubusercontent.com/u/7114151?v=4","gravatar_id":"","url":"https://api.github.com/users/safwanrahman","html_url":"https://github.com/safwanrahman","followers_url":"https://api.github.com/users/safwanrahman/followers","following_url":"https://api.github.com/users/safwanrahman/following{/other_user}","gists_url":"https://api.github.com/users/safwanrahman/gists{/gist_id}","starred_url":"https://api.github.com/users/safwanrahman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safwanrahman/subscriptions","organizations_url":"https://api.github.com/users/safwanrahman/orgs","repos_url":"https://api.github.com/users/safwanrahman/repos","events_url":"https://api.github.com/users/safwanrahman/events{/privacy}","received_events_url":"https://api.github.com/users/safwanrahman/received_events","type":"User","site_admin":false},"repo":{"id":101502521,"node_id":"MDEwOlJlcG9zaXRvcnkxMDE1MDI1MjE=","name":"readthedocs.org","full_name":"safwanrahman/readthedocs.org","owner":{"login":"safwanrahman","id":7114151,"node_id":"MDQ6VXNlcjcxMTQxNTE=","avatar_url":"https://avatars0.githubusercontent.com/u/7114151?v=4","gravatar_id":"","url":"https://api.github.com/users/safwanrahman","html_url":"https://github.com/safwanrahman","followers_url":"https://api.github.com/users/safwanrahman/followers","following_url":"https://api.github.com/users/safwanrahman/following{/other_user}","gists_url":"https://api.github.com/users/safwanrahman/gists{/gist_id}","starred_url":"https://api.github.com/users/safwanrahman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/safwanrahman/subscriptions","organizations_url":"https://api.github.com/users/safwanrahman/orgs","repos_url":"https://api.github.com/users/safwanrahman/repos","events_url":"https://api.github.com/users/safwanrahman/events{/privacy}","received_events_url":"https://api.github.com/users/safwanrahman/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/safwanrahman/readthedocs.org","description":"source code to readthedocs.org","fork":true,"url":"https://api.github.com/repos/safwanrahman/readthedocs.org","forks_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/forks","keys_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/teams","hooks_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/hooks","issue_events_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/issues/events{/number}","events_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/events","assignees_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/assignees{/user}","branches_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/branches{/branch}","tags_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/tags","blobs_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/statuses/{sha}","languages_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/languages","stargazers_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/stargazers","contributors_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/contributors","subscribers_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/subscribers","subscription_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/subscription","commits_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/contents/{+path}","compare_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/merges","archive_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/downloads","issues_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/issues{/number}","pulls_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/pulls{/number}","milestones_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/milestones{/number}","notifications_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/labels{/name}","releases_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/releases{/id}","deployments_url":"https://api.github.com/repos/safwanrahman/readthedocs.org/deployments","created_at":"2017-08-26T17:42:54Z","updated_at":"2018-06-07T16:06:06Z","pushed_at":"2018-07-04T21:35:40Z","git_url":"git://github.com/safwanrahman/readthedocs.org.git","ssh_url":"git@github.com:safwanrahman/readthedocs.org.git","clone_url":"https://github.com/safwanrahman/readthedocs.org.git","svn_url":"https://github.com/safwanrahman/readthedocs.org","homepage":"http://rtfd.org/","size":47821,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rtfd:search_upgrade","ref":"search_upgrade","sha":"af641b0e7479277664a19612c33dc570664afe11","user":{"login":"rtfd","id":366329,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NjMyOQ==","avatar_url":"https://avatars2.githubusercontent.com/u/366329?v=4","gravatar_id":"","url":"https://api.github.com/users/rtfd","html_url":"https://github.com/rtfd","followers_url":"https://api.github.com/users/rtfd/followers","following_url":"https://api.github.com/users/rtfd/following{/other_user}","gists_url":"https://api.github.com/users/rtfd/gists{/gist_id}","starred_url":"https://api.github.com/users/rtfd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtfd/subscriptions","organizations_url":"https://api.github.com/users/rtfd/orgs","repos_url":"https://api.github.com/users/rtfd/repos","events_url":"https://api.github.com/users/rtfd/events{/privacy}","received_events_url":"https://api.github.com/users/rtfd/received_events","type":"Organization","site_admin":false},"repo":{"id":841835,"node_id":"MDEwOlJlcG9zaXRvcnk4NDE4MzU=","name":"readthedocs.org","full_name":"rtfd/readthedocs.org","owner":{"login":"rtfd","id":366329,"node_id":"MDEyOk9yZ2FuaXphdGlvbjM2NjMyOQ==","avatar_url":"https://avatars2.githubusercontent.com/u/366329?v=4","gravatar_id":"","url":"https://api.github.com/users/rtfd","html_url":"https://github.com/rtfd","followers_url":"https://api.github.com/users/rtfd/followers","following_url":"https://api.github.com/users/rtfd/following{/other_user}","gists_url":"https://api.github.com/users/rtfd/gists{/gist_id}","starred_url":"https://api.github.com/users/rtfd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rtfd/subscriptions","organizations_url":"https://api.github.com/users/rtfd/orgs","repos_url":"https://api.github.com/users/rtfd/repos","events_url":"https://api.github.com/users/rtfd/events{/privacy}","received_events_url":"https://api.github.com/users/rtfd/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rtfd/readthedocs.org","description":"The source code that powers readthedocs.org","fork":false,"url":"https://api.github.com/repos/rtfd/readthedocs.org","forks_url":"https://api.github.com/repos/rtfd/readthedocs.org/forks","keys_url":"https://api.github.com/repos/rtfd/readthedocs.org/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rtfd/readthedocs.org/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rtfd/readthedocs.org/teams","hooks_url":"https://api.github.com/repos/rtfd/readthedocs.org/hooks","issue_events_url":"https://api.github.com/repos/rtfd/readthedocs.org/issues/events{/number}","events_url":"https://api.github.com/repos/rtfd/readthedocs.org/events","assignees_url":"https://api.github.com/repos/rtfd/readthedocs.org/assignees{/user}","branches_url":"https://api.github.com/repos/rtfd/readthedocs.org/branches{/branch}","tags_url":"https://api.github.com/repos/rtfd/readthedocs.org/tags","blobs_url":"https://api.github.com/repos/rtfd/readthedocs.org/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rtfd/readthedocs.org/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rtfd/readthedocs.org/git/refs{/sha}","trees_url":"https://api.github.com/repos/rtfd/readthedocs.org/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rtfd/readthedocs.org/statuses/{sha}","languages_url":"https://api.github.com/repos/rtfd/readthedocs.org/languages","stargazers_url":"https://api.github.com/repos/rtfd/readthedocs.org/stargazers","contributors_url":"https://api.github.com/repos/rtfd/readthedocs.org/contributors","subscribers_url":"https://api.github.com/repos/rtfd/readthedocs.org/subscribers","subscription_url":"https://api.github.com/repos/rtfd/readthedocs.org/subscription","commits_url":"https://api.github.com/repos/rtfd/readthedocs.org/commits{/sha}","git_commits_url":"https://api.github.com/repos/rtfd/readthedocs.org/git/commits{/sha}","comments_url":"https://api.github.com/repos/rtfd/readthedocs.org/comments{/number}","issue_comment_url":"https://api.github.com/repos/rtfd/readthedocs.org/issues/comments{/number}","contents_url":"https://api.github.com/repos/rtfd/readthedocs.org/contents/{+path}","compare_url":"https://api.github.com/repos/rtfd/readthedocs.org/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rtfd/readthedocs.org/merges","archive_url":"https://api.github.com/repos/rtfd/readthedocs.org/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rtfd/readthedocs.org/downloads","issues_url":"https://api.github.com/repos/rtfd/readthedocs.org/issues{/number}","pulls_url":"https://api.github.com/repos/rtfd/readthedocs.org/pulls{/number}","milestones_url":"https://api.github.com/repos/rtfd/readthedocs.org/milestones{/number}","notifications_url":"https://api.github.com/repos/rtfd/readthedocs.org/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rtfd/readthedocs.org/labels{/name}","releases_url":"https://api.github.com/repos/rtfd/readthedocs.org/releases{/id}","deployments_url":"https://api.github.com/repos/rtfd/readthedocs.org/deployments","created_at":"2010-08-16T19:18:06Z","updated_at":"2018-07-05T01:14:03Z","pushed_at":"2018-07-04T21:35:45Z","git_url":"git://github.com/rtfd/readthedocs.org.git","ssh_url":"git@github.com:rtfd/readthedocs.org.git","clone_url":"https://github.com/rtfd/readthedocs.org.git","svn_url":"https://github.com/rtfd/readthedocs.org","homepage":"https://readthedocs.org/","size":49606,"stargazers_count":4438,"watchers_count":4438,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2385,"mirror_url":null,"archived":false,"open_issues_count":450,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":2385,"open_issues":450,"watchers":4438,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309"},"html":{"href":"https://github.com/rtfd/readthedocs.org/pull/4309"},"issue":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/issues/4309"},"comments":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/issues/4309/comments"},"review_comments":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309/comments"},"review_comment":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/pulls/4309/commits"},"statuses":{"href":"https://api.github.com/repos/rtfd/readthedocs.org/statuses/e2e8cbba9a368ea9c65e880cedd441bc7c540fa4"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"ericholscher"}}