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&parameters[title]=%25hello%25&parameters[type]=article&parameters_op[title]=like

Patch to come...

Comments

tyler.frankenstein’s picture

Status: Active » Needs review
StatusFileSize
new3.45 KB

If 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.

kylebrowning’s picture

Hey 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?

tyler.frankenstein’s picture

StatusFileSize
new6.25 KB

Added test.

Status: Needs review » Needs work

The last submitted patch, 3: index_conditions-2403645-3.patch, failed testing.

marcingy’s picture

From a code prospective looks nice so plus 1 from me

kylebrowning’s picture

I 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.

tyler.frankenstein’s picture

StatusFileSize
new5.31 KB

Attached 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.

W.M.’s picture

Thanks for the great work put into Services and Drupalgap. My question, is this patch ready to be integrated in the next Services release ?

marcingy’s picture

Status: Needs work » Needs review

Kicking for bot!

kylebrowning’s picture

Status: Needs review » Needs work

Looks great, but new tests need to be added.

You can copy the old index ones and add the new parameter.

d0t101101’s picture

Also hope to see this is included in the next Services release!

tyler.frankenstein’s picture

StatusFileSize
new5.49 KB

Re-rolled the patch to work with the latest dev snapshot.

kylebrowning’s picture

Tyler,

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.

tyler.frankenstein’s picture

Hi 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.

kylebrowning’s picture

Tyler, no worries. Ill probably get to it tomorrow, or Wednesday.

Great work so far.

tyler.frankenstein’s picture

StatusFileSize
new7.24 KB

This patch adds support for users. We now have Nodes, Taxonomy Terms and Users covered.

kylebrowning’s picture

Whoops, other commits have cause this patch to not work.

Can we re-roll?

tyler.frankenstein’s picture

Status: Needs work » Closed (duplicate)

@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.