Skip to content

Commit d7a084e

Browse files
authored
Search: default to search on default version of subprojects (#8148)
This flag has been set to true for a while now.
1 parent c941723 commit d7a084e

File tree

3 files changed

+11
-41
lines changed

3 files changed

+11
-41
lines changed

readthedocs/projects/models.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,7 +1598,6 @@ def add_features(sender, **kwargs):
15981598
ENABLE_MKDOCS_SERVER_SIDE_SEARCH = 'enable_mkdocs_server_side_search'
15991599
DEFAULT_TO_FUZZY_SEARCH = 'default_to_fuzzy_search'
16001600
INDEX_FROM_HTML_FILES = 'index_from_html_files'
1601-
SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION = 'search_subprojects_on_default_version'
16021601

16031602
LIST_PACKAGES_INSTALLED_ENV = 'list_packages_installed_env'
16041603
VCS_REMOTE_LISTING = 'vcs_remote_listing'
@@ -1712,13 +1711,6 @@ def add_features(sender, **kwargs):
17121711
INDEX_FROM_HTML_FILES,
17131712
_('Index content directly from html files instead or relying in other sources'),
17141713
),
1715-
(
1716-
SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION,
1717-
_(
1718-
'When searching subprojects default to its default version if it doesn\'t '
1719-
'have the same version as the main project'
1720-
),
1721-
),
17221714

17231715
(
17241716
LIST_PACKAGES_INSTALLED_ENV,

readthedocs/search/api.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,7 @@ def _get_all_projects_data(self):
228228
)
229229

230230
# Fallback to the default version of the subproject.
231-
if (
232-
not version
233-
and main_project.has_feature(Feature.SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION)
234-
and subproject.default_version
235-
):
231+
if not version and subproject.default_version:
236232
version = self._get_subproject_version(
237233
version_slug=subproject.default_version,
238234
subproject=subproject,
@@ -307,35 +303,21 @@ def get_queryset(self):
307303
main_project = self._get_project()
308304
main_version = self._get_version()
309305
projects = {}
310-
filters = {}
311-
312-
if main_project.has_feature(Feature.SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION):
313-
projects = {
314-
project: project_data.version.slug
315-
for project, project_data in self._get_all_projects_data().items()
316-
}
317-
# Check to avoid searching all projects in case it's empty.
318-
if not projects:
319-
log.info('Unable to find a version to search')
320-
return []
321-
else:
322-
filters['project'] = list(self._get_all_projects_data().keys())
323-
filters['version'] = main_version.slug
324-
# Check to avoid searching all projects in case these filters are empty.
325-
if not filters['project']:
326-
log.info('Unable to find a project to search')
327-
return []
328-
if not filters['version']:
329-
log.info('Unable to find a version to search')
330-
return []
306+
307+
projects = {
308+
project: project_data.version.slug
309+
for project, project_data in self._get_all_projects_data().items()
310+
}
311+
# Check to avoid searching all projects in case it's empty.
312+
if not projects:
313+
log.info('Unable to find a version to search')
314+
return []
331315

332316
query = self.request.query_params['q']
333317
queryset = PageSearch(
334318
query=query,
335319
projects=projects,
336-
filters=filters,
337-
user=self.request.user,
338-
# We use a permission class to control authorization
320+
# We use a permission class to control authorization.
339321
filter_by_user=False,
340322
use_advanced_query=not main_project.has_feature(Feature.DEFAULT_TO_FUZZY_SEARCH),
341323
)

readthedocs/search/tests/test_api.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,6 @@ def test_doc_search_subprojects_default_version(self, api_client, all_projects):
277277
"""Return results from subprojects that match the version from the main project or fallback to its default version."""
278278
project = all_projects[0]
279279
version = project.versions.all()[0]
280-
feature, _ = Feature.objects.get_or_create(
281-
feature_id=Feature.SEARCH_SUBPROJECTS_ON_DEFAULT_VERSION,
282-
)
283-
project.feature_set.add(feature)
284280

285281
subproject = all_projects[1]
286282
subproject_version = subproject.versions.all()[0]

0 commit comments

Comments
 (0)