Skip to content

Search: default to search on default version of subprojects #8148

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
May 3, 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
8 changes: 0 additions & 8 deletions readthedocs/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1598,7 +1598,6 @@ def add_features(sender, **kwargs):
ENABLE_MKDOCS_SERVER_SIDE_SEARCH = 'enable_mkdocs_server_side_search'
DEFAULT_TO_FUZZY_SEARCH = 'default_to_fuzzy_search'
INDEX_FROM_HTML_FILES = 'index_from_html_files'
SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION = 'search_subprojects_on_default_version'

LIST_PACKAGES_INSTALLED_ENV = 'list_packages_installed_env'
VCS_REMOTE_LISTING = 'vcs_remote_listing'
Expand Down Expand Up @@ -1712,13 +1711,6 @@ def add_features(sender, **kwargs):
INDEX_FROM_HTML_FILES,
_('Index content directly from html files instead or relying in other sources'),
),
(
SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION,
_(
'When searching subprojects default to its default version if it doesn\'t '
'have the same version as the main project'
),
),

(
LIST_PACKAGES_INSTALLED_ENV,
Expand Down
40 changes: 11 additions & 29 deletions readthedocs/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,7 @@ def _get_all_projects_data(self):
)

# Fallback to the default version of the subproject.
if (
not version
and main_project.has_feature(Feature.SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION)
and subproject.default_version
):
if not version and subproject.default_version:
version = self._get_subproject_version(
version_slug=subproject.default_version,
subproject=subproject,
Expand Down Expand Up @@ -307,35 +303,21 @@ def get_queryset(self):
main_project = self._get_project()
main_version = self._get_version()
projects = {}
filters = {}

if main_project.has_feature(Feature.SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION):
projects = {
project: project_data.version.slug
for project, project_data in self._get_all_projects_data().items()
}
# Check to avoid searching all projects in case it's empty.
if not projects:
log.info('Unable to find a version to search')
return []
else:
filters['project'] = list(self._get_all_projects_data().keys())
filters['version'] = main_version.slug
# Check to avoid searching all projects in case these filters are empty.
if not filters['project']:
log.info('Unable to find a project to search')
return []
if not filters['version']:
log.info('Unable to find a version to search')
return []

projects = {
project: project_data.version.slug
for project, project_data in self._get_all_projects_data().items()
}
# Check to avoid searching all projects in case it's empty.
if not projects:
log.info('Unable to find a version to search')
return []

query = self.request.query_params['q']
queryset = PageSearch(
query=query,
projects=projects,
filters=filters,
user=self.request.user,
# We use a permission class to control authorization
# We use a permission class to control authorization.
filter_by_user=False,
use_advanced_query=not main_project.has_feature(Feature.DEFAULT_TO_FUZZY_SEARCH),
)
Expand Down
4 changes: 0 additions & 4 deletions readthedocs/search/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,6 @@ def test_doc_search_subprojects_default_version(self, api_client, all_projects):
"""Return results from subprojects that match the version from the main project or fallback to its default version."""
project = all_projects[0]
version = project.versions.all()[0]
feature, _ = Feature.objects.get_or_create(
feature_id=Feature.SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION,
)
project.feature_set.add(feature)

subproject = all_projects[1]
subproject_version = subproject.versions.all()[0]
Expand Down