Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Added REST endpoint for search
Browse files Browse the repository at this point in the history
  • Loading branch information
George Schneeloch committed Sep 4, 2015
1 parent 39513df commit 25dd1d2
Show file tree
Hide file tree
Showing 5 changed files with 568 additions and 0 deletions.
78 changes: 78 additions & 0 deletions apiary.apib
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,84 @@ Create a repository by providing its JSON representation.
"create_date": "2015-06-22"
}

## Group SearchResults

## SearchResult Collection [/repositories/{repo_slug}/search/{?q,sortby,selected_facets}]

+ Parameters
+ repo_slug: `physics-1` (string, required) - slug for the repository
+ q: `zebra` (string, optional) - a piece of text to search with. If this is blank or omitted all results will be returned.
+ sortby: `nr_views` (string, optional) - a column to sort results by. This is descending by default, add prefix '-' to sort in ascending order. May be one of: nr_views, nr_attempts, avg_grade.
+ selected_facets: `course:DemoX` (string, optional) - a facet to narrow searches. Param may be specified more than once to narrow on multiple facets.

### List SearchResults [GET]

+ Response 200 (application/json)

+ Body

{
"count": 1,
"next": null,
"previous": null,
"results": [
{
"resource_type": "discussion",
"course": "DemoX",
"run": "Demo_Course",
"xa_nr_views": 12,
"xa_nr_attempts": 1,
"xa_avg_grade": 4.0,
"lid": 91,
"title": "Peer Grading",
"description": "",
"description_path": "...",
"preview_url": "..."
}
],
"facet_counts": {
"course": {
"facet": {
"key": "course",
"label": "Course"
},
"values": [
{
"count": 1,
"key": "DemoX",
"label": "DemoX"
}
]
},
"run": {
"facet": {
"key": "run",
"label": "Run"
},
"values": [
{
"count": 1,
"key": "Demo_Course",
"label": "Demo_Course"
}
]
},
"resource_type": {
"facet": {
"key": "resource_type",
"label": "Item Type"
},
"values": [
{
"count": 1,
"key": "discussion",
"label": "discussion"
}
]
}
}
}

## Group LearningResources

## LearningResource Collection [/repositories/{repo_slug}/learning_resources/{?type_name}]
Expand Down
16 changes: 16 additions & 0 deletions rest/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
FileField,
SerializerMethodField,
IntegerField,
FloatField,
)

from rest.util import LambdaDefault, RequiredBooleanField
Expand Down Expand Up @@ -289,3 +290,18 @@ class LearningResourceExportTaskSerializer(Serializer):
id = CharField()
status = CharField()
url = CharField()


class RepositorySearchSerializer(Serializer):
"""Serializer for search metadata."""
resource_type = CharField()
course = CharField()
run = CharField()
xa_nr_views = IntegerField(source="nr_views")
xa_nr_attempts = IntegerField(source="nr_attempts")
xa_avg_grade = FloatField(source="avg_grade")
lid = IntegerField()
title = CharField()
description = CharField()
description_path = CharField()
preview_url = CharField()
Loading

0 comments on commit 25dd1d2

Please sign in to comment.