From aeaa1f8628f37713c572e86c0fbe798428f53718 Mon Sep 17 00:00:00 2001 From: Andy Shultz Date: Tue, 14 Nov 2023 09:08:41 -0500 Subject: [PATCH] feat: if course is specified, do not build the course limiting filters Adding these filters in the course case makes it harder to understand what is going on in the search engine for no benefit. --- .../courseware_search/lms_filter_generator.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lms/lib/courseware_search/lms_filter_generator.py b/lms/lib/courseware_search/lms_filter_generator.py index c4e5ab7ac7..b0c0564df4 100644 --- a/lms/lib/courseware_search/lms_filter_generator.py +++ b/lms/lib/courseware_search/lms_filter_generator.py @@ -28,16 +28,18 @@ class LmsSearchFilterGenerator(SearchFilterGenerator): def field_dictionary(self, **kwargs): """ add course if provided otherwise add courses in which the user is enrolled in """ field_dictionary = super().field_dictionary(**kwargs) + course_id = kwargs.get('course_id') if not kwargs.get('user'): field_dictionary['course'] = [] - elif not kwargs.get('course_id'): + elif not course_id: user_enrollments = self._enrollments_for_user(kwargs['user']) field_dictionary['course'] = [str(enrollment.course_id) for enrollment in user_enrollments] - # if we have an org filter, only include results for this org filter - course_org_filter = configuration_helpers.get_current_site_orgs() - if course_org_filter: - field_dictionary['org'] = course_org_filter + # if we have no specific course and an org filter, only include results for this org filter + if not course_id: + course_org_filter = configuration_helpers.get_current_site_orgs() + if course_org_filter: + field_dictionary['org'] = course_org_filter return field_dictionary @@ -46,6 +48,11 @@ class LmsSearchFilterGenerator(SearchFilterGenerator): Exclude any courses defined outside the current org. """ exclude_dictionary = super().exclude_dictionary(**kwargs) + # If we are already filtering to a single course, we do not need + # the further course filters below. + if kwargs.get('course_id'): + return exclude_dictionary + course_org_filter = configuration_helpers.get_current_site_orgs() # If we have a course filter we are ensuring that we only get those courses above if not course_org_filter: