From 8d8b68b21bc34cd26afd8176a75735cdfe14b942 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 29 Apr 2021 17:03:09 -0500 Subject: [PATCH] Search: default to search on default version of subprojects This flag has been set to true for a while now. --- readthedocs/projects/models.py | 8 ------ readthedocs/search/api.py | 40 ++++++++-------------------- readthedocs/search/tests/test_api.py | 4 --- 3 files changed, 11 insertions(+), 41 deletions(-) diff --git a/readthedocs/projects/models.py b/readthedocs/projects/models.py index 23a89466f7a..bf6c4c03a20 100644 --- a/readthedocs/projects/models.py +++ b/readthedocs/projects/models.py @@ -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' @@ -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, diff --git a/readthedocs/search/api.py b/readthedocs/search/api.py index 68280b282fe..ed34b9e7a2c 100644 --- a/readthedocs/search/api.py +++ b/readthedocs/search/api.py @@ -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, @@ -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), ) diff --git a/readthedocs/search/tests/test_api.py b/readthedocs/search/tests/test_api.py index 5f355f3dff5..1efa212295d 100644 --- a/readthedocs/search/tests/test_api.py +++ b/readthedocs/search/tests/test_api.py @@ -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]