{"action":"created","comment":{"url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/comments/239296173","pull_request_review_id":182042070,"id":239296173,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzOTI5NjE3Mw==","diff_hunk":"@@ -15,28 +18,105 @@ def search_get():\n     \"\"\"\n \n     es = Elasticsearch(current_app.config['ELASTICSEARCH_URL'])\n-    search = Search(using=es, index=current_app.config['FIELDS_INDEX_NAME'])\n-    # TODO(malathir): Change this to case insensitive sorting.\n-    search = search.sort('name.keyword')\n-    # Default number of results is 10, which isn't enough.\n-    search = search[0:10000]\n-    response = search.execute()\n-    response_fields = response.to_dict()\n-\n     search_results = []\n-    for field in response_fields['hits']['hits']:\n+    # The number of results that Elasticsearch returns from Search queries to the index.\n+    num_search_results = 100\n+    # The number of results that Elasticsearch returns from Search queries to the fields index.\n+    num_field_search_results = 10000\n+\n+    if not query:\n+        # Return all dataset fields, to populate search box drop-down. Query fields index.\n+        fields_search = Search(\n+            using=es, index=current_app.config['FIELDS_INDEX_NAME']).sort(\n+                'name.keyword')[0:num_field_search_results]\n+        fields_search_response = fields_search.execute()\n+        fields = fields_search_response.to_dict()\n+        search_results.extend(results_from_fields(fields))\n+    else:\n+        # Return only fields matching query.\n+        # Part 1: Search main index. For the BigQuery indexer, this searches BigQuery column values.\n+\n+        # Store the query matches in a dict of es_field_name to an array of facet values.\n+        field_to_facet_values = dict()\n+\n+        # Use MultiMatch to search on facet values. \"phrase_prefix\" matches with\n+        # prefix of words in column values.\n+        multi_match = MultiMatch(query=query, type=\"phrase_prefix\")\n+        search = Search(\n+            using=es, index=current_app.config['INDEX_NAME']).params(\n+                request_timeout=30).query(multi_match)[0:num_search_results]\n+        response = search.execute()\n+        response_fields = response.to_dict()\n+\n+        query_regex = r\"\\b\" + re.escape(query.lower()) + \"\\w+\"\n+        for match in response_fields['hits']['hits']:","path":"api/data_explorer/controllers/search_controller.py","position":61,"original_position":61,"commit_id":"6de27da346715b801f983985fc2026c0198b0e73","original_commit_id":"6de27da346715b801f983985fc2026c0198b0e73","user":{"login":"melissachang","id":10929390,"node_id":"MDQ6VXNlcjEwOTI5Mzkw","avatar_url":"https://avatars1.githubusercontent.com/u/10929390?v=4","gravatar_id":"","url":"https://api.github.com/users/melissachang","html_url":"https://github.com/melissachang","followers_url":"https://api.github.com/users/melissachang/followers","following_url":"https://api.github.com/users/melissachang/following{/other_user}","gists_url":"https://api.github.com/users/melissachang/gists{/gist_id}","starred_url":"https://api.github.com/users/melissachang/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/melissachang/subscriptions","organizations_url":"https://api.github.com/users/melissachang/orgs","repos_url":"https://api.github.com/users/melissachang/repos","events_url":"https://api.github.com/users/melissachang/events{/privacy}","received_events_url":"https://api.github.com/users/melissachang/received_events","type":"User","site_admin":false},"body":"```\r\n# hits contains entire documents. Iterate over the fields to figure out which field matched query.\r\n# Elasticsearch highlight can do this for us, but it makes the search too slow, so do it ourselves.\r\n```","created_at":"2018-12-06T01:01:21Z","updated_at":"2018-12-06T01:02:56Z","html_url":"https://github.com/DataBiosphere/data-explorer/pull/237#discussion_r239296173","pull_request_url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/comments/239296173"},"html":{"href":"https://github.com/DataBiosphere/data-explorer/pull/237#discussion_r239296173"},"pull_request":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237"}}},"pull_request":{"url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237","id":234512468,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0NTEyNDY4","html_url":"https://github.com/DataBiosphere/data-explorer/pull/237","diff_url":"https://github.com/DataBiosphere/data-explorer/pull/237.diff","patch_url":"https://github.com/DataBiosphere/data-explorer/pull/237.patch","issue_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/237","number":237,"state":"open","locked":false,"title":"Search on facet values","user":{"login":"malathi13","id":3248248,"node_id":"MDQ6VXNlcjMyNDgyNDg=","avatar_url":"https://avatars0.githubusercontent.com/u/3248248?v=4","gravatar_id":"","url":"https://api.github.com/users/malathi13","html_url":"https://github.com/malathi13","followers_url":"https://api.github.com/users/malathi13/followers","following_url":"https://api.github.com/users/malathi13/following{/other_user}","gists_url":"https://api.github.com/users/malathi13/gists{/gist_id}","starred_url":"https://api.github.com/users/malathi13/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/malathi13/subscriptions","organizations_url":"https://api.github.com/users/malathi13/orgs","repos_url":"https://api.github.com/users/malathi13/repos","events_url":"https://api.github.com/users/malathi13/events{/privacy}","received_events_url":"https://api.github.com/users/malathi13/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-11-29T05:22:30Z","updated_at":"2018-12-06T01:02:56Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a6ad9fe0e5c05f431e9fc5d7536d1fd87ad25836","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237/commits","review_comments_url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237/comments","review_comment_url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/237/comments","statuses_url":"https://api.github.com/repos/DataBiosphere/data-explorer/statuses/6de27da346715b801f983985fc2026c0198b0e73","head":{"label":"DataBiosphere:mr/search_api","ref":"mr/search_api","sha":"6de27da346715b801f983985fc2026c0198b0e73","user":{"login":"DataBiosphere","id":32805087,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyODA1MDg3","avatar_url":"https://avatars0.githubusercontent.com/u/32805087?v=4","gravatar_id":"","url":"https://api.github.com/users/DataBiosphere","html_url":"https://github.com/DataBiosphere","followers_url":"https://api.github.com/users/DataBiosphere/followers","following_url":"https://api.github.com/users/DataBiosphere/following{/other_user}","gists_url":"https://api.github.com/users/DataBiosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/DataBiosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataBiosphere/subscriptions","organizations_url":"https://api.github.com/users/DataBiosphere/orgs","repos_url":"https://api.github.com/users/DataBiosphere/repos","events_url":"https://api.github.com/users/DataBiosphere/events{/privacy}","received_events_url":"https://api.github.com/users/DataBiosphere/received_events","type":"Organization","site_admin":false},"repo":{"id":119908069,"node_id":"MDEwOlJlcG9zaXRvcnkxMTk5MDgwNjk=","name":"data-explorer","full_name":"DataBiosphere/data-explorer","private":false,"owner":{"login":"DataBiosphere","id":32805087,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyODA1MDg3","avatar_url":"https://avatars0.githubusercontent.com/u/32805087?v=4","gravatar_id":"","url":"https://api.github.com/users/DataBiosphere","html_url":"https://github.com/DataBiosphere","followers_url":"https://api.github.com/users/DataBiosphere/followers","following_url":"https://api.github.com/users/DataBiosphere/following{/other_user}","gists_url":"https://api.github.com/users/DataBiosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/DataBiosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataBiosphere/subscriptions","organizations_url":"https://api.github.com/users/DataBiosphere/orgs","repos_url":"https://api.github.com/users/DataBiosphere/repos","events_url":"https://api.github.com/users/DataBiosphere/events{/privacy}","received_events_url":"https://api.github.com/users/DataBiosphere/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/DataBiosphere/data-explorer","description":null,"fork":false,"url":"https://api.github.com/repos/DataBiosphere/data-explorer","forks_url":"https://api.github.com/repos/DataBiosphere/data-explorer/forks","keys_url":"https://api.github.com/repos/DataBiosphere/data-explorer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataBiosphere/data-explorer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataBiosphere/data-explorer/teams","hooks_url":"https://api.github.com/repos/DataBiosphere/data-explorer/hooks","issue_events_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/events{/number}","events_url":"https://api.github.com/repos/DataBiosphere/data-explorer/events","assignees_url":"https://api.github.com/repos/DataBiosphere/data-explorer/assignees{/user}","branches_url":"https://api.github.com/repos/DataBiosphere/data-explorer/branches{/branch}","tags_url":"https://api.github.com/repos/DataBiosphere/data-explorer/tags","blobs_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataBiosphere/data-explorer/statuses/{sha}","languages_url":"https://api.github.com/repos/DataBiosphere/data-explorer/languages","stargazers_url":"https://api.github.com/repos/DataBiosphere/data-explorer/stargazers","contributors_url":"https://api.github.com/repos/DataBiosphere/data-explorer/contributors","subscribers_url":"https://api.github.com/repos/DataBiosphere/data-explorer/subscribers","subscription_url":"https://api.github.com/repos/DataBiosphere/data-explorer/subscription","commits_url":"https://api.github.com/repos/DataBiosphere/data-explorer/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataBiosphere/data-explorer/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataBiosphere/data-explorer/contents/{+path}","compare_url":"https://api.github.com/repos/DataBiosphere/data-explorer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataBiosphere/data-explorer/merges","archive_url":"https://api.github.com/repos/DataBiosphere/data-explorer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataBiosphere/data-explorer/downloads","issues_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues{/number}","pulls_url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls{/number}","milestones_url":"https://api.github.com/repos/DataBiosphere/data-explorer/milestones{/number}","notifications_url":"https://api.github.com/repos/DataBiosphere/data-explorer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataBiosphere/data-explorer/labels{/name}","releases_url":"https://api.github.com/repos/DataBiosphere/data-explorer/releases{/id}","deployments_url":"https://api.github.com/repos/DataBiosphere/data-explorer/deployments","created_at":"2018-02-01T23:53:44Z","updated_at":"2018-12-05T22:57:13Z","pushed_at":"2018-12-05T23:51:43Z","git_url":"git://github.com/DataBiosphere/data-explorer.git","ssh_url":"git@github.com:DataBiosphere/data-explorer.git","clone_url":"https://github.com/DataBiosphere/data-explorer.git","svn_url":"https://github.com/DataBiosphere/data-explorer","homepage":null,"size":10191,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":2,"open_issues":6,"watchers":1,"default_branch":"master"}},"base":{"label":"DataBiosphere:master","ref":"master","sha":"6da806eac8f0f4ccecf840452b28d6d7b407fb55","user":{"login":"DataBiosphere","id":32805087,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyODA1MDg3","avatar_url":"https://avatars0.githubusercontent.com/u/32805087?v=4","gravatar_id":"","url":"https://api.github.com/users/DataBiosphere","html_url":"https://github.com/DataBiosphere","followers_url":"https://api.github.com/users/DataBiosphere/followers","following_url":"https://api.github.com/users/DataBiosphere/following{/other_user}","gists_url":"https://api.github.com/users/DataBiosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/DataBiosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataBiosphere/subscriptions","organizations_url":"https://api.github.com/users/DataBiosphere/orgs","repos_url":"https://api.github.com/users/DataBiosphere/repos","events_url":"https://api.github.com/users/DataBiosphere/events{/privacy}","received_events_url":"https://api.github.com/users/DataBiosphere/received_events","type":"Organization","site_admin":false},"repo":{"id":119908069,"node_id":"MDEwOlJlcG9zaXRvcnkxMTk5MDgwNjk=","name":"data-explorer","full_name":"DataBiosphere/data-explorer","private":false,"owner":{"login":"DataBiosphere","id":32805087,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyODA1MDg3","avatar_url":"https://avatars0.githubusercontent.com/u/32805087?v=4","gravatar_id":"","url":"https://api.github.com/users/DataBiosphere","html_url":"https://github.com/DataBiosphere","followers_url":"https://api.github.com/users/DataBiosphere/followers","following_url":"https://api.github.com/users/DataBiosphere/following{/other_user}","gists_url":"https://api.github.com/users/DataBiosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/DataBiosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DataBiosphere/subscriptions","organizations_url":"https://api.github.com/users/DataBiosphere/orgs","repos_url":"https://api.github.com/users/DataBiosphere/repos","events_url":"https://api.github.com/users/DataBiosphere/events{/privacy}","received_events_url":"https://api.github.com/users/DataBiosphere/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/DataBiosphere/data-explorer","description":null,"fork":false,"url":"https://api.github.com/repos/DataBiosphere/data-explorer","forks_url":"https://api.github.com/repos/DataBiosphere/data-explorer/forks","keys_url":"https://api.github.com/repos/DataBiosphere/data-explorer/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DataBiosphere/data-explorer/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DataBiosphere/data-explorer/teams","hooks_url":"https://api.github.com/repos/DataBiosphere/data-explorer/hooks","issue_events_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/events{/number}","events_url":"https://api.github.com/repos/DataBiosphere/data-explorer/events","assignees_url":"https://api.github.com/repos/DataBiosphere/data-explorer/assignees{/user}","branches_url":"https://api.github.com/repos/DataBiosphere/data-explorer/branches{/branch}","tags_url":"https://api.github.com/repos/DataBiosphere/data-explorer/tags","blobs_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/refs{/sha}","trees_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DataBiosphere/data-explorer/statuses/{sha}","languages_url":"https://api.github.com/repos/DataBiosphere/data-explorer/languages","stargazers_url":"https://api.github.com/repos/DataBiosphere/data-explorer/stargazers","contributors_url":"https://api.github.com/repos/DataBiosphere/data-explorer/contributors","subscribers_url":"https://api.github.com/repos/DataBiosphere/data-explorer/subscribers","subscription_url":"https://api.github.com/repos/DataBiosphere/data-explorer/subscription","commits_url":"https://api.github.com/repos/DataBiosphere/data-explorer/commits{/sha}","git_commits_url":"https://api.github.com/repos/DataBiosphere/data-explorer/git/commits{/sha}","comments_url":"https://api.github.com/repos/DataBiosphere/data-explorer/comments{/number}","issue_comment_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/comments{/number}","contents_url":"https://api.github.com/repos/DataBiosphere/data-explorer/contents/{+path}","compare_url":"https://api.github.com/repos/DataBiosphere/data-explorer/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DataBiosphere/data-explorer/merges","archive_url":"https://api.github.com/repos/DataBiosphere/data-explorer/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DataBiosphere/data-explorer/downloads","issues_url":"https://api.github.com/repos/DataBiosphere/data-explorer/issues{/number}","pulls_url":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls{/number}","milestones_url":"https://api.github.com/repos/DataBiosphere/data-explorer/milestones{/number}","notifications_url":"https://api.github.com/repos/DataBiosphere/data-explorer/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DataBiosphere/data-explorer/labels{/name}","releases_url":"https://api.github.com/repos/DataBiosphere/data-explorer/releases{/id}","deployments_url":"https://api.github.com/repos/DataBiosphere/data-explorer/deployments","created_at":"2018-02-01T23:53:44Z","updated_at":"2018-12-05T22:57:13Z","pushed_at":"2018-12-05T23:51:43Z","git_url":"git://github.com/DataBiosphere/data-explorer.git","ssh_url":"git@github.com:DataBiosphere/data-explorer.git","clone_url":"https://github.com/DataBiosphere/data-explorer.git","svn_url":"https://github.com/DataBiosphere/data-explorer","homepage":null,"size":10191,"stargazers_count":1,"watchers_count":1,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"bsd-3-clause","name":"BSD 3-Clause \"New\" or \"Revised\" License","spdx_id":"BSD-3-Clause","url":"https://api.github.com/licenses/bsd-3-clause","node_id":"MDc6TGljZW5zZTU="},"forks":2,"open_issues":6,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237"},"html":{"href":"https://github.com/DataBiosphere/data-explorer/pull/237"},"issue":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/237"},"comments":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/issues/237/comments"},"review_comments":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237/comments"},"review_comment":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/pulls/237/commits"},"statuses":{"href":"https://api.github.com/repos/DataBiosphere/data-explorer/statuses/6de27da346715b801f983985fc2026c0198b0e73"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"melissachang"}}