Skip to content

Search: use doctype from indexed pages instead of the db #7984

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions readthedocs/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,13 @@ def _get_all_projects_data(self):
alias='alias',
version=VersionData(
"latest",
"sphinx",
"https://requests.readthedocs.io/en/latest/",
),
),
"requests-oauth": ProjectData(
alias=None,
version=VersionData(
"latest",
"sphinx_htmldir",
"https://requests-oauth.readthedocs.io/en/latest/",
),
),
Expand All @@ -215,7 +213,6 @@ def _get_all_projects_data(self):
alias=None,
version=VersionData(
slug=main_version.slug,
doctype=main_version.documentation_type,
docs_url=main_project.get_docs_url(version_slug=main_version.slug),
),
)
Expand Down Expand Up @@ -246,7 +243,6 @@ def _get_all_projects_data(self):
project_alias = subproject.superprojects.values_list('alias', flat=True).first()
version_data = VersionData(
slug=version.slug,
doctype=version.documentation_type,
docs_url=url,
)
projects_data[subproject.slug] = ProjectData(
Expand Down
5 changes: 2 additions & 3 deletions readthedocs/search/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# Structure used for storing cached data of a version mostly.
ProjectData = namedtuple('ProjectData', ['version', 'alias'])
VersionData = namedtuple('VersionData', ['slug', 'docs_url', 'doctype'])
VersionData = namedtuple('VersionData', ['slug', 'docs_url'])


class ProjectHighlightSerializer(serializers.Serializer):
Expand Down Expand Up @@ -89,7 +89,6 @@ def _get_project_data(self, obj):
version_data = VersionData(
slug=obj.version,
docs_url=docs_url,
doctype=None,
)
projects_data[obj.project] = ProjectData(
alias=project_alias,
Expand Down Expand Up @@ -126,7 +125,7 @@ def _get_full_path(self, obj):

# Generate an appropriate link for the doctypes that use htmldir,
# and always end it with / so it goes directly to proxito.
if project_data.version.doctype in {SPHINX_HTMLDIR, MKDOCS}:
if obj.doctype in {SPHINX_HTMLDIR, MKDOCS}:
path = re.sub('(^|/)index.html$', '/', path)

return docs_url.rstrip('/') + '/' + path.lstrip('/')
Expand Down
30 changes: 30 additions & 0 deletions readthedocs/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ def test_search_correct_link_for_normal_page_html_projects(self, api_client, doc
project.versions.update(documentation_type=doctype)
version = project.versions.all().first()

# Refresh index
version_files = HTMLFile.objects.all().filter(version=version)
for f in version_files:
PageDocument().update(f)

search_params = {
'project': project.slug,
'version': version.slug,
Expand All @@ -428,6 +433,11 @@ def test_search_correct_link_for_index_page_html_projects(self, api_client, doct
project.versions.update(documentation_type=doctype)
version = project.versions.all().first()

# Refresh index
version_files = HTMLFile.objects.all().filter(version=version)
for f in version_files:
PageDocument().update(f)

search_params = {
'project': project.slug,
'version': version.slug,
Expand All @@ -446,6 +456,11 @@ def test_search_correct_link_for_index_page_subdirectory_html_projects(self, api
project.versions.update(documentation_type=doctype)
version = project.versions.all().first()

# Refresh index
version_files = HTMLFile.objects.all().filter(version=version)
for f in version_files:
PageDocument().update(f)

search_params = {
'project': project.slug,
'version': version.slug,
Expand All @@ -464,6 +479,11 @@ def test_search_correct_link_for_normal_page_htmldir_projects(self, api_client,
project.versions.update(documentation_type=doctype)
version = project.versions.all().first()

# Refresh index
version_files = HTMLFile.objects.all().filter(version=version)
for f in version_files:
PageDocument().update(f)

search_params = {
'project': project.slug,
'version': version.slug,
Expand All @@ -482,6 +502,11 @@ def test_search_correct_link_for_index_page_htmldir_projects(self, api_client, d
project.versions.update(documentation_type=doctype)
version = project.versions.all().first()

# Refresh index
version_files = HTMLFile.objects.all().filter(version=version)
for f in version_files:
PageDocument().update(f)

search_params = {
'project': project.slug,
'version': version.slug,
Expand All @@ -500,6 +525,11 @@ def test_search_correct_link_for_index_page_subdirectory_htmldir_projects(self,
project.versions.update(documentation_type=doctype)
version = project.versions.all().first()

# Refresh index
version_files = HTMLFile.objects.all().filter(version=version)
for f in version_files:
PageDocument().update(f)

search_params = {
'project': project.slug,
'version': version.slug,
Expand Down
6 changes: 0 additions & 6 deletions readthedocs/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,10 @@ def _get_project(self, project_slug):
return project

def _get_project_data(self, project, version_slug):
version_doctype = (
project.versions
.values_list('documentation_type', flat=True)
.get(slug=version_slug)
)
docs_url = project.get_docs_url(version_slug=version_slug)
version_data = VersionData(
slug=version_slug,
docs_url=docs_url,
doctype=version_doctype,
)
project_data = {
project.slug: ProjectData(
Expand Down