Skip to content

Commit bf6ccbe

Browse files
committed
deleting old search code
1 parent 21fed3a commit bf6ccbe

File tree

8 files changed

+2
-956
lines changed

8 files changed

+2
-956
lines changed

readthedocs/projects/tasks.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@
5050
from readthedocs.doc_builder.python_environments import Conda, Virtualenv
5151
from readthedocs.projects.models import APIProject
5252
from readthedocs.restapi.client import api as api_v2
53-
from readthedocs.restapi.utils import index_search_request
54-
from readthedocs.search.parse_json import process_all_json_files
5553
from readthedocs.vcs_support import utils as vcs_support_utils
5654
from readthedocs.worker import app
5755
from .constants import LOG_TEMPLATE
@@ -902,40 +900,6 @@ def move_files(version_pk, hostname, html=False, localmedia=False, search=False,
902900
Syncer.copy(from_path, to_path, host=hostname)
903901

904902

905-
@app.task(queue='web')
906-
def update_search(version_pk, commit, delete_non_commit_files=True):
907-
"""
908-
Task to update search indexes.
909-
910-
:param version_pk: Version id to update
911-
:param commit: Commit that updated index
912-
:param delete_non_commit_files: Delete files not in commit from index
913-
"""
914-
version = Version.objects.get(pk=version_pk)
915-
916-
if version.project.is_type_sphinx:
917-
page_list = process_all_json_files(version, build_dir=False)
918-
else:
919-
log.debug('Unknown documentation type: %s',
920-
version.project.documentation_type)
921-
return
922-
923-
log_msg = ' '.join([page['path'] for page in page_list])
924-
log.info("(Search Index) Sending Data: %s [%s]", version.project.slug,
925-
log_msg)
926-
index_search_request(
927-
version=version,
928-
page_list=page_list,
929-
commit=commit,
930-
project_scale=0,
931-
page_scale=0,
932-
# Don't index sections to speed up indexing.
933-
# They aren't currently exposed anywhere.
934-
section=False,
935-
delete=delete_non_commit_files,
936-
)
937-
938-
939903
@app.task(queue='web')
940904
def symlink_project(project_pk):
941905
project = Project.objects.get(pk=project_pk)

readthedocs/projects/views/public.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from readthedocs.builds.views import BuildTriggerMixin
2929
from readthedocs.projects.models import ImportedFile, Project
3030
from readthedocs.search.documents import PageDocument
31-
from readthedocs.search.indexes import PageIndex
3231
from readthedocs.search.views import LOG_TEMPLATE
3332

3433
from .base import ProjectOnboardMixin

readthedocs/restapi/urls.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@
1414
from rest_framework import routers
1515

1616
from readthedocs.constants import pattern_opts
17-
from readthedocs.restapi import views
18-
from readthedocs.restapi.views import (
19-
core_views,
20-
footer_views,
21-
integrations,
22-
search_views,
23-
task_views,
24-
)
25-
17+
from readthedocs.restapi.views import (core_views, footer_views, task_views, integrations)
2618
from .views.model_views import (
2719
BuildCommandViewSet,
2820
BuildViewSet,
@@ -69,24 +61,6 @@
6961
url(r'footer_html/', footer_views.footer_html, name='footer_html'),
7062
]
7163

72-
search_urls = [
73-
url(
74-
r'index_search/',
75-
search_views.index_search,
76-
name='index_search',
77-
),
78-
url(r'^search/$', views.search_views.search, name='api_search'),
79-
url(r'search/project/$',
80-
search_views.project_search,
81-
name='api_project_search',
82-
),
83-
url(
84-
r'search/section/$',
85-
search_views.section_search,
86-
name='api_section_search',
87-
),
88-
]
89-
9064
task_urls = [
9165
url(
9266
r'jobs/status/(?P<task_id>[^/]+)/',
@@ -138,7 +112,6 @@
138112

139113
urlpatterns += function_urls
140114
urlpatterns += task_urls
141-
urlpatterns += search_urls
142115
urlpatterns += integration_urls
143116

144117

readthedocs/restapi/utils.py

Lines changed: 0 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from __future__ import (
55
absolute_import, division, print_function, unicode_literals)
66

7-
import hashlib
87
import logging
98

109
from rest_framework.pagination import PageNumberPagination
@@ -13,7 +12,6 @@
1312
NON_REPOSITORY_VERSIONS, STABLE,
1413
STABLE_VERBOSE_NAME)
1514
from readthedocs.builds.models import Version
16-
from readthedocs.search.indexes import PageIndex, ProjectIndex, SectionIndex
1715

1816
log = logging.getLogger(__name__)
1917

@@ -154,119 +152,6 @@ def delete_versions(project, version_data):
154152
return set()
155153

156154

157-
def index_search_request(
158-
version, page_list, commit, project_scale, page_scale, section=True,
159-
delete=True):
160-
"""
161-
Update search indexes with build output JSON.
162-
163-
In order to keep sub-projects all indexed on the same shard, indexes will be
164-
updated using the parent project's slug as the routing value.
165-
"""
166-
# TODO refactor this function
167-
# pylint: disable=too-many-locals
168-
project = version.project
169-
170-
log_msg = ' '.join([page['path'] for page in page_list])
171-
log.info(
172-
'Updating search index: project=%s pages=[%s]',
173-
project.slug,
174-
log_msg,
175-
)
176-
177-
project_obj = ProjectIndex()
178-
project_obj.index_document(
179-
data={
180-
'id': project.pk,
181-
'name': project.name,
182-
'slug': project.slug,
183-
'description': project.description,
184-
'lang': project.language,
185-
'author': [user.username for user in project.users.all()],
186-
'url': project.get_absolute_url(),
187-
'tags': None,
188-
'weight': project_scale,
189-
})
190-
191-
page_obj = PageIndex()
192-
section_obj = SectionIndex()
193-
index_list = []
194-
section_index_list = []
195-
routes = [project.slug]
196-
routes.extend([p.parent.slug for p in project.superprojects.all()])
197-
for page in page_list:
198-
log.debug('Indexing page: %s:%s', project.slug, page['path'])
199-
to_hash = '-'.join([project.slug, version.slug, page['path']])
200-
page_id = hashlib.md5(to_hash.encode('utf-8')).hexdigest()
201-
index_list.append({
202-
'id': page_id,
203-
'project': project.slug,
204-
'version': version.slug,
205-
'path': page['path'],
206-
'title': page['title'],
207-
'headers': page['headers'],
208-
'content': page['content'],
209-
'taxonomy': None,
210-
'commit': commit,
211-
'weight': page_scale + project_scale,
212-
})
213-
if section:
214-
for sect in page['sections']:
215-
id_to_hash = '-'.join([
216-
project.slug,
217-
version.slug,
218-
page['path'],
219-
sect['id'],
220-
])
221-
section_index_list.append({
222-
'id': (hashlib.md5(id_to_hash.encode('utf-8')).hexdigest()),
223-
'project': project.slug,
224-
'version': version.slug,
225-
'path': page['path'],
226-
'page_id': sect['id'],
227-
'title': sect['title'],
228-
'content': sect['content'],
229-
'weight': page_scale,
230-
})
231-
for route in routes:
232-
section_obj.bulk_index(
233-
section_index_list,
234-
parent=page_id,
235-
routing=route,
236-
)
237-
238-
for route in routes:
239-
page_obj.bulk_index(index_list, parent=project.slug, routing=route)
240-
241-
if delete:
242-
log.info('Deleting files not in commit: %s', commit)
243-
# TODO: AK Make sure this works
244-
delete_query = {
245-
'query': {
246-
'bool': {
247-
'must': [
248-
{
249-
'term': {
250-
'project': project.slug,
251-
},
252-
},
253-
{
254-
'term': {
255-
'version': version.slug,
256-
},
257-
},
258-
],
259-
'must_not': {
260-
'term': {
261-
'commit': commit,
262-
},
263-
},
264-
},
265-
},
266-
}
267-
page_obj.delete_document(body=delete_query)
268-
269-
270155
class RemoteOrganizationPagination(PageNumberPagination):
271156
page_size = 25
272157

readthedocs/restapi/views/search_views.py

Lines changed: 0 additions & 151 deletions
This file was deleted.

0 commit comments

Comments
 (0)