eea.facetednavigation icon indicating copy to clipboard operation
eea.facetednavigation copied to clipboard

Multiple select widgets for the same index overwrite each other

Open dholth opened this issue 11 years ago • 3 comments

Multiple select widgets for the same index overwrite each other. The offending line is in .../browser/app/query.py: query.update(widget.query(kwargs))

For me it's much more useful if they AND rather than overwriting each other. For example, the following code iterates through every key in the new query. If it's also present in the old query it can convert it to a dictionary query with the 'and' operator, and concatenate the two together:

        def query_to_dict(a):
            if not isinstance(a, dict):
                if not isinstance(a, list):
                    a = [a]
                a = {'operator': 'and', 'query': a}
            return a

            new_terms = widget.query(kwargs)
            for term in new_terms:
                if term in query:
                    old_term = query_to_dict(query[term])
                    new_term = query_to_dict(new_terms[term])
                    new_term['query'] += old_term['query']
                    new_terms[term] = new_term
            query.update(new_terms)

dholth avatar Sep 04 '14 20:09 dholth

Yes. On the other hand we use this feature-o-bug to restrict the default query:

For example, you want to create a faceted navigable that displays only Pages, News and Events. But you still want to let the user to filter by portal_type:

  1. First widget for portal_type index is hidden with the default values selected (Page, News, Events)
  2. Second widget for portal_type is visible, counter enabled, hide zero value

This way this page displays by default only Pages, News and Events and still, the final user can filter between these types.

avoinea avatar Sep 05 '14 06:09 avoinea

Couldn't the AND behavior proposed by the OP be at least implemented as an option? I mean, there could be an option to configure whether the behaviour would be AND or replace.

I am trying to set up a nav page in which the user will choose "subject" from a widget, and "business process" from another one. Both classifications are implemented by using Tags, so the content editor would tag the item with a tag from a "subject" set and a tag from the "business process" set. I implemented vocabularies for both sets, so each of them could feed a Checkboxes or Tag cloud widget. But the user won't be able to filter by both sets at the same time, to see only the content items that are tagged as subject A AND business process X, for instance.

albieback avatar Apr 15 '15 21:04 albieback

Actually it does not work as expected for me. I have two widgets (a Checkboxes one and a Radio one) both on the same index in order to get a subset of choices so that user can only choose one of a,b,c on index I which also refers to d,e.

The resulting query (which should only contain one term) contains all the terms in an or condition. It means that whichever choice the user selects, the resultset is always the same.

Is that a different bug?

marfago avatar Apr 22 '15 10:04 marfago