Views "IN" filters not working

Created on 6 April 2023, over 1 year ago
Updated 28 August 2024, 3 months ago

When I add a filter in my View for a field, such as "Content datasource: Content type" and then save the view, this filter never gets applied and is not even passed to the Algolia backend. In the Algolia query log, I just see:

{
  "attributesToRetrieve": "search_api_id",
  "facets": [
  ],
  "analytics": true,
  "length": "6",
  "offset": 0,
  "query": "*"
}

with no filters. Tried adding a filter for a taxonomy term and ran into the same problem. Sending a query string works fine, so Algolia is connected. But Search API is not sending the filters for some reason.

🐛 Bug report
Status

Needs review

Version

3.0

Component

Code

Created by

🇺🇸United States mpotter

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mpotter
  • 🇺🇸United States mpotter

    It appears that the SearchApiAlgoliaBackend::extractConditions function does not support `IN` queries. Would be good to document this as it prevents many common Views filters such as Content Type from working.

  • Merge request !13Issue #3352807: Views filters not working → (Open) created by mpotter
  • Status changed to Needs review over 1 year ago
  • 🇺🇸United States mpotter

    Added a patch that will at least support the "IN" operator when only one option is selected. This allows a basic Content Type filter to work when you just need a single content type since Drupal Views doesn't have an option for '=' operator on that field.

  • 🇺🇸United States mpotter

    Updated patch to get the value rather than key of array.

    However, while this patch works for Content Type, I'm not able to get it working for Taxonomy fields. I have a `field_topic` and with this patch it properly passes a filter of `field_topic:123` and in Algolia I have a node with a value of 123 for field_topic but the result isn't returned. I just get no results at all. So something is still not quite right with taxonomy filters.

  • 🇺🇸United States mpotter

    Found the bug problem with taxonomy terms. The existing code had a bug when adding the "AND" clause to the filter query. I think I can also see how to chain multiple terms using the AND operator, so will post another update for that soon.

  • 🇺🇸United States mpotter

    OK, I've updated the patch to work with any number of items with the IN operator. I think this is ready for review now.

  • 🇮🇳India nikunjkotecha India, Gujarat, Rajkot

    Can we please have full steps to reproduce so we can review the patch and confirm the fix?

    Details required
    * Content type
    * Taxonomy / reference fields
    * Views, what field is the filter applied on
    ...

    Also, how is this different from https://www.drupal.org/project/search_api_algolia/issues/3223351 Handle 'IN' operator Needs review ?

  • 🇧🇪Belgium dieterholvoet Brussels

    I also added support for NOT IN operators to the MR.

Production build 0.71.5 2024