Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

facets: provide CombinedTermsFacet to fix #798 [+] #549

Conversation

fenekku
Copy link
Contributor

@fenekku fenekku commented Nov 27, 2023

This approach doesn't use 'nested' fields, but instead relies on a
field containing <parent><split char><child> to aggregate correctly.

label=_('Resource types'),
value_labels=VocabularyL10NLabels(current_service)
),
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just repeated docstring - cleaning up 🧹

@@ -149,7 +144,7 @@ def _parse_values(self, filter_values):
.. code-block:: python

{
'publication': ['publication::book', 'publication::journal'],
'publication': ['book', 'journal'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually what this function does.

@@ -246,6 +239,211 @@ def get_labelled_values(
return ret_val


class CombinedTermsFacet(NestedTermsFacet):
"""
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best place to explain more complex things and reasoning behind approaches is in the code itself so I placed the explainer here.

Comment on lines +328 to +339
def get_parents(self):
"""Return parents.

We have to delay getting the parents since it may require an application
context.
"""
if not self._cached_parents:
if callable(self._parents):
self._cached_parents = self._parents()
else:
self._cached_parents = self._parents
return self._cached_parents
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tradeoff here was in favor of simplicity of "caching". The parents are computed once, so a restart of the application is needed if new subjects are installed. Maybe this can be documented somewhere, if so where?

@@ -303,3 +248,100 @@ def test_facets_post_filtering(app, service, identity_simple, records):
# Test hits are filtered
assert 1 == len(res)
assert set(["001"]) == set([h["metadata"]["title"] for h in res])


def test_combined_terms_facets(app, service, identity_simple, search_clear):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test other combination of scheme+subject than in resource test to be thorough.

@fenekku fenekku removed the request for review from rekt-hard December 1, 2023 13:13
@fenekku fenekku force-pushed the 798_incorrect_nested_aggregations_option_2 branch from 8a2d045 to 6624851 Compare December 1, 2023 21:16
@fenekku fenekku force-pushed the 798_incorrect_nested_aggregations_option_2 branch from 6624851 to d389762 Compare December 18, 2023 19:21
This approach doesn't use 'nested' fields, but instead relies on a
field containing <parent><split char><child> to aggregate correctly.
@fenekku fenekku force-pushed the 798_incorrect_nested_aggregations_option_2 branch from d389762 to 1d370c4 Compare March 19, 2024 20:28
@fenekku
Copy link
Contributor Author

fenekku commented Mar 19, 2024

the mergening has started

@fenekku fenekku merged commit ea4b1b1 into inveniosoftware:master Mar 19, 2024
12 checks passed
@fenekku fenekku deleted the 798_incorrect_nested_aggregations_option_2 branch March 19, 2024 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: To release 🔧
Development

Successfully merging this pull request may close these issues.

2 participants