Skip to content

Commit

Permalink
feat: add organization and category filter in course_runs and programs
Browse files Browse the repository at this point in the history
  • Loading branch information
hinakhadim committed Oct 23, 2023
1 parent 1e28f1d commit 88c2016
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions course_discovery/apps/api/v1/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ProgramSearchViewSet(BaseElasticsearchDocumentViewSet):
'title': 'title',
'type': {'field': 'type.raw'},
'uuid': 'uuid',
'org': {'field': 'org', 'lookups': [LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_QUERY_EXCLUDE]}
}

def get_serializer_context(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ProgramDocument(BaseDocument, OrganizationsMixin):
no_of_courses = fields.IntegerField(fields={'raw': fields.KeywordField()})
one_click_purchase_enabled = fields.BooleanField()

org = fields.KeywordField(multi=True)

def prepare_aggregation_key(self, obj):
return 'program:{}'.format(obj.uuid)

Expand Down Expand Up @@ -124,6 +126,10 @@ def prepare_type(self, obj):

def prepare_no_of_courses(self, obj):
return len([course_run for course_run in obj.course_runs])

def prepare_org(self, obj):
organizations = [org.key for org in obj.authoring_organizations.all()] + [org.key for org in obj.credit_backing_organizations.all()]
return list(set(organizations))

def get_queryset(self):
return super().get_queryset().select_related('type').select_related('partner').prefetch_related('courses__course_runs')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from discovery_dataloader_app import serializers
from django_elasticsearch_dsl_drf.constants import (
LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_QUERY_EXCLUDE,
LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_QUERY_EXCLUDE, LOOKUP_QUERY_IN
)
from django_elasticsearch_dsl_drf.filter_backends import DefaultOrderingFilterBackend, FilteringFilterBackend, MultiMatchSearchFilterBackend, SearchFilterBackend
from opaque_keys.edx.keys import CourseKey
Expand Down Expand Up @@ -97,6 +97,8 @@ class DataLoaderCourseRunSearchViewSet(CourseRunSearchViewSet):
'published': 'published',
'availability': 'availability',
'featured': 'course_overridden',
'title': 'title',
'number': 'number',
'org': {'field': 'org.raw', 'lookups': [LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS]},
'category': {'field': 'subjects.raw', 'lookups': [LOOKUP_FILTER_TERM, LOOKUP_FILTER_TERMS, LOOKUP_QUERY_IN]},

}

0 comments on commit 88c2016

Please sign in to comment.