(Premise: this has already been asked on Drupal Answer without success)
I'm using core jsonapi module, and works well for a simple query like:
Retrieve all articles with title that contains "MyKeyValue" or subtitle that contains "MyKeyValue"
That, translated in jsonapi query, is:
fields[node--article]=title,field_subtitle
filter[or-group][group][conjunction]=OR
filter[status][value]=1
filter[title-filter][condition][path]=title
filter[title-filter][condition][operator]=CONTAINS
filter[title-filter][condition][value]=MyKeyValue
filter[title-filter][condition][memberOf]=or-group
filter[subtitle-filter][condition][path]=field_subtitle
filter[subtitle-filter][condition][operator]=CONTAINS
filter[subtitle-filter][condition][value]=MyKeyValue
filter[subtitle-filter][condition][memberOf]=or-group
But HOW to manage multivalues within the CONTAINS condition? I mean: how to accomplish a query like:
Retrieve all articles with title that contains ("MyKeyValue" AND "AnotherKeyValue") or subtitle that contains ("MyKeyValue" AND "AnotherKeyValue")
I tried to pass multiple values in this way:
...
filter[title-filter][condition][operator]=CONTAINS
filter[title-filter][condition][value][]=MyKeyValue
filter[title-filter][condition][value][]=AnotherKeyValue
...
filter[subtitle-filter][condition][operator]=CONTAINS
filter[subtitle-filter][condition][value][]=MyKeyValue
filter[subtitle-filter][condition][value][]=AnotherKeyValue
...
But does not work.
Any help will be greatly appreciated, thank you.
Comments
Comment #2
wim leersComment #3
gabesullice@MXT, thanks for the excellent issue summary. It was very easy to interpret :) 🙏
I think the problem is that
CONTAINSis for string values. What you want is theINoperator.Marking as "Fixed" because I'm 99% sure this is the problem. Feel free to reopen this issue if it doesn't fix the problem though!
Comment #4
mxtThank you for your answer @gabesullice, but the
INoperator search for exact values only, isn't it?If this is the case, it is not useful to me.
I'll try to clarify better my needs with the following example:
Suppose that, between others, there is a node with title "Che buoni gli spaghetti italiani"
and subtitle "Li mangio tutte le sere"
The query:
Our node above should match because contains "mang" and "ser" within the subtitle:
title: "Che buoni gli spaghetti italiani" => does not match
subtitle: "Li mangio tutte le sere" => yes, match
How to reach the goal with JSON API?
Thank you
Comment #5
gabesulliceHi @MXT, sorry for my long absence. Since you reopened this a number of similar reports have come in. I think this is probably related to #3066202: Filtering multivalue reference fields to contain multiple specified values does not work. The only difference appears to be that your issue is not using an entity reference. I'm going to mark this one postponed on that issue rather than close this as a duplicate so that once that former is fixed, we can determine if this one is still resolved or still broken.
Comment #6
gabesullice@MXT, I posted a workaround that I think should also for for you here: #3066202-12: Filtering multivalue reference fields to contain multiple specified values does not work
If that fixes your issue, please let use know and update this issue to "Closed (duplicate)" since we'll know that they both have the same underlying cause. If it doesn't fix your issue, please also let us know and change this back to "Active" again (thanks for doing that before!) since we'll know your problem has its own unique cause.