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

Multiple select widgets for the same index overwrite each other #53

Open
dholth opened this issue Sep 4, 2014 · 3 comments
Open

Multiple select widgets for the same index overwrite each other #53

dholth opened this issue Sep 4, 2014 · 3 comments

Comments

@dholth
Copy link

dholth commented Sep 4, 2014

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)
@avoinea
Copy link
Member

avoinea commented Sep 5, 2014

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.

@albieback
Copy link

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.

@marfago
Copy link

marfago commented Apr 22, 2015

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?

avoinea added a commit that referenced this issue Dec 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants