Skip

X + !Y = X + Y
October 28, 2010 2:19 PM   Subscribe

In Drupal displays, "contains X" + "does not contain Y" is giving me X and Y. Help?

I'm having this problem in Drupal where things seem to be working in some strange way I don't understand. I'm sure I'm missing something, I just haven't been able to figure out what.

I have several displays on a view, set up identically except for the filter. This is what they're doing by filter:

"contains X": results contain X
"contains Y": results contain Y
"does not contain X": results do not contain X
"does not contain Y": results do not contain Y
"contains X" + "does not contain Y": results contain X and Y
"contains Y" + "does not contain X": results contain X and Y

I feel certain there is something--as there so often is with Drupal--that I've set up wrong without knowing how or why.

Leads and suggestions greatly appreciated.
posted by johnofjack to Technology (15 answers total)
 
Oh, and no, the filters are not set up to be case sensitive.
posted by johnofjack at 2:22 PM on October 28, 2010


Can you grab (if necessary, obfuscate the field names, etc) the query that shows up with a preview?
posted by epersonae at 2:28 PM on October 28, 2010


Sounds like an OR clause.
X OR !Y = both X and Y

Can you confirm that all returned entries contain X? Ignore Y for a second.
posted by unixrat at 2:31 PM on October 28, 2010


Sounds like it's probably doing a union of your search terms instead of an intersection. It's giving you all of the things that match "contains X" AND all of the things that match "does not contain Y".
If thats the case, the search results should contain items that:
Contain "X" and contain "Y" - matches "contains X"
Contain "X" and don't contain "Y" (the desired result) - matches both
Don't contain "X" and also don't contain "Y" - matches "does not contain Y"
Is that what's happening?

I don't know anything about drupal, but maybe that'll help with the googling. Are there operators other than "+" you can use? Maybe "&"?
posted by duckstab at 2:35 PM on October 28, 2010


Are both X and Y in the same field (node type, content, taxonomy term, whatever) or in two different fields? (I wouldn't think it would matter, but you never know.)
posted by epersonae at 2:38 PM on October 28, 2010


Bonus question: what version of Views?
posted by epersonae at 2:42 PM on October 28, 2010


the query

Yes, please supply the query and/or the full view export. Your current question isn't enough information to give you anything more than a guess as an answer.

Also, as awesome as AskMe is, this is a really specific technical question about a technology that has a huge friendly community of people available to help answer exactly this kind of question, so I'd strongly suggest taking the question to one of the many Drupal forums next time.
posted by scottreynen at 5:51 PM on October 28, 2010


The field names are standard. I've removed most of the SELECT AS statement because it's basically irrelevant to the problem.

SELECT DISTINCT(node.nid) AS nid,
[etc.]
FROM node node
LEFT JOIN term_node term_node ON node.vid = term_node.vid
LEFT JOIN term_data term_data ON term_node.tid = term_data.tid
LEFT JOIN content_field_image node_data_field_image ON node.vid = node_data_field_image.vid
INNER JOIN users users ON node.uid = users.uid
LEFT JOIN content_field_teaser node_data_field_teaser ON node.vid = node_data_field_teaser.vid
WHERE (UPPER(term_data.name) NOT LIKE UPPER('%Y%')) AND (UPPER(term_data.name) LIKE UPPER('%X%'))

X and Y are both taxonomy terms on the same item (my goal is to get 'X and Y' and 'X and not Y' in two different boxes on the same page). I've got the X as a pane input and the NOT Y as a filter. I've tried them both as filters but that didn't work either. I haven't found any way to use NOT Y as a pane input (it could save me creating another view, however much that matters).

Views version is 6.x-1.7 on the test server and (oddly enough) 6.x-1.6 on the live server.

Sorry, scottreynen, I should have thought of the Drupal community before AskMe, but for some reason didn't. Of course I can see how asking there would probably be better.
posted by johnofjack at 8:11 PM on October 28, 2010


I've got the X as a pane input

Had, briefly--didn't work. Put it back as a filter just to have case insensitive, not that it matters when it doesn't work anyway.
posted by johnofjack at 8:13 PM on October 28, 2010


Hm. I tried something like that on a test site I'm working on, and it did the same thing. (Views 6.x-2.11)
posted by epersonae at 9:30 AM on October 29, 2010


I did a quick browse of the Views queue and didn't see any likely answers. (Including scanning non-open issues) As a stab in the dark (!) you might try the Views Or module. And in any case, also try submitting an issue to the Views queue.
posted by epersonae at 9:51 AM on October 29, 2010


The problem is your !Y isn't removing all nodes with Y as a taxonomy term; it's only removing the terms that include Y. A node with Y as a term can still be selected if it has any other term that does not include Y.

You wrote earlier:

"does not contain Y": results do not contain Y

I'm skeptical this was actually excluding all nodes with term Y, as this seems to be impossible with the way the taxonomy filter works. What does that query look like?

I think what you'd need to do to get X && !Y to work is select all nodes that do contain Y, and then exclude that set from the results of those that contain X. According to the maintainer of Views, that's not possible in Views without writing some custom code. Basically, you'd run the Y view in code, get all the node IDs, and then pass those to an exclude argument of the X view to make it a X && !Y view. Not the easiest code to write.

A non-code solution would be to change X and Y from taxonomy terms to checkbox CCK fields. That would be more hassle to change the terms, but give you the filters you need in Views.
posted by scottreynen at 10:42 AM on October 30, 2010


Is there any chance that the Views Exclude Previous module would help you out here?
posted by kristi at 12:04 PM on October 30, 2010


That's interesting, scottreynen. I'll have to take a closer look at it at work and see if that is indeed the case (which, as you say, would mean that I've misunderstood how the "does not contain" filter works).

kristi, that's an interesting suggestion, too. Right now I'm limited in what I can do with Drupal--working with existing modules is definitely possible, but installing new modules is up to the discretion & generosity of someone else. But the feature I'm going after here is one that we definitely want, so it's possible that might be our solution.
posted by johnofjack at 8:28 PM on October 30, 2010


The problem is your !Y isn't removing all nodes with Y as a taxonomy term; it's only removing the terms that include Y. A node with Y as a term can still be selected if it has any other term that does not include Y.

scottreynen, you're right. I can see why I misunderstood it earlier, but this is indeed how it's working. For this filter to work to exclude nodes, it would require every node to have no more than one tag.

What I don't understand is why it's working like that. I can't imagine many likely scenarios in which this is useful--the point of tagging is that it's uncontrolled, and most people tend to tag with abandon (take a look at the tags people use on MeFi posts, or Flickr photos, etc. People want many access points to a piece of info, not just one).

At any rate: thanks for the clarification. I'll see what alternate solutions I can come up with.

Thanks for the suggestions, everyone!
posted by johnofjack at 8:55 AM on October 31, 2010


« Older Need advice on how to handle a...   |  A rather trying test of your g... Newer »
This thread is closed to new comments.


Post