Problem/Motivation

Backends like Solr rely on the $query->getLanguages() function to implement their multilingual capabilities.
If the new Languages (with fallback) processor is used, $query->getLanguages() returns no languages.
But it would also be wrong to simply return the languages from the new filter as they need to be handled differently.

Proposed resolution

Additionally provide $query->getLanguagesWithFallback().

Comments

mkalkbrenner created an issue. See original summary.

mkalkbrenner’s picture

Status: Active » Needs review
Related issues: +#1960684: Allow filtering by "Language (with fallback)"
StatusFileSize
new5.41 KB
mkalkbrenner’s picture

StatusFileSize
new4.92 KB

Status: Needs review » Needs work

The last submitted patch, 3: 3306204.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

drunken monkey’s picture

Status: Needs work » Needs review
StatusFileSize
new2.31 KB

Thanks a lot for pointing out this problem and providing a patch! You’re right, we totally forgot that the Solr backend needs language information for reasons other than filtering on the language code, so this should also be included in some way when using a language filter with fallback.

However, I’m also not quite convinced that such a large change, with a new QueryInterface method, is actually needed here. (If it is, it would at least need better documentation, so people have a chance of understanding what this property means.) For one thing, there are already query options, which are usually used when some specific plugin or component provides or needs some information that doesn’t concern the large majority of plugins. As such, I think this new data could just be added as a query option instead of a whole new query property with associated methods.

Also, it seems like this information should always be included for required language filters ($opInRequired in my revised patch) that do not use setLanguages() (or even for those, I guess, as it shouldn’t do any harm either?), not just when the data comes from this specific processor. (Moreover, I think it usually will.) So we can probably drop the check on the data definition. Otherwise, I think it should use a separate flag in the data definition’s settings (like currently 'views_type' => 'language',) instead of checking for the processor ID.

Finally, and completely unrelatedly, I think the boolean condition for $direct_language_condition was missing an === 'AND'. Might as well fix that, while we’re at it.

Patch with my suggested solution attached. Please review, test, and tell me if that would be enough to let you resolve the problem in the Solr backend. (It seems to me like it should, but I could of course be mistaken.)

Status: Needs review » Needs work
drunken monkey’s picture

Status: Needs work » Needs review
mkalkbrenner’s picture

Will the search_api_included_languages option contain all languages or just additional/fallback ones?

drunken monkey’s picture

I think this is best seen in the code: As long as it’s a required (AND), positive (in) language condition, I add all selected values to the option in \Drupal\search_api\Plugin\views\filter\SearchApiLanguage::query(). But this could easily be changed, if it would make your job easier.

mkalkbrenner’s picture

Status: Needs review » Fixed

OK, I got it to work with this version.

mkalkbrenner’s picture

Status: Fixed » Reviewed & tested by the community

  • drunken monkey committed 0130868 on 8.x-1.x
    Issue #3306204 by mkalkbrenner, drunken monkey: Added a new query option...
drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

Good to hear, thanks a lot for your feedback!
Committed.
Thanks again!

Status: Fixed » Closed (fixed)

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

edykst’s picture

Hi guys.
This patch broke all our search pages.
The getGroupType() returns an array instead of the expected string.

$query->getGroupType($this->options['group']) === 'AND'

So we get the error 'search_api_language Undefined field ! Incorrect filter criteria is using for searching!'

ps. we don't use solr

edykst’s picture

aspilicious’s picture

@drunken_monkey, edykst is correct this patch introduces a regression. We don't filter on languages anymore causing lot's of broken searches when you have big mulilingual websites.

Proper patch in the make.

aspilicious’s picture

StatusFileSize
new763 bytes
aspilicious’s picture

My patch isn't sufficient either because the function can return a string OR an array

public function getGroupType($group) {
return !empty($this->where[$group]) ? $this->where[$group] : 'AND';
}

drunken monkey’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new6.19 KB

Thanks a lot for pinging me, Bram! Really bad that we caused a regression with this, should fix this ASAP.

However, there seems to be a separate bug regarding the backend plugins you’re using: In theory, the filter should fall back to placing a condition on the special search_api_language field, which is documented to have the same effect as the language option (basically). So, if the backend plugin doesn’t honor that, that’s a bug, too. You might want to report that there. This is also why the tests didn’t pick up the regression: As the DB backend correctly handles the search_api_language fallback, the test views worked fine. I now added explicit checks for the generated search query to make sure this doesn’t happen again.

Regarding the fix, as the getGroupType() docs clearly state that will return a string, 'AND' or 'OR', the bug is obviously in that method, not in the caller. The fix should therefore be applied there. (Seems there is only a single caller anyways, so probably a negligible risk that anyone relies on the broken old behavior.)

Please test/review the attached patch and we can hopefully fix this quickly.

drunken monkey’s picture

Component: General code » Views integration
mkalkbrenner’s picture

Priority: Major » Critical
StatusFileSize
new100.56 KB
new24.68 KB

search_api tests are failing on Drupal 9.5 and 10 (9.4 works) using the Solr backend.
To be concrete: ViewsTest::regressionTest2869121()

But the failure is not about languages but an empty string (or array) provided as id and create timestamp. By surprise the patch in #20 solves it.

This is the condition group provided by search_api without the patch:

And this is the condition group provided by search_api with patch #20 applied:

As you can see, an empty string is provided as id. That leads to a Solr exception that an empty string is not valid for a number field. I assume that the same issue exists for the DB backend but maybe the empty string doesn't lead to a DB error.

@drunken monkey I won't set this issue to RTBC again, because the relation between the patch and the issue I described and the fact that this happens only with drupal >= 9.4 is strange.
Nevertheless this should be fixed ASAP

drunken monkey’s picture

Priority: Critical » Major
Status: Needs review » Fixed

You’re right, I could reproduce this behavior locally as well. Furthermore, for me, the patch in #20 did nothing to solve it. Really pretty bad. Not sure what, yet, but Core seems to have messed something up there.

Created #3318187: Fix regressions in Views filters as the follow-up issue to fix all those regressions, so people have an easier time finding it. Marking this one as “Fixed” again.
Still, thanks a lot for your work in here!

Status: Fixed » Closed (fixed)

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