Skip to content

Commit

Permalink
Fixed sorting in v2 API
Browse files Browse the repository at this point in the history
  • Loading branch information
eidens committed Dec 8, 2023
1 parent b327b7d commit ae5bdf8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,17 @@ def papers_get(reviewed_by=None, query=None, page=None, per_page=None, sort_by=N
"""
lucene_query = _to_lucene_query(query) if query else None
db_page = page - 1 # neo4j pages are 0-indexed, page is checked for > 0 in param validation
db_sort_by = ({
"preprint-date": "preprint_date",
"reviewing-date": "review_date",
}).get(sort_by)
sort_ascending = sort_order == "asc"
db_params = dict(
reviewed_by=reviewed_by, # parameterized in database query, no need to escape
lucene_query=lucene_query, # user input is escaped in _to_lucene_query()
page=db_page, # converted from 1- to 0-indexed above
# remaining parameters are already validated and can be passed through
per_page=per_page,
sort_by=sort_by,
per_page=per_page, # already validated, and can be passed through
sort_by=db_sort_by,
sort_ascending=sort_ascending
)
result = ask_neo(REFEREED_PREPRINTS_V2(), **db_params)
Expand Down
2 changes: 1 addition & 1 deletion neoflask/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ class REFEREED_PREPRINTS_V2(Query):
'reviewed_by': {'req_param': 'reviewed_by', 'default': None},
'lucene_query': {'req_param': 'lucene_query', 'default': None},

'sort_by': {'req_param': 'sort_by', 'default': 'pub_date'},
'sort_by': {'req_param': 'sort_by', 'default': 'preprint_date'},
'sort_ascending': {'req_param': 'sort_ascending', 'default': False},

'page': {'req_param': 'page', 'default': 0},
Expand Down

0 comments on commit ae5bdf8

Please sign in to comment.