Hello! First of all: Thanks for the great module! It's a great help and saves a lot of SQL hacking, great!
Today I experimented with this module and had a look at the generated SQL statements. As it seems, arguments I add to a view are interpreted in an additive way resulting the SQL having the according filtering statements connected with 'AND' in its WHERE-part. It is not possible to conjunct arguments in an disjunctive way, which would be reflected with 'OR' conjunctions in the resulting SQL query.
Example: Let's say i want to filter after two arguments, the first giving the user name and the second some taxonomy term name: A request like somehost/Clint/Drupal will be reflected in the SQL statement like:
...
WHERE
(users.name = 'Clint') AND
(term_data.name = 'Drupal')
If I now want to filter with another third taxonomy term argument, an appropriate query like somehost/Clint/Drupal/Cms should be interpreted as:
...
WHERE
(users.name = 'Clint') AND
(term_data.name = 'Drupal' OR
term_data.name = 'Cms')
But as all arguments are connected with 'ADD', in the moment it will result in a useless SQL query:
...
WHERE
(users.name = 'Clint') AND
(term_data.name = 'Drupal') AND
(term_data.name = 'Cms')
Thus, I propose the introduction of a way to apply arguments in a disjunctive way (OR). Maybe it is possible to bundle arguments of the same type into an OR-group. Seems like a natural fit for me, because (at least in my example) it makes no sense to filter the same argument type twice in an additive way: (term_data.name = 'Drupal') AND (term_data.name = 'Cms') is a pointless request.
Comments
Comment #1
mfredrickson commentedSee also http://en.wikipedia.org/wiki/Conjunctive_normal_form for a formal write up on what you're proposing. I'd like to see this.
To do so, we'd probably have to change the view's object, such that filters are grouped, instead of being a flat list. Also, we'd need UI changes to add the filter groups. Finally, there would be the problem of exposed filters. From a data perspective, exposed filters would be fairly simple, but from a UI perspective, it could be very confusing. For example, if I had a view with the filter groups
It could be very confusing to have two sets of terms. Moreover - what I always wanted those taxonomy terms linked (i.e. the say terms selected in each OR group).
This is a good idea, but I think we should spend a little time specing out exactly how the system behaves before charging ahead. :-)
Comment #2
henmue commentedYeah, the form should correspond to CNF. I did not want to mention the conjunctive normal form, because boolean logic is a bit far-fetched, but what the heck! No worries. :-)
From the perspective of flexibility, a full reproduction of SQLs abilities would be best. That is, as you pointed out, a little more complicated as the current AND-conjunction of arguments. That's why I thought of the automism of bundling arguments of the same type, I think an AND-conjunction is of no use in this case.
If you want to go all out and implement arbitrary "conjunctive normal forms", I see two possibilities. The first is to change the whole GUI accordingly, which is a bit much for my taste. The second option which comes to my mind is some kind of composition instruction. If your had four arbitrary arguments you could state in a single line something like
that your arguments shall be interpreted like
That could keep the GUI as is but provide the whole flexibility.
Comment #3
catchDid this make it into Views 2?
Comment #4
lokisapocalypse commentedI agree that this would be a very useful feature and would like to see it be a part of views. I don't believe it should replace AND but allow users to choose.
Comment #5
scottrigby@lokisapocalypse: new features will go into 6.x first.
@catch not yet :p -- but from a conversation with merlinofchaos on IRC it looks like this feature will only happen after we can do the same thing with filters.
Here's a link to the filters issue help keep track of the status #118672: Adding sql ORing capability with filters
Also marking #334883: Extending the WHERE clause in argument handling code as duplicate of this issue.
Comment #6
catchThere's also http://drupal.org/project/views_or
and #291660: Patch to views instead of a module?
Comment #7
scottrigby@catch: right - Though sadly, from what merlinofchaos said at #3 in that issue and clarified today - Arguments didn't get the underlying structure filters did to support grouping :( so it looks like views_or module will only work for filters in the meantime but not yet for arguments.
Unless there's some other way to do this using arguments currently -- I mean, if you know about any provisional method for doing this? i'd love to try it out -- I don't have any other leads on ORing arguments :p
Comment #8
emi_bcn commented+1
Comment #9
henmue commented@all
Hi! Never thought that this issue would live for so long... :o)
I had no time to try it out, but the views_or module descrition states that it can handle arguments as well.
Regards Henry
Comment #10
murzSubscribe
Comment #11
entrigan commentedComment #12
zeppie commentedsubscribe,
Rearranging filters works perfectly!! a simular UI for arguments would be be great!! (or am I missing something and is this already possible? )
Comment #13
not_Dries_Buytaert commentedBTW: The module suggested in post #6 (6.x-1.x-dev d.d. 2010-Jul-11: http://drupal.org/node/289567) seems to work also for arguments (not only filters).
An example SQL-statement WITHOUT the module installed, enabled and configured (i.e. AND-ing):
The same SQL-statement WITH the module installed, enabled and configured (i.e. OR-ing):
So, only the JOIN and WHERE parts differ. I doubt whether the JOIN part should have changed from an inner to a left outer. So, I don't know whether the suggested module would be a safe workaround for this issue.
Comment #14
esmerel commentedViews or is already part of views 3. #118672: Adding sql ORing capability with filters
Comment #15
entrigan commentedThat is for ORing filters. This issue is about arguments.
Comment #16
merlinofchaos commentedThat is correct. However, I'm sorry to say that I am not going to consider applying OR to arguments at this time. The complexity of doing so is vast and I am not sure we can ever do it properly without a serious redesign of how arguments and filters interact.
Comment #17
danmuzyka commentedIn case anyone else out there is using Views 6.x-3.x and trying to OR together arguments, here is the workaround that our team implemented.
Our use case was to create a view listing books that were either written, illustrated, edited, etc. by a given person. We had a content type 'book' and a content type 'contributor.' 'Book' type nodes had several nodereference fields that could point to nodes of type 'contributor.' These nodereference fields included: author, editor, illustrator, photographer, translator, etc. Our goal was to pass in one nid to the view, and to show all book nodes where that nid appeared in at least one of those nodereference fields.
Here is how we did it using Views 6.x-3.x and a simple views hook function. First, we created a view with a
Global: Nullargument. Then we set up filters corresponding to what we wanted to use as arguments. In our case, these wereContent: Author,Content: Editor,Content: Illustrator,Content: Photographer, andContent: Translator. We didn't select any nodes from theis one oflist, so in the Filters list for the view they all ended in the 'Unknown.'Next, we changed the
Use groupingsetting underAdvanced settingstoYes, grouped together the nodereference field filters, and set theGroup OperatortoOR. Finally, we usedhook_views_pre_build()in a custom module to assign the value of theGlobal: Nullargument to the filter fields:This relatively simple approach worked!
Comment #18
seandunaway commentedGreat thinking and thanks for sharing danmuzyka! This works great with content fields but for some reason taxonomy are 'ungroupable'.
Comment #19
leelooch commentedThanks danmuzyka for this workaround.
How do you solve the "No valid values found on filter" error that prevents from saving the view because of the filter values set to "unknown" ?
Update : It's OK, I found my own workaround by putting Node: Nid filters on relationships and assigning the value of arg[0] to fields that look like : $view->filter['nid']->value['value'] ($dpm($view); to see what it looks like)
thanks again !