{"action":"created","issue":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/5229","repository_url":"https://api.github.com/repos/crystal-lang/crystal","labels_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5229/labels{/name}","comments_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5229/comments","events_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5229/events","html_url":"https://github.com/crystal-lang/crystal/pull/5229","id":270375364,"number":5229,"title":"Improved search feature for API docs","user":{"login":"straight-shoota","id":466378,"avatar_url":"https://avatars0.githubusercontent.com/u/466378?v=4","gravatar_id":"","url":"https://api.github.com/users/straight-shoota","html_url":"https://github.com/straight-shoota","followers_url":"https://api.github.com/users/straight-shoota/followers","following_url":"https://api.github.com/users/straight-shoota/following{/other_user}","gists_url":"https://api.github.com/users/straight-shoota/gists{/gist_id}","starred_url":"https://api.github.com/users/straight-shoota/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/straight-shoota/subscriptions","organizations_url":"https://api.github.com/users/straight-shoota/orgs","repos_url":"https://api.github.com/users/straight-shoota/repos","events_url":"https://api.github.com/users/straight-shoota/events{/privacy}","received_events_url":"https://api.github.com/users/straight-shoota/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":34,"created_at":"2017-11-01T16:53:39Z","updated_at":"2017-12-03T16:30:44Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/crystal-lang/crystal/pulls/5229","html_url":"https://github.com/crystal-lang/crystal/pull/5229","diff_url":"https://github.com/crystal-lang/crystal/pull/5229.diff","patch_url":"https://github.com/crystal-lang/crystal/pull/5229.patch"},"body":"This PR greatly improves client-side search on generated HTML pages of the API docs.\r\nIt uses the program description available as JSON data from #4746 and implements a custom search algorithm in JavaScript.\r\nThe search results include types, constants, methods, macros matching the query string in one or more of the fields name, namespace, description, arguments or type.\r\nA custom ranking algorithm sorts results based on matching quality and relevance.\r\n\r\nThe search-algorithm is actually quite simple, it uses no search index or advanced information retrieval functions. It simply traverses through all the types and tries to find matching features. This is really just fast enough.\r\nI considered using something like lunr.js but this would have been complicated to setup to create a domain-specific search experience. With the custom algorithm it is very easy to fine tune matching and ranking behaviour to allow developers to find what they need as fast as possible.\r\n\r\nThis approach has some drawbacks with regards to fulltext search capabilities (especially concerning docstrings), but this can certainly be improved upon.\r\n\r\n## Search features:\r\n* prefix filter: `#` matches instance methods, `.` matches class methods and macros, `:`/`::` matches namespace\r\n* search is generally case-insensitive but results with case-equality areranked higher.\r\n* search results list can be navigated by key (when in focus):\r\n  * `i`, `c`, `ArrowUp`: move upwards\r\n  * `j`, `h`, `ArrowDown`: move downwards\r\n  * `Enter`: load result\r\n  * `Escape`: cancel search\r\n  * arrows, `Enter` and `Escape` also work when the search-input is in focus\r\n* support for URL fragment-based search query: `/#q=mysearch` will initialize a search at page load\r\n* page-wide shortkeys to start search: `s` or `/`\r\n\r\n## Preview\r\n[Online Preview](https://straight-shoota.github.io/crystal/docs-search-only/)\r\n\r\nThis is intended to be alongside #4755 which makes it look even better ([Online Preview](https://straight-shoota.github.io/crystal/doc-search/)) though it can be merged separately.\r\n\r\nCloses #1792"},"comment":{"url":"https://api.github.com/repos/crystal-lang/crystal/issues/comments/348792372","html_url":"https://github.com/crystal-lang/crystal/pull/5229#issuecomment-348792372","issue_url":"https://api.github.com/repos/crystal-lang/crystal/issues/5229","id":348792372,"user":{"login":"RX14","id":2788811,"avatar_url":"https://avatars0.githubusercontent.com/u/2788811?v=4","gravatar_id":"","url":"https://api.github.com/users/RX14","html_url":"https://github.com/RX14","followers_url":"https://api.github.com/users/RX14/followers","following_url":"https://api.github.com/users/RX14/following{/other_user}","gists_url":"https://api.github.com/users/RX14/gists{/gist_id}","starred_url":"https://api.github.com/users/RX14/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RX14/subscriptions","organizations_url":"https://api.github.com/users/RX14/orgs","repos_url":"https://api.github.com/users/RX14/repos","events_url":"https://api.github.com/users/RX14/events{/privacy}","received_events_url":"https://api.github.com/users/RX14/received_events","type":"User","site_admin":false},"created_at":"2017-12-03T16:30:44Z","updated_at":"2017-12-03T16:30:44Z","author_association":"MEMBER","body":"This is absolutely fantastic."}}
{"actor":{"display_login":"RX14"}}