Skip to content

Commit

Permalink
Merge pull request #246 from oarepo/facet_groups_ref
Browse files Browse the repository at this point in the history
groups refactor
  • Loading branch information
Alzpeta authored Nov 29, 2023
2 parents 2f4c214 + d6f6f5b commit ed589ce
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
2 changes: 1 addition & 1 deletion oarepo_model_builder/datatypes/components/facets/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def process_facets(self, datatype, section, **__kwargs):
searchable=facet_section.get("searchable"),
imports=facet_section.get("imports", []),
facet=facet_section.get("facet", None),
facet_groups=facet_section.get("facet-groups", ["default"]),
facet_groups=facet_section.get("facet-groups", ["_default"]),
)

# set the field on the definition
Expand Down
6 changes: 3 additions & 3 deletions oarepo_model_builder/invenio/invenio_record_search_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ def finish(self, **extra_kwargs):
search_data = []
for f in facets:
for group in f.facet_groups:
if group != "default":
if group != "_default":
if group not in facet_groups.keys():
facet_groups[group] = {}
facet_groups[group][f.path] = "facets." + f.path
if group == "default":
default_group.append({f.path: "facets." + f.path})
if len(f.facet_groups) > 0:
default_group.append({f.path: "facets." + f.path})
search_data.append({f.path: "facets." + f.path})
if "sortable" in self.current_model.definition:
sort_options = self.current_model.definition["sortable"]
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = oarepo-model-builder
version = 4.0.69
version = 4.0.70
description = A utility library that generates OARepo required data model files from a JSON specification file
authors = Miroslav Bauer <[email protected]>, Miroslav Simek <[email protected]>
readme = README.md
Expand Down
67 changes: 67 additions & 0 deletions tests/test_search_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def test_sort():
data = builder.filesystem.open(
os.path.join("test", "services", "records", "search.py")
).read()
print(data)
assert strip_whitespaces(data) == strip_whitespaces(
"""
from invenio_records_resources.services import SearchOptions as InvenioSearchOptions
Expand All @@ -74,11 +75,20 @@ class TestSearchOptions(InvenioSearchOptions):
facets = {
'b': facets.b,
'c_d': facets.c_d,
**getattr(InvenioSearchOptions, 'facets', {})
}
sort_options = {
Expand Down Expand Up @@ -231,6 +241,14 @@ def test_facet_groups():
"type": "keyword",
"facets": {"searchable": True, "facet-groups": []},
},
"b2": {
"type": "keyword",
"facets": {"searchable": True},
},
"b3": {
"type": "keyword",
"facets": {"searchable": True, "facet-groups": ['default']},
},
"c": {
"type": "keyword",
"facets": {"searchable": True, "facet": False},
Expand Down Expand Up @@ -293,23 +311,72 @@ def test_facet_groups():
from flask_babelex import lazy_gettext as _
from . import facets
class TestSearchOptions(BaseSearchOptions):
\"""TestRecord search options.\"""
facet_groups ={
'curator': {
'a' : facets.a,
'g' : facets.g,
**getattr(BaseSearchOptions, 'facet_groups', {}).get('curator', {})
},
'user': {
'a' : facets.a,
**getattr(BaseSearchOptions, 'facet_groups', {}).get('user', {})
},
'default': {
'b3' : facets.b3,
**getattr(BaseSearchOptions, 'facet_groups', {}).get('default', {})
},
}
facets = {
'a': facets.a,
'arr_e_f': facets.arr_e_f,
'b2': facets.b2,
'b3': facets.b3,
'g': facets.g,
**getattr(BaseSearchOptions, 'facets', {})
}
""",
)
Expand Down

0 comments on commit ed589ce

Please sign in to comment.