(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

MXT created an issue. See original summary.

wim leers’s picture

Issue tags: +API-First Initiative
gabesullice’s picture

Status: Active » Fixed

@MXT, thanks for the excellent issue summary. It was very easy to interpret :) 🙏

I think the problem is that CONTAINS is for string values. What you want is the IN operator.

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!

mxt’s picture

Status: Fixed » Active

Thank you for your answer @gabesullice, but the IN operator 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:

Retrieve all articles with title that contains ("mang" AND "ser") OR subtitle that contains ("mang" AND "ser")

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

gabesullice’s picture

Title: JSON:API - How to retrieve multiple values in a CONTAINS condition? » [PP-1] JSON:API - How to retrieve multiple values in a CONTAINS condition?
Category: Support request » Bug report
Status: Active » Postponed
Related issues: +#3066202: Filtering multivalue reference fields to contain multiple specified values does not work

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

gabesullice’s picture

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

Version: 8.7.2 » 8.7.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.7.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.