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

Add organization and category filter in course_runs and programs #70

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
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]},

}
Loading