Skip to content

Commit 295d684

Browse files
committed
Use another endpoint
1 parent 87619fb commit 295d684

File tree

8 files changed

+20
-19
lines changed

8 files changed

+20
-19
lines changed

docs/server-side-search.rst

+7-7
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ API
6969
---
7070

7171
Search is exposed through our API that's proxied from the domain where your docs are being served.
72-
This is ``https://docs.readthedocs.io/_/api/v2/docsearch`` for the ``docs`` project, for example.
72+
This is ``https://docs.readthedocs.io/_/api/v2/search`` for the ``docs`` project, for example.
7373

7474
.. warning::
7575

7676
This API isn't stable yet, some small things may change in the future.
7777

78-
.. http:get:: /_/api/v2/docsearch/
78+
.. http:get:: /_/api/v2/search/
7979
8080
Return a list of search results for a project,
8181
including results from its :doc:`/subprojects`.
@@ -112,12 +112,12 @@ This is ``https://docs.readthedocs.io/_/api/v2/docsearch`` for the ``docs`` proj
112112

113113
.. code-tab:: bash
114114

115-
$ curl "https://docs.readthedocs.io/_/api/v2/docsearch/?project=docs&version=latest&q=server%20side%20search"
115+
$ curl "https://docs.readthedocs.io/_/api/v2/search/?project=docs&version=latest&q=server%20side%20search"
116116

117117
.. code-tab:: python
118118

119119
import requests
120-
URL = 'https://docs.readthedocs.io/_/api/v2/docsearch/'
120+
URL = 'https://docs.readthedocs.io/_/api/v2/search/'
121121
params = {
122122
'q': 'server side search',
123123
'project': 'docs',
@@ -132,7 +132,7 @@ This is ``https://docs.readthedocs.io/_/api/v2/docsearch`` for the ``docs`` proj
132132

133133
{
134134
"count": 41,
135-
"next": "https://docs.readthedocs.io/api/v2/docsearch/?page=2&project=read-the-docs&q=server+side+search&version=latest",
135+
"next": "https://docs.readthedocs.io/api/v2/search/?page=2&project=read-the-docs&q=server+side+search&version=latest",
136136
"previous": null,
137137
"results": [
138138
{
@@ -164,8 +164,8 @@ This is ``https://docs.readthedocs.io/_/api/v2/docsearch`` for the ``docs`` proj
164164
{
165165
"type": "domain",
166166
"role": "http:get",
167-
"name": "/_/api/v2/docsearch/",
168-
"id": "get--_-api-v2-docsearch-",
167+
"name": "/_/api/v2/search/",
168+
"id": "get--_-api-v2-search-",
169169
"content": "Retrieve search results for docs",
170170
"highlights": {
171171
"name": [""],

readthedocs/api/v2/proxied_urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
api_footer_urls = [
1515
url(r'footer_html/', ProxiedFooterHTML.as_view(), name='footer_html'),
1616
url(r'docsearch/$', ProxiedPageSearchAPIView.as_view(), name='doc_search'),
17+
url(r'search/$', ProxiedPageSearchAPIView.as_view(new_api=True), name='search_api'),
1718
]
1819

1920
urlpatterns = api_footer_urls

readthedocs/core/static-src/core/js/doc-embed/search.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ function attach_elastic_search_query_sphinx(data) {
4949
var search_def = $.Deferred();
5050
var search_url = document.createElement('a');
5151

52-
search_url.href = data.proxied_api_host + '/api/v2/docsearch/';
52+
search_url.href = data.proxied_api_host + '/api/v2/search/';
5353
search_url.search = '?q=' + $.urlencode(query) + '&project=' + project +
54-
'&version=' + version + '&language=' + language + '&new-api=true';
54+
'&version=' + version + '&language=' + language;
5555

5656
search_def
5757
.then(function (data) {
@@ -273,9 +273,9 @@ function attach_elastic_search_query_mkdocs(data) {
273273
var search_def = $.Deferred();
274274

275275
var search_url = document.createElement('a');
276-
search_url.href = data.proxied_api_host + '/api/v2/docsearch/';
276+
search_url.href = data.proxied_api_host + '/api/v2/search/';
277277
search_url.search = '?q=' + encodeURIComponent(query) + '&project=' + project +
278-
'&version=' + version + '&language=' + language + '&new-api=true';
278+
'&version=' + version + '&language=' + language;
279279

280280
search_def
281281
.then(function (data) {

readthedocs/core/static/core/js/readthedocs-doc-embed.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

readthedocs/search/api.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ class PageSearchAPIView(GenericAPIView):
194194
- project
195195
- version
196196
197-
Optional params:
197+
Optional params from the view:
198198
199-
- new-api (true/false): make use of the new stable API.
199+
- new_api (true/false): Make use of the new stable API.
200200
Defaults to false. Remove after a couple of days/weeks
201201
and always use the new API.
202202
@@ -209,6 +209,7 @@ class PageSearchAPIView(GenericAPIView):
209209
http_method_names = ['get']
210210
permission_classes = [IsAuthorizedToViewVersion]
211211
pagination_class = SearchPagination
212+
new_api = False
212213

213214
def _get_project(self):
214215
cache_key = '_cached_project'
@@ -371,7 +372,7 @@ def get_queryset(self):
371372
return queryset
372373

373374
def get_serializer_class(self):
374-
if self.request.query_params.get('new-api', 'false') == 'true':
375+
if self.new_api:
375376
return PageSearchSerializer
376377
return OldPageSearchSerializer
377378

readthedocs/search/tests/test_api.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@ def setup_method(self, method):
3333
# This reverse needs to be inside the ``setup_method`` method because from
3434
# the Corporate site we don't define this URL if ``-ext`` module is not
3535
# installed
36-
self.url = reverse('doc_search')
36+
self.url = reverse('search_api')
3737

3838
def get_search(self, api_client, search_params):
39-
# TODO: remove once the api is stable
40-
search_params['new-api'] = 'true'
4139
return api_client.get(self.url, search_params)
4240

4341
@pytest.mark.parametrize('page_num', [0, 1])

readthedocs/search/tests/test_search_tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def setup_class(cls):
2020
# This reverse needs to be inside the ``setup_class`` method because from
2121
# the Corporate site we don't define this URL if ``-ext`` module is not
2222
# installed
23-
cls.url = reverse('doc_search')
23+
cls.url = reverse('search_api')
2424

2525
def test_search_query_recorded_when_results_not_zero(self, api_client):
2626
"""Test if search query is recorded in a database when a search is made."""

readthedocs/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
url(r'^api/v2/', include('readthedocs.api.v2.urls')),
5252
# Keep the `doc_search` at root level, so the test does not fail for other API
5353
url(r'^api/v2/docsearch/$', PageSearchAPIView.as_view(), name='doc_search'),
54+
url(r'^api/v2/search/$', PageSearchAPIView.as_view(new_api=True), name='search_api'),
5455
url(
5556
r'^api-auth/',
5657
include('rest_framework.urls', namespace='rest_framework')

0 commit comments

Comments
 (0)