Skip to content

Commit

Permalink
feat: add learning_type facet to algolia index (#3987)
Browse files Browse the repository at this point in the history
  • Loading branch information
bseverino authored Jul 5, 2023
1 parent 20892ae commit 3f698b3
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
12 changes: 11 additions & 1 deletion course_discovery/apps/course_metadata/algolia_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def delegate_attributes(cls):
search_fields = ['partner_names', 'partner_keys', 'product_title', 'product_source', 'primary_description',
'secondary_description', 'tertiary_description']
facet_fields = ['availability_level', 'subject_names', 'levels', 'active_languages', 'staff_slugs',
'product_allowed_in', 'product_blocked_in']
'product_allowed_in', 'product_blocked_in', 'learning_type']
ranking_fields = ['availability_rank', 'product_recent_enrollment_count', 'promoted_in_spanish_index',
'product_value_per_click_usa', 'product_value_per_click_international',
'product_value_per_lead_usa', 'product_value_per_lead_international']
Expand Down Expand Up @@ -290,6 +290,10 @@ def subject_names(self):
def program_types(self):
return [program.type.name_t for program in self.programs.all()]

@property
def learning_type(self):
return [self.product_type, *self.program_types]

@property
def product_card_image_url(self):
if self.image:
Expand Down Expand Up @@ -529,6 +533,12 @@ def program_types(self):
return [self.type.name_t]
return None

@property
def learning_type(self):
if self.type:
return [self.type.name_t]
return []

@property
def tags(self):
topics = [topic.name for topic in self.topics]
Expand Down
7 changes: 4 additions & 3 deletions course_discovery/apps/course_metadata/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class EnglishProductIndex(BaseProductIndex):
('active_languages', 'language'), ('product_type', 'product'), ('program_types', 'program_type'),
('staff_slugs', 'staff'), ('product_allowed_in', 'allowed_in'),
('product_blocked_in', 'blocked_in'), 'subscription_eligible',
'subscription_prices')
'subscription_prices', 'learning_type',)
ranking_fields = ('availability_rank', ('product_recent_enrollment_count', 'recent_enrollment_count'),
('product_value_per_click_usa', 'value_per_click_usa'),
('product_value_per_click_international', 'value_per_click_international'),
Expand Down Expand Up @@ -116,6 +116,7 @@ class EnglishProductIndex(BaseProductIndex):
'partner', 'availability', 'subject', 'level', 'language', 'product', 'program_type',
'filterOnly(staff)', 'filterOnly(allowed_in)', 'filterOnly(blocked_in)', 'skills.skill',
'skills.category', 'skills.subcategory', 'tags', 'subscription_eligible', 'subscription_prices',
'learning_type',
],
'customRanking': ['asc(availability_rank)', 'desc(recent_enrollment_count)']
}
Expand All @@ -132,7 +133,7 @@ class SpanishProductIndex(BaseProductIndex):
('active_languages', 'language'), ('product_type', 'product'), ('program_types', 'program_type'),
('staff_slugs', 'staff'), ('product_allowed_in', 'allowed_in'),
('product_blocked_in', 'blocked_in'), 'subscription_eligible',
'subscription_prices',)
'subscription_prices', 'learning_type',)
ranking_fields = ('availability_rank', ('product_recent_enrollment_count', 'recent_enrollment_count'),
('product_value_per_click_usa', 'value_per_click_usa'),
('product_value_per_click_international', 'value_per_click_international'),
Expand Down Expand Up @@ -170,7 +171,7 @@ class SpanishProductIndex(BaseProductIndex):
'partner', 'availability', 'subject', 'level', 'language', 'product', 'program_type',
'filterOnly(staff)', 'filterOnly(allowed_in)', 'filterOnly(blocked_in)',
'skills.skill', 'skills.category', 'skills.subcategory', 'tags', 'subscription_eligible',
'subscription_prices',
'subscription_prices', 'learning_type',
],
'customRanking': ['desc(promoted_in_spanish_index)', 'asc(availability_rank)', 'desc(recent_enrollment_count)']
}
Expand Down
27 changes: 27 additions & 0 deletions course_discovery/apps/course_metadata/tests/test_algolia_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,28 @@ def test_null_in_year_value(self):
assert course.product_value_per_lead_usa == ProductValue.DEFAULT_VALUE_PER_LEAD
assert course.product_value_per_lead_international == ProductValue.DEFAULT_VALUE_PER_LEAD

@ddt.data(False, True)
def test_learning_type_open_course(self, has_program):
course_type = CourseTypeFactory()
course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner, type=course_type)
if has_program:
program_type = ProgramTypeFactory()
program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, type=program_type)
course.programs.set([program])
assert course.learning_type == ['Course', program_type.name_t]
else:
assert course.learning_type == ['Course']

@ddt.data(
(CourseType.EXECUTIVE_EDUCATION_2U, 'Executive Education'),
(CourseType.BOOTCAMP_2U, 'Boot Camp'),
)
@ddt.unpack
def test_learning_type_non_open_course(self, course_type_slug, expected_result):
course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner)
course.type = CourseTypeFactory(slug=course_type_slug)
assert course.learning_type == [expected_result]


@ddt.ddt
@pytest.mark.django_db
Expand Down Expand Up @@ -810,3 +832,8 @@ def test_null_in_year_value(self):
assert program.product_value_per_click_international == ProductValue.DEFAULT_VALUE_PER_CLICK
assert program.product_value_per_lead_usa == ProductValue.DEFAULT_VALUE_PER_LEAD
assert program.product_value_per_lead_international == ProductValue.DEFAULT_VALUE_PER_LEAD

def test_learning_type(self):
program_type = ProgramTypeFactory()
program = AlgoliaProxyProgramFactory(partner=self.__class__.edxPartner, type=program_type)
assert program.learning_type == [program_type.name_t]

0 comments on commit 3f698b3

Please sign in to comment.