brin sort in line with query structure
This commit is contained in:
parent
d24296df71
commit
d3c16d62b4
1 changed files with 14 additions and 11 deletions
|
@ -78,15 +78,9 @@ def api_error(request):
|
||||||
|
|
||||||
def _order_query(qs, sort, prefix='sort__'):
|
def _order_query(qs, sort, prefix='sort__'):
|
||||||
order_by = []
|
order_by = []
|
||||||
if isinstance(sort, basestring):
|
|
||||||
sort = [sort, ]
|
|
||||||
for e in sort:
|
for e in sort:
|
||||||
desc = ''
|
key = {'id': 'movieId'}.get(e['key'], e['key'])
|
||||||
if e.startswith('-'):
|
order = '%s%s%s' % (e['operator'], prefix, key)
|
||||||
e = e[1:]
|
|
||||||
desc = '-'
|
|
||||||
order = {'id': 'movieId'}.get(e, e)
|
|
||||||
order = '%s%s%s' % (desc, prefix, order)
|
|
||||||
order_by.append(order)
|
order_by.append(order)
|
||||||
if order_by:
|
if order_by:
|
||||||
qs = qs.order_by(*order_by)
|
qs = qs.order_by(*order_by)
|
||||||
|
@ -122,12 +116,21 @@ def _parse_query(data, user):
|
||||||
def api_find(request):
|
def api_find(request):
|
||||||
'''
|
'''
|
||||||
param data
|
param data
|
||||||
{'query': query, 'sort': string, 'range': array}
|
{'query': query, 'sort': array, 'range': array}
|
||||||
|
|
||||||
query: query object, more on query syntax at
|
query: query object, more on query syntax at
|
||||||
https://wiki.0x2620.org/wiki/0xdb2QuerySyntax
|
https://wiki.0x2620.org/wiki/0xdb2QuerySyntax
|
||||||
sort: string or arrays of keys; to sort key in descending order prefix with -
|
sort: array of key, operator dics
|
||||||
default: ['director', '-year']
|
[
|
||||||
|
{
|
||||||
|
key: "year",
|
||||||
|
operator: "-"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: "director",
|
||||||
|
operator: ""
|
||||||
|
}
|
||||||
|
]
|
||||||
range: result range, array [from, to]
|
range: result range, array [from, to]
|
||||||
keys: array of keys to return
|
keys: array of keys to return
|
||||||
group: group elements by, country, genre, director...
|
group: group elements by, country, genre, director...
|
||||||
|
|
Loading…
Reference in a new issue