Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
course-discovery
Commits
4608eef1
Commit
4608eef1
authored
Dec 09, 2016
by
Matthew Piatetsky
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Enable sorting search results by start date
parent
763b4205
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
2 deletions
+23
-2
course_discovery/apps/api/v1/tests/test_views/test_search.py
+19
-1
course_discovery/apps/api/v1/views/search.py
+4
-1
No files found.
course_discovery/apps/api/v1/tests/test_views/test_search.py
View file @
4608eef1
...
...
@@ -220,13 +220,13 @@ class CourseRunSearchViewSetTests(DefaultPartnerMixin, SerializationMixin, Login
self
.
assertEqual
(
response_data
[
'results'
][
0
]
.
get
(
'program_types'
),
[
active_program
.
type
.
name
])
@ddt.ddt
class
AggregateSearchViewSet
(
DefaultPartnerMixin
,
SerializationMixin
,
LoginMixin
,
ElasticsearchTestMixin
,
APITestCase
):
path
=
reverse
(
'api:v1:search-all-facets'
)
def
get_search_response
(
self
,
querystring
=
None
):
querystring
=
querystring
or
{}
qs
=
urllib
.
parse
.
urlencode
(
querystring
)
url
=
'{path}?{qs}'
.
format
(
path
=
self
.
path
,
qs
=
qs
)
return
self
.
client
.
get
(
url
)
...
...
@@ -297,6 +297,24 @@ class AggregateSearchViewSet(DefaultPartnerMixin, SerializationMixin, LoginMixin
self
.
assertListEqual
(
response_data
[
'objects'
][
'results'
],
[
self
.
serialize_course_run
(
course_run
),
self
.
serialize_program
(
program
)])
@ddt.data
(
'start'
,
'-start'
)
def
test_results_ordered_by_start_date
(
self
,
ordering
):
""" Verify the search results can be ordered by start date """
now
=
datetime
.
datetime
.
utcnow
()
archived
=
CourseRunFactory
(
course__partner
=
self
.
partner
,
start
=
now
-
datetime
.
timedelta
(
weeks
=
2
))
current
=
CourseRunFactory
(
course__partner
=
self
.
partner
,
start
=
now
-
datetime
.
timedelta
(
weeks
=
1
))
starting_soon
=
CourseRunFactory
(
course__partner
=
self
.
partner
,
start
=
now
+
datetime
.
timedelta
(
weeks
=
3
))
upcoming
=
CourseRunFactory
(
course__partner
=
self
.
partner
,
start
=
now
+
datetime
.
timedelta
(
weeks
=
4
))
course_run_keys
=
[
course_run
.
key
for
course_run
in
[
archived
,
current
,
starting_soon
,
upcoming
]]
response
=
self
.
get_search_response
({
"ordering"
:
ordering
})
self
.
assertEqual
(
response
.
status_code
,
200
)
self
.
assertEqual
(
response
.
data
[
'objects'
][
'count'
],
4
)
course_runs
=
CourseRun
.
objects
.
filter
(
key__in
=
course_run_keys
)
.
order_by
(
ordering
)
expected
=
[
self
.
serialize_course_run
(
course_run
)
for
course_run
in
course_runs
]
self
.
assertEqual
(
response
.
data
[
'objects'
][
'results'
],
expected
)
class
TypeaheadSearchViewTests
(
TypeaheadSerializationMixin
,
LoginMixin
,
ElasticsearchTestMixin
,
APITestCase
):
path
=
reverse
(
'api:v1:search-typeahead'
)
...
...
course_discovery/apps/api/v1/views/search.py
View file @
4608eef1
...
...
@@ -6,6 +6,7 @@ from haystack.query import SearchQuerySet
from
rest_framework
import
status
from
rest_framework.decorators
import
list_route
from
rest_framework.exceptions
import
ParseError
from
rest_framework.filters
import
OrderingFilter
from
rest_framework.permissions
import
IsAuthenticated
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
...
...
@@ -18,7 +19,9 @@ from course_discovery.apps.course_metadata.models import Course, CourseRun, Prog
class
BaseHaystackViewSet
(
FacetMixin
,
HaystackViewSet
):
document_uid_field
=
'key'
facet_filter_backends
=
[
filters
.
HaystackFacetFilterWithQueries
,
filters
.
HaystackFilter
]
facet_filter_backends
=
[
filters
.
HaystackFacetFilterWithQueries
,
filters
.
HaystackFilter
,
OrderingFilter
]
ordering_fields
=
(
'start'
,)
load_all
=
True
lookup_field
=
'key'
permission_classes
=
(
IsAuthenticated
,)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment