feat: options for excluding courses from search

Adds two new fields to the indexed course data:
- invitation_only
- catalog_visibility

Also adds two new settings:
`SEARCH_SKIP_INVITATION_ONLY_FILTERING`
`SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING`

These settings can be used to filter out courses in the search results
based on their catalog visibility or based on whether they are
invitation-only courses.
This commit is contained in:
ha-D
2021-08-20 12:05:49 +00:00
committed by Braden MacDonald
parent 07b767a8a1
commit a4b36346c9
4 changed files with 21 additions and 0 deletions

View File

@@ -587,6 +587,8 @@ class CourseAboutSearchIndexer(CoursewareSearchIndexer):
AboutInfo("org", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY),
AboutInfo("modes", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_MODE),
AboutInfo("language", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY),
AboutInfo("invitation_only", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY),
AboutInfo("catalog_visibility", AboutInfo.PROPERTY, AboutInfo.FROM_COURSE_PROPERTY),
]
@classmethod

View File

@@ -4009,6 +4009,10 @@ SEARCH_RESULT_PROCESSOR = "lms.lib.courseware_search.lms_result_processor.LmsSea
SEARCH_FILTER_GENERATOR = "lms.lib.courseware_search.lms_filter_generator.LmsSearchFilterGenerator"
# Override to skip enrollment start date filtering in course search
SEARCH_SKIP_ENROLLMENT_START_DATE_FILTERING = False
# Override to skip excluding invitation-only courses in course search
SEARCH_SKIP_INVITATION_ONLY_FILTERING = True
# Override to skip excluding non-catalog courses in course search
SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING = True
# The configuration visibility of account fields.
ACCOUNT_VISIBILITY_CONFIGURATION = {

View File

@@ -728,6 +728,15 @@ if FEATURES.get('ENABLE_COURSEWARE_SEARCH') or \
SEARCH_ENGINE = "search.elastic.ElasticSearchEngine"
SEARCH_FILTER_GENERATOR = ENV_TOKENS.get('SEARCH_FILTER_GENERATOR', SEARCH_FILTER_GENERATOR)
SEARCH_SKIP_INVITATION_ONLY_FILTERING = ENV_TOKENS.get(
'SEARCH_SKIP_INVITATION_ONLY_FILTERING',
SEARCH_SKIP_INVITATION_ONLY_FILTERING
)
SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING = ENV_TOKENS.get(
'SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING',
SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING
)
# TODO: Once we have successfully upgraded to ES7, switch this back to ELASTIC_SEARCH_CONFIG.
ELASTIC_SEARCH_CONFIG = ENV_TOKENS.get('ELASTIC_SEARCH_CONFIG_ES7', [{}])

View File

@@ -2,6 +2,7 @@
This file contains implementation override of SearchFilterGenerator which will allow
* Filter by all courses in which the user is enrolled in
"""
from django.conf import settings
from search.filter_generator import SearchFilterGenerator
from openedx.core.djangoapps.course_groups.partition_scheme import CohortPartitionScheme
@@ -52,4 +53,9 @@ class LmsSearchFilterGenerator(SearchFilterGenerator):
if org_filter_out_set:
exclude_dictionary['org'] = list(org_filter_out_set)
if not getattr(settings, "SEARCH_SKIP_INVITATION_ONLY_FILTERING", False):
exclude_dictionary['invitation_only'] = True
if not getattr(settings, "SEARCH_SKIP_SHOW_IN_CATALOG_FILTERING", False):
exclude_dictionary['catalog_visibility'] = 'none'
return exclude_dictionary