-
Notifications
You must be signed in to change notification settings - Fork 25
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
documents: add more facets for documents search #2953
Conversation
f7eccfd
to
43af519
Compare
1b85862
to
98dd50a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As this task is a bit complexe it would be great to add comments. You can also put more details in you commit message. This commit add AND OR facets which are quite complex. Adding tests to check AND OR combinations can be a good added value: this can be done during the PO tests to save time.
@@ -1956,30 +1958,67 @@ def _(x): | |||
) | |||
) | |||
), | |||
subject=dict( | |||
subject_fiction=dict( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The facets fiction and no_fiction seems identical, facet fileter is missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filters are dynamically added using the function _facet_filter.
"""Create a filter DSL expression.""" | ||
filters = [] | ||
filters_group = {} | ||
for name, filter_factory in definitions.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments are welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @jma ; It's very complicated to understand how this method works. I will suggest a lot of comments, maybe with some exemple.
Additionally add docstring about method params.
q = Q('bool', should=filter_) | ||
s = s.query(q) | ||
|
||
if facet_name == 'subject_fiction': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dislike this approach: hard coding a facet filter name here: is it possible to create a facet filter here:
https://github.com/rero/rero-ils/pull/2953/files#diff-6be28a31924cc25a9c440ab46eedfa749b3b94ec7a6c5bb3021f76530ac95e4aL1959
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could explore the "filtered aggregation" : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
Something like :
"aggs": {
"subject_fiction": {
"filter": { "terms": { "genreForm.identifiedBy.value": ['A027757308', 'A021097366'] } },
"aggs": {
"subject": { "term": { "field": "facet_subjects" } }
}
},
"subject_no_fiction": {
"filter": { "not": { "terms": { "genreForm.identifiedBy.value": ['A027757308', 'A021097366'] } } },
"aggs": {
"subject": { "term": { "field": "facet_subjects" } }
}
}
}
Not tested, but I think it's a way to build you are expected. Additionally, some post_process serialization should be necessary to get "subject" into the main aggregation level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the OR filters defined in post_filters in the config.py file, each facet needs to be filtered to reflect the selection made by the user on other facets.
These filters are dynamically created by the function _facet_filter in the file facets.py and a nested aggregation is created in the function default_facets_factory before applying the filter.
The facets subject_fiction and subject_no_fiction have a filter independently of the other facets selection. These filters are added to the dynamically generated filters in the function _facet_filter.
This problem will be addressed in another PR.
@@ -565,8 +564,7 @@ | |||
"type": "object", | |||
"properties": { | |||
"value": { | |||
"type": "text", | |||
"index": false | |||
"type": "keyword" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This require a document reindexing. Please mention this in your commit message!
@@ -115,18 +115,28 @@ def post_process_serialize_search(self, results, pid_fetcher): | |||
|
|||
# Aggregations process | |||
if viewcode == global_view_code: | |||
aggregations = results.get('aggregations', {}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A small comment is welcome.
"""Create a filter DSL expression.""" | ||
filters = [] | ||
filters_group = {} | ||
for name, filter_factory in definitions.items(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As @jma ; It's very complicated to understand how this method works. I will suggest a lot of comments, maybe with some exemple.
Additionally add docstring about method params.
rero_ils/facets.py
Outdated
for v in values: | ||
urlkwargs.add(name, v) | ||
|
||
return (filters, filters_group, urlkwargs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
COSMETIC : parentheses aren't required ;-)
rero_ils/facets.py
Outdated
|
||
|
||
def _post_filter(search, urlkwargs, definitions): | ||
"""Ingest post filter in query.""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring for params
q = Q('bool', should=filter_) | ||
s = s.query(q) | ||
|
||
if facet_name == 'subject_fiction': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you could explore the "filtered aggregation" : https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-filter-aggregation.html
Something like :
"aggs": {
"subject_fiction": {
"filter": { "terms": { "genreForm.identifiedBy.value": ['A027757308', 'A021097366'] } },
"aggs": {
"subject": { "term": { "field": "facet_subjects" } }
}
},
"subject_no_fiction": {
"filter": { "not": { "terms": { "genreForm.identifiedBy.value": ['A027757308', 'A021097366'] } } },
"aggs": {
"subject": { "term": { "field": "facet_subjects" } }
}
}
}
Not tested, but I think it's a way to build you are expected. Additionally, some post_process serialization should be necessary to get "subject" into the main aggregation level.
rero_ils/config.py
Outdated
_('online'): online_or_terms_filter({ | ||
'electronicLocator.type': ['versionOfResource', 'resource'], | ||
'holdings_type': ['electronic'] | ||
}), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you indent?
f4fd1e6
to
9756ceb
Compare
PO testsGeneral
Online facet
Organisation public view
Other issues (not to be solved with the facets)
|
54bcc7b
to
eb16686
Compare
eb16686
to
52b916c
Compare
d531ace
to
c22d5de
Compare
* this commit requires documents re-indexing Co-Authored-by: Valeria Granata <valeria@chaw.com>
c22d5de
to
37bc84e
Compare
Co-Authored-by: Valeria Granata valeria@chaw.com
Why are you opening this PR?
Closes #2763
Dependencies
My PR depends on the following
rero-ils-ui
's PR(s):How to test
Please test:
Example: it is possible to select several values of Document type.
Note: an AND is applied between values of different facets.