The options when using filter by "Taxonomy: Term" or "Taxonomy: Terms for VOCAB_NAME" include "is all of", "in one of" and "is none of". I'm trying to use "is none of" to hide some nodes from my view, but it's not working.
For simplicity, let's say my taxonomy is called "privacy" and it has one term "hidden". I set up my filter for "is none of" term "hidden".
The resulting query looks like:
SELECT node.title, node.nid, count(node.nid) as num_nodes FROM node node LEFT JOIN term_node term_node ON node.nid = term_node.nid WHERE (node.type IN ('ocp_project')) AND (!(term_node.tid = '1025')) GROUP BY node.nid LIMIT 0, 5
Where the join with term_node and the where (!(term_node.tid = '1025')) come from the filter.
The reason it does not work is because my nodes have other terms, from other vocabularies associated with them. So even the nodes with tid 1025 ("hidden") associated with them are returned by this query. The query would only work if all nodes have exactly one term set from exactly one vocabulary.
The query that should be generated would be more complex, joining both term_data and term_node, aliasing them to be term_data_VID and term_node_VID. And somehow fitering out where term_node_VID.tid=1025, while allowing nodes with other values from VID, or no values from VID. (where VID is the vid of my "privacy" vocabulary). I'm not sure exactly what that query looks like. It may be difficult to express in SQL and even more difficult to express in the views data structures.
| Comment | File | Size | Author |
|---|---|---|---|
| #13 | views_taxonomy_with_depth.patch.txt | 4.76 KB | fago |
| #10 | views_tax_NOR.patch.txt | 9 KB | fago |
Comments
Comment #1
fagoi would say its the other way round - it works if your nodes have another term, else it doesn't.
so this seems to be a duplicate of this issue I created recently.
please test the patch from this issue and report if it fixes your problem too.
Comment #2
Dave Cohen commentedI don't think its a duplicate. Your code affects queries which get a NOT IN clause, my query gets a (!(node_term.tid = '1025')) clause.
I'm trying to filter out all nodes with term '1025' set. Instead I get is all nodes that have any term other than 1025 set - even if they also have 1025 set. So some nodes with 1025 set are not excluded, and that's a problem.
Comment #3
ricmadeira commentedHell, I'm getting this error too. Using "Is None Of" does nothing for me, and yes, the items I'm trying to exclude have terms in other vocabularies.
BTW... how can I find out what my view's resulting query looks like?
Comment #4
ricmadeira commentedI tried the patch fago made for the other issue, BTW, and as yogadex predicted, it did nothing to fix this problem.
Comment #5
Dave Cohen commentedTo find out what the resulting query looks like use the devel module and enable the query log.
Comment #6
merlinofchaos commentedYesterday I put in a fix that might fix the exclusion issue.
Comment #7
Dave Cohen commentedMerlin, in case the fix you refer to is http://drupal.org/node/74505, that's not the same problem. At least I don't think it is.
Comment #8
fagoI agree, this is still not working correctly.
I can take a look on this during the next days.
Comment #9
monkeythug commentedHi,
I don't want to teach grandma to suck eggs - but that SQL looks completely wrong to me. Surely it should look something like :
SELECT node.title, node.nid, count(node.nid) as num_nodes FROM node node
WHERE (node.type IN ('ocp_project'))
AND NOT EXISTS
(
SELECT 1
FROM term_node
WHERE term_node.nid = node.nid
AND term_node.tid = '1025'
)
GROUP BY node.nid LIMIT 0, 5
Of course I have no idea how to get the code to generate this ... :-)
Cheers
David.
Comment #10
fagoattached a patch, whitch should fix it. please test
I removed the option of "depth", because I can't see any use for it. If we already filter for term ids, what should the additional depth setting do? Any term id has a fixed depth generated by it's position in the tree, so what should this additional depth filter do!?
Or is there any use case I missed?
Comment #11
merlinofchaos commentedViews doesn't do sub-selects.
Comment #12
merlinofchaos commentedNo, the depth option is very important.
If I have a taxonomy hierarchy that looks something like this:
plants -->
flowers -->
petunias
marigolds
dandilions
trees
oak
maple
And I want to get all 'trees' I can search for 'tree' with a depth of 1; then anything with 'oak' or 'maple' will get hit. (Yes, this is probably going to suck when using exclusion).
In this case, depth really means 'find any node with term tree, or any node with a term that is 1 step down from tree'.
Comment #13
fagoah right, a really useful feature.
Here is a new patch which keeps the depth option. However there is still no support for using the depth option with the NOR operator, because this is not possible without doing subqueries.
please test :)
Comment #14
merlinofchaos commentedSeems to work. Thanks for the fix!
Comment #15
harry slaughteradding depth exclusion does not fix the original problem outlined this issue, right?
Comment #16
merlinofchaos commenteddepth exclusion isn't implemented. It's quite difficult to accomplish.
Comment #17
harry slaughtersorry, i'm lost. patch above suggest depth exclusion existed or was implemented in the patch.
depth exclusion was not the original point of this (fixed) issue, and that's what i'm asking about.
if you create a view that includes a filter of 'is none of [vocab]', it simply won't exclude content that has additional vocab applied to it. i understand that views does not support sub-selects, but i was wondering if there were some other way to achieve the goal of completely excluding nodes with tags from a certain vocab.
i think the author of this post would be interested too.
i'm reviewing http://drupal.org/node/42609 to see if i can achieve this within a module that uses the views api, but it seems like i'm limited to small fragments of queries and can't insert a subselect "manually".
hrmmm...
Comment #18
fagoI thought about the vocabulary & NOR filter, when I wrote this patch. But I wasn't able to find a way to do it without subqueries. If you can think of an sql statement which does it, post it..
So the NOR filter with vocabulary is not totally correct. NOR and depth filtering is also not possible without subqueries.
Comment #19
(not verified) commented