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.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mpotter created an issue. See original summary.

mpotter’s picture

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.

mpotter’s picture

Status: Active » Needs review

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.

mpotter’s picture

Title: Views filters not working » Views "IN" filters not working
mpotter’s picture

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.

mpotter’s picture

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.

mpotter’s picture

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.

davps’s picture

nikunjkotecha’s picture

Status: Needs review » Postponed (maintainer needs more info)
Related issues: +#3223351: Handle 'IN' operator

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 ?

dieterholvoet’s picture

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

dieterholvoet’s picture

Title: Views "IN" filters not working » Add support for 'IN' and 'NOT IN' filters
Status: Postponed (maintainer needs more info) » Needs review

This is a feature request, not a bug report, so there aren't any steps to reproduce here. If you're looking for an example: you don't need views for that, just creating a query in code is enough. Something like this:

$index = Index::load('nodes');
$query = $index->query();
$query->addCondition('type', ['article', 'page'], 'IN');
$results = $query->execute();
nikunjkotecha’s picture

Version: 3.0.0-beta5 » 3.0.x-dev
Category: Bug report » Feature request
Status: Needs review » Fixed

Issue was created as bug, changed to feature request now. Thanks everyone for the work.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.