Port Views Or to Views 3
catch - August 5, 2008 - 23:37
| Project: | Views |
| Version: | 6.x-3.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | duplicate |
| Issue tags: | OR |
Jump to:
Description
This was a planned feature of Views 2 which merlinofchaos hasn't had time to write - however if someone was to submit a decent patch for it, he'd likely commit such a patch. A quick look at your module suggests some code style issues (and you say yourself it's experimental) - but still, better in the queue against views where it can be integrated with the main project.

#1
FYI I'm interested in this feature. At this time it probably has to wait until after Views 2.0 to make it in, but I'd happily describe to you the UI I was looking for; a quick perusal of your code suggests you're using the underlying mechanisms that were meant for this.
The intended UI was meant to work like this:
Click on 'filters'; be presented with a select that sets the group-level conjunction (AND/OR), and the ability to add groups. Maybe add groups could also go on the rearrange page.
The rearrange page would use the tabledrag's hierarchy mechanism to let you simply drag filters from one group to another. This is a lot cleaner than using non-filter filters to separate groups. =)
#2
@catch : Hey, thanks for your interest. I agree this should be part of Views ! I was planning to ask for at least some of the required API to be added, once this was stable. In the mean time, it's easier to work on a module, with CVS, bug tracking, etc. It's harder to develop/collaborate on a patch queue. I'll submit an issue in Views 2 that points back to this module (and this issue.)
The UI suggested by merlinofcahos is quite differet (and better!) than mine, so in it's current form, this wouldn't work as a patch.
@merlinofchaos : Yes, your UI is much nicer ! I'm quite busy right now, and as soon as I have some free time I promissed I would finish porting the nodereferrer module to D6. But once that is done, if this isn't yet in Views, I'll be really happy to help with it.
For information, this is some of the problems I have encountered :
1. and 2. means that it's impossible to change either the clause or the group operators without changing the effect of some of the queries. The only way I could see around that was to clear (and store) all groups between each alternative, then let the modules add whatever they want in the groups/where clauses. Once they have done it, I compact it all (all the groups and where clauses) into one where clause ; which I can then easily insert back.
For 3. I change the joins to LEFT joins, and add an extra condition in the where clauses. That works on the ones I've tested...
#3
How does the INNER join mess up the OR clauses?
I understand how 1 and 2 do; 1 can be fixed by making sure modules that do this add all their items together when possible. Item 2 is a little bit more difficult to deal with.
There's also the problem that all arguments add their filters in the magic group 0, which was something I did just to get past the problem of "Er, what group to use?" when I should've used $this->group like I did with filters so that arguments could also join in the OR grouping.
Also, I'm ok with an imperfect solution. We can identify filters that will not work with OR grouping and document them on the filter itself -- we could even use a flag that the UI can look at so that it's very automatic and consistent.
#4
My understanding of an INNER join is that it only returns entries that have a matching record in both tables. This condition (that it must exist in both tables) applies to all parts of the query - regardless of the OR clauses.
Here is an example. Consider the following filters :
Taxonomy Term Id = CarrotOR
Published Date = now
This will generate the following query :
SELECT node.nid AS nidFROM node node
INNER JOIN term_node term_node ON node.vid = term_node.vid
WHERE (term_node.tid = 64) OR
(node.created = ***CURRENT_TIME***+0)
So this will return :
However, this will not return nodes that have a published date of NOW, and have no entries in the term_node table.
I have deal with this problem by rewritting this query as :
SELECT node.nid AS nidFROM node node
LEFT JOIN term_node term_node ON node.vid = term_node.vid
WHERE (term_node.tid = 64 AND term_node.vid IS NOT NULL) OR
(node.created = ***CURRENT_TIME***+0)
(though in that particular case it's not needed, as term_node.tid = 64 implies term_node.vid IS NOT NULL)
#5
Grouping?
This may be nice if there we can group multiple Conditions in AND OR NOT ??
#6
Has progress been made on this? Does Views 2 support OR now?
#7
I am currently doing a project that needs this feature (or some horrible kitten-killing hack). What is the current status? Is this in views2 yet? Is the code here usable against the current release of views2? Does this work with nodereferrer?
Thanks!
#8
@will_in_wi : I'm using Views Or on a production site with Views 2.1 and it works fine. As far as I know Views 2.2 didn't break backwards compatibility, so it should work fine.
I don't see why it wouldn't work with nodereferrer (I wrote the original D6 port of that one) but if it doesn't just report a bug and I'll have a look.
#9
+1
#10
subscribe
#11
+1
#12
For reference, the active issue for adding this functionality to Views is #118672: Adding sql ORing capability with filters.
#13
+1 Subscribe
#14
+ 1
#15
subscribing
#16
I have a suggestion: Simply have a user-defined logical operator between every filter, and the option to negate that filter (i.e. a logical "not").
Since filters can be re-ordered, every combination of groupings could be achieved. (You'd have to be familiar with De Morgan's laws, but it could be done.)
#17
+1
#18
+1
#19
subscribe
#20
Subscribing
#21
subscribe
#22
subscribe
#23
+1 Subscribe
#24
Great work so far... subscribing.
#25
Subscribing
#26
+1
#27
+1 Subscribe
#28
subscribe. Maybe will be better to create an issue on a Views2 module?
#29
There is one: #118672: Adding sql ORing capability with filters
#30
Subscribe.
#31
subscribe
#32
subscribe
#33
subscribe
#34
subscribe
#35
@Karlheinz #16 http://drupal.org/node/291660#comment-1800130
this sounds interesting. how would you do that?
#36
Whoops, you're right. It's been a while since I took logic. I thought between DeMorgan's Laws and the Distributivity Laws, there would be a way to get rid of groupings. But after working through it all, I realize I'm wrong.
For the curious, these are the laws I'm talking about:
x && (y || z) == (x && y) || (x && z)x || (y && z) == (x || y) && (x || z)
(!x) && (!y) == !(x || y)
(!x) || (!y) == !(x && y)
x || y == !((!x) && (!y))
#37
Subscribe
#38
I think this needs to hit the Views 3.0 queue in order to get exposure. This is definitely a necessary feature. Rebasing...
#39
Saw a previous mention of a previous feature request. Marking dupe.
#118672: Adding sql ORing capability with filters
#40
Yeah, none of the folks who work on Views are responsible for the views_or module, so I'm not sure moving this to the Views queue was a good idea.