Skip to content

Commit

Permalink
facets: fix facets with range query
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsherva committed Feb 21, 2024
1 parent 80b3f97 commit 1c6f02d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 7 deletions.
8 changes: 8 additions & 0 deletions invenio_app_ils/acquisition/mappings/os-v1/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 CERN.
#
# invenio-app-ils is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Acquisition ES mappings."""
8 changes: 8 additions & 0 deletions invenio_app_ils/acquisition/mappings/os-v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 CERN.
#
# invenio-app-ils is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Acquisition ES mappings."""
4 changes: 2 additions & 2 deletions invenio_app_ils/facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def inner(values):

return dsl.query.Bool(
[
dsl.RangeField(**{field: args}),
dsl.query.Range(**{field: args}),
dsl.Q(
"terms",
**{"state": current_app.config["CIRCULATION_STATES_LOAN_ACTIVE"]}
Expand Down Expand Up @@ -144,6 +144,6 @@ def inner(values):
input_date = str(arrow.get(values[0]).date())
except arrow.parser.ParserError:
raise ValueError("Input should be a date")
return dsl.RangeField(**{field: {comparator: input_date}})
return dsl.query.Range(**{field: {comparator: input_date}})

return inner
2 changes: 1 addition & 1 deletion invenio_app_ils/records/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from invenio_app_ils.permissions import backoffice_permission
from invenio_app_ils.records.permissions import RecordPermission
from invenio_app_ils.series.api import SERIES_PID_TYPE
from invenio_app_ils.signals import record_viewed, file_downloaded
from invenio_app_ils.signals import file_downloaded, record_viewed


def create_document_stats_blueprint(app):
Expand Down
8 changes: 4 additions & 4 deletions tests/api/ils/test_facets.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_current_ranged_loans_filter(app):
overdue = rfilter(["Overdue"])
field = {"lt": str(arrow.utcnow().date())}
assert overdue == dsl.query.Bool(
[dsl.RangeField(field=field), current_loans_query]
[dsl.query.Range(field=field), current_loans_query]
)

upcoming = rfilter(["Upcoming return"])
Expand All @@ -53,7 +53,7 @@ def test_current_ranged_loans_filter(app):
"lte": str((arrow.utcnow() + timedelta(days=7)).date()),
}
assert upcoming == dsl.query.Bool(
[dsl.RangeField(field=field), current_loans_query]
[dsl.query.Range(field=field), current_loans_query]
)


Expand All @@ -78,10 +78,10 @@ def test_date_range_filter(app):
to_filter = date_range_filter("field", "lte")

try:
assert from_filter([input_date]) == dsl.RangeField(
assert from_filter([input_date]) == dsl.query.Range(
field={"gte": input_date}
)
assert to_filter([input_date]) == dsl.RangeField(field={"lte": input_date})
assert to_filter([input_date]) == dsl.query.Range(field={"lte": input_date})
except (ValueError, AssertionError):
with pytest.raises(ValueError):
from_filter([input_date])
Expand Down

0 comments on commit 1c6f02d

Please sign in to comment.