Skip to content
Snippets Groups Projects
Commit be6d35b8 authored by jan.bednarik's avatar jan.bednarik
Browse files

Order search of Reports by newest date.

parent 4637f71c
Branches
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ def query_reports(query, paginator, *, highlight=False):
s = s.query('multi_match', query=query, fields=fields)
if highlight:
s = s.highlight(*fields, **HIGHLIGHT_PARAMS)
s = s.sort('-published')
s = s.sort('-date')
s = s[paginator.slice_from:paginator.slice_to]
return s.execute()
......@@ -26,6 +26,6 @@ def reports_by_author(author_id, paginator):
s = ReportDoc.search()
s = s.exclude('term', is_draft=True)
s = s.filter('term', author_id=author_id)
s = s.sort('-published')
s = s.sort('-date')
s = s[paginator.slice_from:paginator.slice_to]
return s.execute()
......@@ -42,8 +42,8 @@ reports = [
},
{
'id': 2,
'date': arrow.get(2018, 1, 5).datetime,
'published': arrow.get(2018, 1, 10).datetime,
'date': arrow.get(2018, 1, 3).datetime,
'published': arrow.get(2018, 1, 4).datetime,
'title': 'The Two Towers',
'body': 'Another long story.',
'received_benefit': 'Mithrill Jacket',
......@@ -54,8 +54,8 @@ reports = [
},
{
'id': 3,
'date': arrow.get(2018, 1, 7).datetime,
'published': arrow.get(2018, 1, 8).datetime,
'date': arrow.get(2018, 1, 5).datetime,
'published': arrow.get(2018, 1, 6).datetime,
'title': 'The Return of the King',
'body': 'Aragorn is the King. And we have lost the Ring.',
'received_benefit': '',
......@@ -65,8 +65,8 @@ reports = [
},
{
'id': 4,
'date': arrow.get(2018, 1, 9).datetime,
'published': arrow.get(2018, 1, 11).datetime,
'date': arrow.get(2018, 1, 7).datetime,
'published': arrow.get(2018, 1, 8).datetime,
'title': 'The Silmarillion',
'body': 'Not finished yet.',
'received_benefit': '',
......@@ -77,8 +77,8 @@ reports = [
},
{
'id': 5,
'date': arrow.get(2018, 1, 12).datetime,
'published': arrow.get(2018, 1, 13).datetime,
'date': arrow.get(2018, 1, 9).datetime,
'published': arrow.get(2018, 1, 10).datetime,
'title': 'The Hobbit',
'body': 'Work in progress...',
'received_benefit': '',
......
......@@ -197,14 +197,14 @@ snapshots['test_with_reports 1'] = {
'cursor': 'MQ==',
'node': {
'body': 'Another long story.',
'date': '2018-01-05 00:00:00+00:00',
'date': '2018-01-03 00:00:00+00:00',
'extra': '{"rings": 1}',
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
'ourParticipants': 'Frodo, Gimli, Legolas',
'providedBenefit': '',
'published': '2018-01-10 00:00:00+00:00',
'published': '2018-01-04 00:00:00+00:00',
'receivedBenefit': 'Mithrill Jacket',
'title': 'The Two Towers'
}
......@@ -228,14 +228,14 @@ snapshots['test_with_reports 1'] = {
'cursor': 'MQ==',
'node': {
'body': 'Aragorn is the King. And we have lost the Ring.',
'date': '2018-01-07 00:00:00+00:00',
'date': '2018-01-05 00:00:00+00:00',
'extra': None,
'id': 'UmVwb3J0OjM=',
'isDraft': False,
'otherParticipants': 'Sauron',
'ourParticipants': 'Aragorn',
'providedBenefit': 'The Ring',
'published': '2018-01-08 00:00:00+00:00',
'published': '2018-01-06 00:00:00+00:00',
'receivedBenefit': '',
'title': 'The Return of the King'
}
......
......@@ -19,13 +19,13 @@ snapshots['test_authenticated 1'] = {
'reportDrafts': [
{
'body': 'Not finished yet.',
'date': '2018-01-09 00:00:00+00:00',
'date': '2018-01-07 00:00:00+00:00',
'id': 'UmVwb3J0OjQ=',
'isDraft': True,
'otherParticipants': '',
'ourParticipants': '',
'providedBenefit': '',
'published': '2018-01-11 00:00:00+00:00',
'published': '2018-01-08 00:00:00+00:00',
'receivedBenefit': '',
'title': 'The Silmarillion'
}
......
......@@ -13,30 +13,6 @@ snapshots['test_all 1'] = {
'edges': [
{
'cursor': 'MQ==',
'node': {
'author': {
'extra': None,
'firstName': 'Spongebob',
'hasCollidingName': False,
'id': 'QXV0aG9yOjI=',
'lastName': 'Squarepants',
'totalReports': 1
},
'body': 'Another long story.',
'date': '2018-01-05 00:00:00+00:00',
'extra': '{"rings": 1}',
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
'ourParticipants': 'Frodo, Gimli, Legolas',
'providedBenefit': '',
'published': '2018-01-10 00:00:00+00:00',
'receivedBenefit': 'Mithrill Jacket',
'title': 'The Two Towers'
}
},
{
'cursor': 'Mg==',
'node': {
'author': {
'extra': '{"movies": 1}',
......@@ -47,18 +23,42 @@ snapshots['test_all 1'] = {
'totalReports': 2
},
'body': 'Aragorn is the King. And we have lost the Ring.',
'date': '2018-01-07 00:00:00+00:00',
'date': '2018-01-05 00:00:00+00:00',
'extra': None,
'id': 'UmVwb3J0OjM=',
'isDraft': False,
'otherParticipants': 'Sauron',
'ourParticipants': 'Aragorn',
'providedBenefit': 'The Ring',
'published': '2018-01-08 00:00:00+00:00',
'published': '2018-01-06 00:00:00+00:00',
'receivedBenefit': '',
'title': 'The Return of the King'
}
},
{
'cursor': 'Mg==',
'node': {
'author': {
'extra': None,
'firstName': 'Spongebob',
'hasCollidingName': False,
'id': 'QXV0aG9yOjI=',
'lastName': 'Squarepants',
'totalReports': 1
},
'body': 'Another long story.',
'date': '2018-01-03 00:00:00+00:00',
'extra': '{"rings": 1}',
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
'ourParticipants': 'Frodo, Gimli, Legolas',
'providedBenefit': '',
'published': '2018-01-04 00:00:00+00:00',
'receivedBenefit': 'Mithrill Jacket',
'title': 'The Two Towers'
}
},
{
'cursor': 'Mw==',
'node': {
......@@ -111,14 +111,14 @@ snapshots['test_query 1'] = {
'totalReports': 1
},
'body': 'Another long story.',
'date': '2018-01-05 00:00:00+00:00',
'date': '2018-01-03 00:00:00+00:00',
'extra': '{"rings": 1}',
'id': 'UmVwb3J0OjI=',
'isDraft': False,
'otherParticipants': 'Saruman, Sauron',
'ourParticipants': 'Frodo, Gimli, Legolas',
'providedBenefit': '',
'published': '2018-01-10 00:00:00+00:00',
'published': '2018-01-04 00:00:00+00:00',
'receivedBenefit': 'Mithrill Jacket',
'title': 'The Two Towers'
}
......@@ -145,14 +145,14 @@ snapshots['test_highlight 1'] = {
'totalReports': 2
},
'body': 'Aragorn is the King. And we have lost the <mark>Ring</mark>.',
'date': '2018-01-07 00:00:00+00:00',
'date': '2018-01-05 00:00:00+00:00',
'extra': None,
'id': 'UmVwb3J0OjM=',
'isDraft': False,
'otherParticipants': 'Sauron',
'ourParticipants': 'Aragorn',
'providedBenefit': 'The <mark>Ring</mark>',
'published': '2018-01-08 00:00:00+00:00',
'published': '2018-01-06 00:00:00+00:00',
'receivedBenefit': '',
'title': 'The Return of the King'
}
......@@ -194,8 +194,8 @@ snapshots['test_first 1'] = {
{
'cursor': 'MQ==',
'node': {
'id': 'UmVwb3J0OjI=',
'title': 'The Two Towers'
'id': 'UmVwb3J0OjM=',
'title': 'The Return of the King'
}
}
],
......@@ -217,8 +217,8 @@ snapshots['test_first_after 1'] = {
{
'cursor': 'Mg==',
'node': {
'id': 'UmVwb3J0OjM=',
'title': 'The Return of the King'
'id': 'UmVwb3J0OjI=',
'title': 'The Two Towers'
}
}
],
......@@ -257,8 +257,8 @@ snapshots['test_last_before 1'] = {
{
'cursor': 'Mg==',
'node': {
'id': 'UmVwb3J0OjM=',
'title': 'The Return of the King'
'id': 'UmVwb3J0OjI=',
'title': 'The Two Towers'
}
}
],
......
......@@ -10,8 +10,8 @@ pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')]
@pytest.mark.parametrize('query, expected_ids', [
('', [2, 3, 1]),
('sauron', [2, 3]),
('', [3, 2, 1]),
('sauron', [3, 2]),
('towers', [2]),
('Aragorn Gandalf', [3, 1]),
])
......@@ -33,8 +33,8 @@ def test_query_reports__highlight():
@pytest.mark.parametrize('first, after, expected_ids', [
(2, None, [2, 3]),
(2, encode_cursor(1), [3, 1]),
(2, None, [3, 2]),
(2, encode_cursor(1), [2, 1]),
])
def test_query_reports__pagination(first, after, expected_ids):
prepare_reports()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment