Problem/Motivation

When a contextual filter uses a conjunction 'OR', the default group in SearchApiQuery::build() will have type 'OR'. But this type is being ignored, $this->query was initialized before with AND and it is not possible to change it.

We've noticed this problem since version 1.26 (because now the base is "$this->query" and before it was a new group).
The changes came from patch here: https://www.drupal.org/node/3029582 .

Steps to reproduce

I'm using a hook_views_query_alter where I add change the contextual filter type to OR.

I believe this problem also affects views_contextual_filters_or now, see: https://www.drupal.org/project/views_contextual_filters_or/issues/3314825 .

Comments

dxvargas created an issue. See original summary.

dxvargas’s picture

I'm uploading a first patch that fixes the problem.

dxvargas’s picture

There was a bug, I'm uploading again a first patch that fixes the problem.

dxvargas’s picture

Title: For default group type OR is ignored » Default group type OR is ignored in SearchApiQuery::build
Issue summary: View changes
michelrrr’s picture

[ UPDATE
Fixed thanks to : this patch #3 + https://www.drupal.org/project/search_api/issues/3313837
]

Hello, I've applied the patch in order to get the OR working (with 2 fields only) but now it return all records instead of only the ones specified in the contextual filters. By looking at the query in the view, I see the OR correctly set on the fields nevertheless, I get back all contents instead of the ones matching the query. Don't know if it's linked to the "... OR" extension or to "search api"

drunken monkey’s picture

Status: Active » Needs review

#3318187: Fix regressions in Views filters solved a similar issue, did that patch maybe fix the problem for you? Please try out the latest dev version and let me know.

carolpettirossi’s picture

@drunken monkey, the patch from https://www.drupal.org/project/search_api/issues/3318187 did not solve the issue for me.

drunken monkey’s picture

Status: Needs review » Postponed (maintainer needs more info)

OK, thanks for the feedback!
Are there any steps to reproduce that don’t require an alter hook?

dxvargas’s picture

Hi @drunken_monkey,

The related issue https://www.drupal.org/project/views_contextual_filters_or/issues/3314825 has the same problem and it is using plugins instead of an alter hook.

carolpettirossi’s picture

@drunken monkey, hopefully the context below helps:

I'm using the views_contextual_filters_or module.

My scenario:
Content types and Taxonomies are categorized with "Brands", where Brands are taxonomy terms.
When the user searches for something while in the brand A site, the search should return only Taxononomies or Nodes for that brand hence why I have the configuration below in the Contextual Filters:

Content datasource: Brand
Taxonomy term datasource: Brand

And the settings below in the Query settings:

Contextual filters OR
Contextual filters applied to OR logic.

carolpettirossi’s picture

Status: Postponed (maintainer needs more info) » Needs work
carolpettirossi’s picture

For me, with the scenario, I described in #10,

drunken monkey’s picture

Component: General code » Views integration
Status: Needs work » Needs review
StatusFileSize
new1.73 KB

I was able to reproduce the problem using the Views Contextual Filters OR module and I think I managed to also arrive at a solution covering all scenarios. Please test/review the attached patch.

ben25’s picture

I can HAPPILY confirm that #13 is working for me.

frontmobe’s picture

I can confirm the patch in #13 solves the issue on a search index view with multiple contextual filters enabled, search_api 1.28 and views_contextual_filters_or 1.4 modules enabled (running Drupal 9.5).

Thanks for the patch!

  • drunken monkey committed 0b6db15a on 8.x-1.x
    Issue #3316665 by drunken monkey, carolpettirossi, dxvargas: Fixed OR...
drunken monkey’s picture

Good to hear, thanks a lot for testing and reporting back!
Committed.
Thanks again, everyone!

drunken monkey’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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