The services_resource_build_index_query() function currently limits us to only using an IN condition when building the query to index entities. It would be extremely useful to be able to (optionally) customize this condition for each field in the $parameters array.
For example, if we could use a LIKE condition on the title field for nodes, we could easily power autocomplete widgets in an application. For example, searching for article nodes that have "hello" in the title could be done with this proposed argument structure for the index resource(s):
?q=endpoint/node.json&fields=nid,title¶meters[title]=%25hello%25¶meters[type]=article¶meters_op[title]=like
Patch to come...
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | index_conditions-2403645-16.patch | 7.24 KB | tyler.frankenstein |
Comments
Comment #1
tyler.frankenstein commentedIf this looks reasonable, the patch could easily be expanded to support all core entity types, and not just the node entity type. Please confirm, thanks.
Comment #2
kylebrowning commentedHey Tyler!
This looks great, but it also needs tests. Can you copy and paste the node index test and change it tot support this new param?
Comment #3
tyler.frankenstein commentedAdded test.
Comment #5
marcingy commentedFrom a code prospective looks nice so plus 1 from me
Comment #6
kylebrowning commentedI should have been a bit more clear, the test needs to actually assert that the response returns LIKEness, not just the same test that node index does with the new parameter in place.
Comment #7
tyler.frankenstein commentedAttached patch adds this exact same feature but for the taxonomy term index resource also. Removing tests (from #3) for now, since I'm not quite sure how to implement them, yet.
Comment #8
W.M. commentedThanks for the great work put into Services and Drupalgap. My question, is this patch ready to be integrated in the next Services release ?
Comment #9
marcingy commentedKicking for bot!
Comment #10
kylebrowning commentedLooks great, but new tests need to be added.
You can copy the old index ones and add the new parameter.
Comment #11
d0t101101 commentedAlso hope to see this is included in the next Services release!
Comment #12
tyler.frankenstein commentedRe-rolled the patch to work with the latest dev snapshot.
Comment #13
kylebrowning commentedTyler,
Would love to commit this but our rule on Services is any patch must come with a test, or an update to a test.
If you don't feel comfortable doing the test thats fine, Ill try and work on it later this week, just let me know if you can't do it.
Comment #14
tyler.frankenstein commentedHi Kyle, I don't feel comfortable writing the tests yet, and have just been leaving them out in the hopes someone else would implement them before this gets committed. That'd be great if you'd like to add the tests, thank you! FYI, I'll also be re-rolling this patch again very soon (this week) to add this same support for User entities.
Comment #15
kylebrowning commentedTyler, no worries. Ill probably get to it tomorrow, or Wednesday.
Great work so far.
Comment #16
tyler.frankenstein commentedThis patch adds support for users. We now have Nodes, Taxonomy Terms and Users covered.
Comment #17
kylebrowning commentedWhoops, other commits have cause this patch to not work.
Can we re-roll?
Comment #18
tyler.frankenstein commented@kylebrowning, thank you for committing my patch in #2537968: Improve flexibility of entity index resources, I'll go ahead and mark this issue as a duplicate as it is no longer needed.