Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pathway association in algolia objects and sort results #475

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions enterprise_catalog/apps/catalog/algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
'prices',
'course_details',
'banner_image_url',
'visible_via_association',
]

# default configuration for the index
Expand Down Expand Up @@ -109,6 +110,7 @@
'enterprise_customer_uuids',
],
'customRanking': [
'asc(visible_via_association)',
'desc(recent_enrollment_count)',
],
}
Expand Down Expand Up @@ -455,6 +457,19 @@ def get_pathway_card_image_url(pathway):
return None


def get_pathway_association(pathway):
"""
Gets the pathway association

Arguments:
pathway (dict): a dictionary representing a pathway.

Returns:
bool: True if available via association else False
"""
return bool(pathway.get('visible_via_association', False))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visible_via_association is already a boolean field, Why do we need this method?



def get_pathway_partners(pathway):
"""
Gets the partners for a pathway. Used for the "partners.name" facet in Algolia.
Expand Down Expand Up @@ -1080,6 +1095,7 @@ def _algolia_object_from_product(product, algolia_fields):
'card_image_url': get_pathway_card_image_url(searchable_product),
'partners': get_pathway_partners(searchable_product),
'subjects': get_pathway_subjects(searchable_product),
'visible_via_association': get_pathway_association(searchable_product),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visible_via_association should be already available here in searchable_product as a boolean field.

})

algolia_object = {}
Expand Down
23 changes: 23 additions & 0 deletions enterprise_catalog/apps/catalog/tests/test_algolia_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
get_course_skill_names,
get_course_subjects,
get_initialized_algolia_client,
get_pathway_association,
get_pathway_availability,
get_pathway_card_image_url,
get_pathway_course_keys,
Expand Down Expand Up @@ -1196,6 +1197,28 @@ def test_get_pathway_card_image(self, pathway_metadata, expected_type):
image_url = get_pathway_card_image_url(pathway_metadata)
self.assertEqual(expected_type, image_url)

@ddt.data(
(
{'visible_via_association': False},
False,
),
(
{'visible_via_association': True},
True,
),
(
{'visible_via_association': None},
False,
),
)
@ddt.unpack
def test_get_pathway_association(self, pathway_metadata, expected_value):
"""
Assert that the visible via association is properly parsed.
"""
pathway_association = get_pathway_association(pathway_metadata)
self.assertEqual(expected_value, pathway_association)

@ddt.data(
(
{'steps': [
Expand Down