|
| 1 | +Searching with Read the Docs |
| 2 | +============================ |
| 3 | + |
| 4 | +Read the Docs uses Elasticsearch to provide a better search experience. |
| 5 | +This guide is intended to show that how to add "search as you type" feature to your documentation, |
| 6 | +how to use advanced query syntax to get more accurate results and |
| 7 | +many other search features that Read the Docs supports with example searches. |
| 8 | + |
| 9 | +You can find information on the search architecture and how we index document on our |
| 10 | +:doc:`Search <../development/search>` docs. |
| 11 | + |
| 12 | + |
| 13 | +.. contents:: Table of contents |
| 14 | + :local: |
| 15 | + :backlinks: none |
| 16 | + :depth: 3 |
| 17 | + |
| 18 | + |
| 19 | +Improvements over Sphinx search |
| 20 | +------------------------------- |
| 21 | + |
| 22 | +Sphinx is designed to create a self-contained webpage and |
| 23 | +all search indexing is done when the documentation is built. |
| 24 | +As a result, it would be impossible for Sphinx to add features like searching translations |
| 25 | +or subprojects or having analytics on common searches. |
| 26 | +Read the Docs supports a powerful documentation search unlike |
| 27 | +Sphinx which only have a basic search support. |
| 28 | + |
| 29 | +Features of Read the Docs documentation search are: |
| 30 | + |
| 31 | +- Search as you type feature supported. |
| 32 | +- Search analytics. |
| 33 | +- Search across multiple projects. |
| 34 | +- Search inside subprojects. |
| 35 | +- Advanced query syntax. |
| 36 | +- Improved search result order. |
| 37 | +- Public search API (documentation pending). |
| 38 | +- Case insensitive search. |
| 39 | +- Results from sections of the documentation. |
| 40 | +- Code search. |
| 41 | + |
| 42 | + |
| 43 | +Search features for project admins |
| 44 | +---------------------------------- |
| 45 | + |
| 46 | +Enable "search as you type" in your documentation |
| 47 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 48 | + |
| 49 | +`readthedocs-sphinx-search`_ is a Sphinx extension which integrates your |
| 50 | +documentation more closely with Read the Docs' search implementation. |
| 51 | +It adds a clean and minimal full page search UI which supports **search as you type** feature. |
| 52 | + |
| 53 | +To get a glimpse of it, you can press :guilabel:`/` (forward slash) and start typing |
| 54 | +or just visit these URLs: |
| 55 | + |
| 56 | +- https://docs.readthedocs.io/?rtd_search=contributing |
| 57 | +- https://docs.readthedocs.io/?rtd_search=api/v3/projects/ |
| 58 | + |
| 59 | + |
| 60 | +Search analytics |
| 61 | +~~~~~~~~~~~~~~~~ |
| 62 | + |
| 63 | +Search queries are recorded and are stored in database to provide valuable analytics to the project admins. |
| 64 | +These analytics makes it easy to know what your users are looking for in your documentation. |
| 65 | +You can see these analytics in your project admin dashboard. |
| 66 | + |
| 67 | +.. note:: |
| 68 | + |
| 69 | + Currently, this feature is in beta state and is available under a |
| 70 | + :ref:`feature flag <guides/feature-flags:Available Flags>`. |
| 71 | + We plan to make this available for everyone soon. |
| 72 | + If you want to test this feature out and help giving us feedback, |
| 73 | + please contact us via `GitHub issues`_. |
| 74 | + |
| 75 | +.. figure:: /_static/images/guides/search-analytics-demo.png |
| 76 | + :width: 40% |
| 77 | + :align: center |
| 78 | + :alt: Search analytics in project admin dashboard |
| 79 | + |
| 80 | + Search analytics demo |
| 81 | + |
| 82 | + |
| 83 | +Search features for readers |
| 84 | +--------------------------- |
| 85 | + |
| 86 | +Search across all projects |
| 87 | +~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 88 | + |
| 89 | +Our `main site search`_ supports searching for projects and |
| 90 | +searching across all projects. |
| 91 | +You can also use it to select the specific project and version to narrow down the search results. |
| 92 | + |
| 93 | +Example queries: |
| 94 | + |
| 95 | +- https://readthedocs.org/search/?q=celery&type=project |
| 96 | +- https://readthedocs.org/search/?q=celery._state&type=file |
| 97 | +- https://readthedocs.org/search/?q=celery._state&type=file&project=celery |
| 98 | +- https://readthedocs.org/search/?q=celery._state&type=file&project=celery&version=master |
| 99 | + |
| 100 | + |
| 101 | +Search inside subprojects |
| 102 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 103 | + |
| 104 | +We allow projects to configured as subprojects of another project. |
| 105 | +You can read more about this in our :doc:`Subprojects <../subprojects>` documentation. |
| 106 | + |
| 107 | +If a search is made in a project which have one or more subprojects under it, |
| 108 | +the search results then also includes the results from subprojects because |
| 109 | +they share a search index with their parent and sibling projects. |
| 110 | +For example: `Kombu`_ is one of the subprojects of `Celery`_, |
| 111 | +so if you search in Celery docs, then the results from Kombu will also be there. |
| 112 | +Example: https://docs.celeryproject.org/en/master/search.html?q=utilities&check_keywords=yes&area=default |
| 113 | + |
| 114 | + |
| 115 | +Search query syntax |
| 116 | +~~~~~~~~~~~~~~~~~~~ |
| 117 | + |
| 118 | +Read the Docs uses `Simple Query String`_ feature of `Elasticsearch`_, |
| 119 | +hence the search query can be made complex to get more accurate results. |
| 120 | + |
| 121 | +Exact phrase search |
| 122 | ++++++++++++++++++++ |
| 123 | + |
| 124 | +If a query is wrapped in ``"``, |
| 125 | +then only those results where the phrase is exactly matched will be returned. |
| 126 | + |
| 127 | +Example queries: |
| 128 | + |
| 129 | +- https://docs.readthedocs.io/?rtd_search=%22custom%20css%22 |
| 130 | +- https://docs.readthedocs.io/?rtd_search=%22adding%20a%20subproject%22 |
| 131 | +- https://docs.readthedocs.io/?rtd_search=%22when%20a%20404%20is%20returned%22 |
| 132 | + |
| 133 | +Exact phrase search with slop value |
| 134 | ++++++++++++++++++++++++++++++++++++ |
| 135 | + |
| 136 | +``~N`` after a phrase signifies slop amount. |
| 137 | +It can be used to match words which are near one another. |
| 138 | + |
| 139 | +Example queries: |
| 140 | + |
| 141 | +- https://docs.readthedocs.io/?rtd_search=%22dashboard%20admin%22~2 |
| 142 | +- https://docs.readthedocs.io/?rtd_search=%22single%20documentation%22~1 |
| 143 | +- https://docs.readthedocs.io/?rtd_search=%22read%20the%20docs%20story%22~5 |
| 144 | + |
| 145 | +Prefix query |
| 146 | +++++++++++++ |
| 147 | + |
| 148 | +``*`` at the end of any term signifies a prefix query. |
| 149 | +It returns the results containg the words with specific prefix. |
| 150 | + |
| 151 | +Example queries: |
| 152 | + |
| 153 | +- https://docs.readthedocs.io/?rtd_search=API%20v* |
| 154 | +- https://docs.readthedocs.io/?rtd_search=single%20v*%20doc* |
| 155 | +- https://docs.readthedocs.io/?rtd_search=build*%20and%20c*%20to%20doc* |
| 156 | + |
| 157 | +Fuzzy query |
| 158 | ++++++++++++ |
| 159 | + |
| 160 | +``~N`` after a word signifies edit distance (fuzziness). |
| 161 | +This type of query is helpful when spelling of the actual keyword is unsure. |
| 162 | +It returns results that contain terms similar to the search term, |
| 163 | +as measured by a `Levenshtein edit distance`_. |
| 164 | + |
| 165 | +Example queries: |
| 166 | + |
| 167 | +- https://docs.readthedocs.io/?rtd_search=reedthedcs~2 |
| 168 | +- https://docs.readthedocs.io/?rtd_search=authentation~3 |
| 169 | +- https://docs.readthedocs.io/?rtd_search=configurtion~1 |
| 170 | + |
| 171 | + |
| 172 | +Using the search query syntax to build complex queries |
| 173 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 174 | + |
| 175 | +The search query syntaxes described in the previous section |
| 176 | +can be used with one another to build complex queries. |
| 177 | + |
| 178 | +Example queries: |
| 179 | + |
| 180 | +- https://docs.readthedocs.io/?rtd_search=auto*%20redirect* |
| 181 | +- https://docs.readthedocs.io/?rtd_search=abandon*%20proj* |
| 182 | +- https://docs.readthedocs.io/?rtd_search=localisation~3%20of%20doc* |
| 183 | + |
| 184 | + |
| 185 | +.. _readthedocs-sphinx-search: https://readthedocs-sphinx-search.readthedocs.io/ |
| 186 | +.. _GitHub issues: https://github.com/readthedocs/readthedocs.org/issues/new |
| 187 | +.. _main site search: https://readthedocs.org/search/?q=&type=file&version=latest |
| 188 | +.. _Kombu: http://docs.celeryproject.org/projects/kombu/en/master/ |
| 189 | +.. _Celery: http://docs.celeryproject.org/en/master/ |
| 190 | +.. _Simple Query String: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html# |
| 191 | +.. _Elasticsearch: https://www.elastic.co/products/elasticsearch |
| 192 | +.. _Levenshtein edit distance: https://en.wikipedia.org/wiki/Levenshtein_distance |
0 commit comments