|
| 1 | +In Doc Search UI |
| 2 | +================ |
| 3 | + |
| 4 | +Giving readers the ability to easily search the information |
| 5 | +that they are looking for is important for us. |
| 6 | +We have already upgraded to the latest version of `Elasticsearch`_ and |
| 7 | +we plan to implement `search as you type` feature for all the documentations hosted by us. |
| 8 | +It will be designed to provide instant results as soon as the user starts |
| 9 | +typing in the search bar with a clean and minimal frontend. |
| 10 | +This design document aims to provides the details of it. |
| 11 | +This is a GSoC'19 project. |
| 12 | + |
| 13 | +.. warning:: |
| 14 | + |
| 15 | + This design document details future features that are **not yet implemented**. |
| 16 | + To discuss this document, please get in touch in the `issue tracker`_. |
| 17 | + |
| 18 | + |
| 19 | +The final result may look something like this: |
| 20 | + |
| 21 | +.. figure:: ../_static/images/design-docs/in-doc-search-ui/in-doc-search-ui-demo.gif |
| 22 | + :align: center |
| 23 | + :target: ../_static/images/design-docs/in-doc-search-ui/in-doc-search-ui-demo.gif |
| 24 | + |
| 25 | + Short demo |
| 26 | + |
| 27 | + |
| 28 | +Goals And Non-Goals |
| 29 | +------------------- |
| 30 | + |
| 31 | +Project Goals |
| 32 | +++++++++++++++ |
| 33 | + |
| 34 | +* Support a search-as-you-type/autocomplete interface. |
| 35 | +* Support across all (or virtually all) Sphinx themes. |
| 36 | +* Support for the JavaScript user experience down to IE11 or graceful degradation where we can't support it. |
| 37 | +* Project maintainers should have a way to opt-in/opt-out of this feature. |
| 38 | +* (Optional) Project maintainers should have the flexibility to change some of the styles using custom CSS and JS files. |
| 39 | + |
| 40 | +Non-Goals |
| 41 | +++++++++++ |
| 42 | + |
| 43 | +* For the initial release, we are targeting only Sphinx documentations |
| 44 | + as we don't index MkDocs documentations to our Elasticsearch index. |
| 45 | + |
| 46 | + |
| 47 | +Existing Search Implementation |
| 48 | +------------------------------ |
| 49 | + |
| 50 | +We have a detailed documentation explaing the underlying architecture of our search backend |
| 51 | +and how we index documents to our Elasticsearch index. |
| 52 | +You can read about it :doc:`here <../development/search>`. |
| 53 | + |
| 54 | + |
| 55 | +Proposed Architecture for In-Doc Search UI |
| 56 | +------------------------------------------ |
| 57 | + |
| 58 | +Frontend |
| 59 | +++++++++ |
| 60 | + |
| 61 | +Technologies |
| 62 | +~~~~~~~~~~~~ |
| 63 | + |
| 64 | +Frontend is to designed in a theme agnostics way. For that, |
| 65 | +we explored various libraries which may be of use but none of them fits our needs. |
| 66 | +So, we might be using vanilla JavaScript for this purpose. |
| 67 | +This will provide us some advantages over using any third party library: |
| 68 | + |
| 69 | +* Better control over the DOM. |
| 70 | +* Performance benefits. |
| 71 | + |
| 72 | + |
| 73 | +Proposed Architecture |
| 74 | +~~~~~~~~~~~~~~~~~~~~~ |
| 75 | + |
| 76 | +We plan to select the search bar, which is present in every theme, |
| 77 | +and use the `querySelector()`_ method of JavaScript. |
| 78 | +Then add an event listener to it to listen for the changes and |
| 79 | +fire a search query to our backend as soon as there is any change. |
| 80 | +Our backend will then return the suggestions, |
| 81 | +which will be shown to the user in a clean and minimal UI. |
| 82 | +We will be using `document.createElement()`_ and `node.removeChild()`_ method |
| 83 | +provided by JavaScript as we don't want empty `<div>` hanging out in the DOM. |
| 84 | + |
| 85 | +We have a few ways to include the required JavaScript and CSS files in all the projects: |
| 86 | + |
| 87 | +* Add CSS into `readthedocs-doc-embed.css` and JS into `readthedocs-doc-embed.js` |
| 88 | + and it will get included. |
| 89 | +* Package the in-doc search into it's own self-contained CSS and JS files |
| 90 | + and include them in a similar manner to `readthedocs-doc-embed.*`. |
| 91 | +* It might be possible to package up the in-doc CSS/JS as a sphinx extension. |
| 92 | + This might be nice because then it's easy to enable it on a per-project basis. |
| 93 | + When we are ready to roll it out to a wider audience, |
| 94 | + we can make a decision to just turn it on for everybody (put it in `here`_) |
| 95 | + or we could enable it as an opt-in feature like the `404 extension`_. |
| 96 | + |
| 97 | + |
| 98 | +UI/UX |
| 99 | +~~~~~ |
| 100 | + |
| 101 | +We have two ways which can be used to show suggestions to the user. |
| 102 | + |
| 103 | +* Show suggestions below the search bar. |
| 104 | +* Open a full page search interface when the user click on search field. |
| 105 | + |
| 106 | + |
| 107 | +Backend |
| 108 | ++++++++ |
| 109 | + |
| 110 | +We have a few options to support `search as you type` feature, |
| 111 | +but we need to decide that which option would be best for our use-case. |
| 112 | + |
| 113 | +Edge NGram Tokenizer |
| 114 | +~~~~~~~~~~~~~~~~~~~~ |
| 115 | + |
| 116 | +* Pros |
| 117 | + |
| 118 | + * More effective than Completion Suggester when it comes to autocompleting |
| 119 | + words that can appear in any order. |
| 120 | + * It is considerable fast because most of the work is being done at index time, |
| 121 | + hence the time taken for autocompletion is reduced. |
| 122 | + * Supports highlighting of the matching terms. |
| 123 | + |
| 124 | +* Cons |
| 125 | + |
| 126 | + * Requires greater disk space. |
| 127 | + |
| 128 | + |
| 129 | +Completion Suggester |
| 130 | +~~~~~~~~~~~~~~~~~~~~ |
| 131 | + |
| 132 | +* Pros |
| 133 | + |
| 134 | + * Really fast as it is optimized for speed. |
| 135 | + * Does not require large disk space. |
| 136 | + |
| 137 | +* Cons |
| 138 | + |
| 139 | + * Matching always starts at the beginning of the text. So, for example, |
| 140 | + "Hel" will match "Hello, World" but not "World Hello". |
| 141 | + * Highlighting of the matching words is not supported. |
| 142 | + * According to the official docs for Completion Suggester, |
| 143 | + fast lookups are costly to build and are stored in-memory. |
| 144 | + |
| 145 | + |
| 146 | +Milestones |
| 147 | +---------- |
| 148 | + |
| 149 | ++-----------------------------------------------------------------------------------+------------------+ |
| 150 | +| Milestone | Due Date | |
| 151 | ++===================================================================================+==================+ |
| 152 | +| A local implementation of the project. | 12th June, 2019 | |
| 153 | ++-----------------------------------------------------------------------------------+------------------+ |
| 154 | +| In-doc search on a test project hosted on Read the Docs using the RTD Search API. | 20th June, 2019 | |
| 155 | ++-----------------------------------------------------------------------------------+------------------+ |
| 156 | +| In-doc search on docs.readthedocs.io. | 20th June, 2019 | |
| 157 | ++-----------------------------------------------------------------------------------+------------------+ |
| 158 | +| Friendly user trial where users can add this on their own docs. | 5th July, 2019 | |
| 159 | ++-----------------------------------------------------------------------------------+------------------+ |
| 160 | +| Additional UX testing on the top-10 Sphinx themes. | 15th July, 2019 | |
| 161 | ++-----------------------------------------------------------------------------------+------------------+ |
| 162 | +| Finalize the UI. | 25th July, 2019 | |
| 163 | ++-----------------------------------------------------------------------------------+------------------+ |
| 164 | +| Improve the search backend for efficient and fast search results. | 10th August, 2019| |
| 165 | ++-----------------------------------------------------------------------------------+------------------+ |
| 166 | + |
| 167 | + |
| 168 | +Open Questions |
| 169 | +++++++++++++++ |
| 170 | + |
| 171 | +* Should we rely on jQuery, any third party library or pure vanilla JavaScript? |
| 172 | +* Are the subprojects to be searched? |
| 173 | +* Is our existing Search API is sufficient? |
| 174 | +* Should we go for edge ngrams or completion suggester? |
| 175 | + |
| 176 | + |
| 177 | +.. _issue tracker: https://github.com/rtfd/readthedocs.org/issues |
| 178 | +.. _Elasticsearch: https://www.elastic.co/products/elasticsearch |
| 179 | +.. _querySelector(): https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector |
| 180 | +.. _document.createElement(): https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement |
| 181 | +.. _node.removeChild(): https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild |
| 182 | +.. _here: https://github.com/rtfd/readthedocs.org/blob/9ca5858e859dea0759d913e8db70a623d62d6a16/readthedocs/doc_builder/templates/doc_builder/conf.py.tmpl#L135-L142 |
| 183 | +.. _404 extension : https://github.com/rtfd/sphinx-notfound-page |
0 commit comments