Problem/Motivation
It would be really nice if we can do queries like this:
http://example.com/node.json&field_tags=12,16 (to get nodes tagged with term id 12 OR 16)
http://example.com/node.json&field_tags=12+16 (to get nodes tagged with term id 12 AND 16)
For instance, ContribKanban wanted to say "With tags `accessibility` AND `SprintWeekend2017`". However passing both tids does not accomplish the needs.
For d8rules it would make sense to list both
- issues with the d8rules tag globally https://www.drupal.org/project/issues/search/?issue_tags=d8rules
- issues which are in the Rules repository https://www.drupal.org/project/issues/search/rules?version%5B%5D=8.x
Show all the critical, needs review|needs work|active|rtbc|etc. issues for drupal 8.0.x
Show all the critical, rtbc issues for drupal 8.0.x that are in tag "D8 upgrade path" but not "Needs critical triage"
It is possible to use multiple values for a query filter.
OR
?id[]=1&?id=[] works for an OR
using
?property[]=VALUE
?field_name[column][]=VALUE
Example: https://www.drupal.org/api-d7/taxonomy_term.json?tid[]=25130&tid[]=26976
Example: 10 nodes that have high priority https://www.drupal.org/api-d7/node.json?field_issue_priority[value][]=10...
AND
Proposed resolution
From GitHub's API to query a repo's issues - https://developer.github.com/v3/issues/. Their API uses "," as an AND operator for querying issues via labels.
Remaining tasks
Figure out what some common standard patterns are.
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | make_or_and_and_queries-2308939-12.patch | 5.27 KB | mglaman |
| #12 | interdiff-2308939-12-6.txt | 1.47 KB | mglaman |
| #6 | make_or_and_and_queries-2308939-6.patch | 5.27 KB | mglaman |
Comments
Comment #1
webchickAgreed that this would be extremely useful. I've been playing around with some of the sample queries at https://www.drupal.org/api and as far as I can tell, there's no way to do things like:
Show all the critical, needs review|needs work|active|rtbc|etc. issues for drupal 8.0.x
Show all the critical, rtbc issues for drupal 8.0.x that are in tag "D8 upgrade path" but not "Needs critical triage"
Comment #2
mglamanYes, I would love it to be TID+TID+TID or using pipes (|). It would allow Contrib Kanban (http://contribkanban.com/) to cut down it's request. Each list is its own configuration, and multiple status IDs. This causes it to have to make a request for each status to get a decent amount of data.
Comment #3
drummComment #4
mglamanAfter doing some poking, I don't think we can use "+" as a determinate, because that is a valid character - https://www.drupal.org/api-d7/taxonomy_term.json?name=Imagefield_CSS+Panels. And the endpoint doesn't care what kind of data a field is (at brief glance at code, haven't actually tested so pardon if incorrect.)
It seems like using commas is proper approach. The autocomplete module uses it as a determinate, as noted from taxonomy_autocomplete()'s documentation
Comment #5
mglamanHighlighting a piece of code in the module when handling field conditions
The following was added through #1707938: Querying filters: specify the field column. Allows fields to be queried for non-normalized table columns. Problem is.. if an value is converted to an array before this, it would break fields
Comment #6
mglamanHere is a patch which adds support to both AND and OR requests. AND is specified using commas and OR is specified via pipes. I've updated tests as well.
Example:
http://restws.contrib.dev/node.json?nid=10|3 would return nodes 10 and 3.
http://restws.contrib.dev/node.json?field_tags=5,22 would return nodes with tag references to term id 5 and 22.
Comment #7
marcvangendAre there other places in Drupal where multiple values are separated by AND / OR operator characters? I can think of one: Views contextual filters. According to https://www.drupal.org/node/1578564:
(Yes, that's the opposite of my initial feature request :-))
Let's look for some kind of standard for value separators, either in Drupal core/contrib or elsewhere, and use that.
Comment #8
mglamanmarcvangend, I had wanted to use plus signs to denote "OR". However, with string based requests I was afraid of complications - see example in #4. I agree keeping to "," for AND and "+" for OR would be best. Let me try fiddling some more :) Thanks for taking a look.
Comment #9
webchickI'd encourage us to look 'up a level' and see what's common in REST frameworks out there, since that's what we're attempting to emulate.
Comment #10
mglamanFrom GitHub's API to query a repo's issues - https://developer.github.com/v3/issues/. Their API uses "," as an AND operator for querying issues via labels. Unfortunately I didn't see anything in relation to OR.
Comment #11
dasjoNot sure if that would support it, but for d8rules it would make sense to list both
- issues with the d8rules tag globally https://www.drupal.org/project/issues/search/?issue_tags=d8rules
- issues which are in the Rules repository https://www.drupal.org/project/issues/search/rules?version%5B%5D=8.x
Comment #12
mglamanRe-rolled #6 to use Views-like + for OR and , for AND
Comment #14
btopro commentedtested last patch didn't seem to do anything when I issue a call like
node.xml?nid=12+13This is the proposed usage pattern correct?
Comment #15
mglamanI need to revisit my patch. My note in #12 is flip-flopped from summary. Maybe I did in my code too. Which explains test fail.
Comment #16
xeraseth commentedA few notes:
?id[]=1&id[]=2. I went to start writing a patch to do the "OR" value as this format and to my surprise this format works already.Comment #17
mglamanCan confirm,
?id[]=1&?id=[]works for an OR! See https://www.drupal.org/api-d7/taxonomy_term.json?tid[]=25130&tid[]=26976Awesome find, and simplifies ContribKanban.com's requests. A LOT.
Comment #18
mglamanit appears []= only works on property conditions, and throws a 500 when its a field condition :/ requesting mutliple IDs works, however something like the following errors out: https://www.drupal.org/api-d7/node.json?limit=100&type=project_issue&fie...
Comment #19
btopro commentedWOAH, matt, you just totally blew my mind! Can confirm this works with fields too so long as you supply the array value.
example:
node.json?field_name_here[value][]=stuff&field_name_here[value][]=thingsComment #20
btopro commented10 nodes that have high priority
https://www.drupal.org/api-d7/node.json?field_issue_priority[value][]=100&limit=10Comment #21
mglamanProof this is working using what btopro found: https://contribkanban.com/board/panelizer
Each lane is using OR for the possible statuses to display.
Comment #22
lokapujyaDoes D8 do this?
Comment #23
mglamanChanging the title here, since we discovered OR is possible via array values as
?property[]=VALUEor?field_name[column][]=VALUE. However there's no way to make this an AND query.For instance, for ContribKanban I wanted to say "With tags `accessibility` AND `SprintWeekend2017`". However passing both tids does not accomplish the needs.
Comment #24
yesct commented@mglaman so the tests in the patch include both an and and or test?
If a test only patch ran, do you think the or case would pass?
Someone please check the issue summary update.