Skip to content

Commit c971410

Browse files
committed
Keep path around, add full_path
1 parent ec839cd commit c971410

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

readthedocs/projects/models.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,8 @@ def get_processed_json(self):
12541254
return {
12551255
'headers': [],
12561256
'content': '',
1257-
'path': self.path,
1257+
'path': file_path,
1258+
'full_path': self.path,
12581259
'title': '',
12591260
'sections': [],
12601261
}

readthedocs/search/api.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,14 @@ def get_link(self, obj):
4242
projects_url = self.context.get('projects_url')
4343
if projects_url:
4444
docs_url = projects_url[obj.project]
45-
path = os.path.splitext(obj.path)[0]
46-
return docs_url + path
45+
return docs_url + obj.path
4746

4847
def get_url(self, obj):
4948
"""Gets the full url."""
5049
projects_url = self.context.get('projects_url')
5150
if projects_url:
5251
docs_url = projects_url[obj.project]
53-
return docs_url + obj.path
52+
return docs_url + obj.full_path
5453

5554
def get_highlight(self, obj):
5655
highlight = getattr(obj.meta, 'highlight', None)

readthedocs/search/documents.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class PageDocument(RTDDocTypeMixin, DocType):
116116
project = fields.KeywordField(attr='project.slug')
117117
version = fields.KeywordField(attr='version.slug')
118118
path = fields.KeywordField(attr='processed_json.path')
119+
full_path = fields.KeywordField(attr='processed_json.full_path')
119120

120121
# Searchable content
121122
title = fields.TextField(attr='processed_json.title')
@@ -153,7 +154,7 @@ def faceted_search(
153154

154155
def get_queryset(self):
155156
"""Overwrite default queryset to filter certain files to index."""
156-
queryset = super(PageDocument, self).get_queryset()
157+
queryset = super().get_queryset()
157158

158159
# Do not index files that belong to non sphinx project
159160
# Also do not index certain files

readthedocs/search/parse_json.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,15 @@ def process_file(fjson_filename, filename):
6969
raise
7070
data = json.loads(file_contents)
7171
sections = []
72+
path = ''
7273
title = ''
7374
body_content = ''
7475

76+
if 'current_page_name' in data:
77+
path = data['current_page_name']
78+
else:
79+
log.info('Unable to index file due to no name %s', filename)
80+
7581
if data.get('body'):
7682
body = PyQuery(data['body'])
7783
body_content = body.text().replace('¶', '')
@@ -89,7 +95,8 @@ def process_file(fjson_filename, filename):
8995
return {
9096
'headers': process_headers(data, fjson_filename),
9197
'content': body_content,
92-
'path': filename,
98+
'path': path,
99+
'full_path': filename,
93100
'title': title,
94101
'sections': sections,
95102
}

0 commit comments

Comments
 (0)