When creating a view with a filter on interface language, the following error occurs:

Notice: Undefined offset: 0 in Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend->createFilterQuery() (line 1691 of modules/contrib/search_api_solr/src/Plugin/search_api/backend/SearchApiSolrBackend.php).
Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend->createFilterQuery('ss_search_api_language', Array, 'IN', Object) (Line: 1588)
Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend->createFilterQueries(Object, Array, Array) (Line: 1556)
Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend->getFilterQueries(Object, Array, Array) (Line: 903)
Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend->search(Object) (Line: 427)
Drupal\search_api\Entity\Server->search(Object) (Line: 346)
Drupal\search_api\Query\Query->execute() (Line: 501)
Drupal\search_api\Plugin\views\query\SearchApiQuery->execute(Object) (Line: 1412)
Drupal\views\ViewExecutable->execute() (Line: 104)
Drupal\facets\Plugin\facets\facet_source\SearchApiViews->fillFacetsWithResults(Array) (Line: 346)
Drupal\facets\FacetManager\DefaultFacetManager->updateResults('search_api_views:search:page_1') (Line: 198)
Drupal\facets\FacetManager\DefaultFacetManager->processFacets('search_api_views:search:page_1') (Line: 365)
Drupal\facets\FacetManager\DefaultFacetManager->returnProcessedFacet(Object) (Line: 181)
Drupal\facets\Plugin\Condition\OtherFacet->evaluate() (Line: 66)
Drupal\Core\Condition\ConditionManager->execute(Object) (Line: 77)
Drupal\Core\Condition\ConditionPluginBase->execute() (Line: 26)
Drupal\block\BlockAccessControlHandler->resolveConditions(Array, 'and') (Line: 123)
Drupal\block\BlockAccessControlHandler->checkAccess(Object, 'view', Object) (Line: 93)
Drupal\Core\Entity\EntityAccessControlHandler->access(Object, 'view', Object, 1) (Line: 334)
Drupal\Core\Entity\Entity->access('view', NULL, 1) (Line: 56)
Drupal\block\BlockRepository->getVisibleBlocksPerRegion(Array) (Line: 137)
Drupal\block\Plugin\DisplayVariant\BlockPageVariant->build() (Line: 259)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 117)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.view', Object) (Line: 149)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 98)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 77)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 628)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
An error occurred while trying to search with Solr: Solr HTTP error: OK (400) {"error":{"metadata":["error-class","org.apache.solr.common.SolrException","root-error-class","org.apache.solr.parser.ParseException"],"msg":"org.apache.solr.search.SyntaxError: Cannot parse 'ss_search_api_language:': Encountered \"<EOF>\" at line 1, column 23.\nWas expecting one of:\n <BAREOPER> ...\n \"(\" ...\n \"*\" ...\n <QUOTED> ...\n <TERM> ...\n <PREFIXTERM> ...\n <WILDTERM> ...\n <REGEXPTERM> ...\n \"[\" ...\n \"{\" ...\n <LPARAMS> ...\n \"filter(\" ...\n <NUMBER> ...\n ","code":400}} .

$field is ss_search_api_language
$value is array ( '***LANGUAGE_language_interface***' => '"en"'

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mpp created an issue. See original summary.

mpp’s picture

Issue summary: View changes
mpp’s picture

Status: Active » Needs review
FileSize
598 bytes
mpp’s picture

array_shift($value) will work on an array with non integer hash keys.
question remains why the key is "***LANGUAGE_language_interface***" and not 0?

mpp’s picture

Title: Undefined offset: 0 in Drupal\search_api_solr\Plugin\search_api\backend\SearchApiSolrBackend » Undefined offset: 0 in SearchApiSolrBackend
Priority: Normal » Major
AsadKamil’s picture

Patch applied cleanly to 8.x Branch
Thanks

root@asad-Vostro-3550:/var/www/html/git/search_api_solr# git apply -v 2773019-1.patch 
Checking patch src/Plugin/search_api/backend/SearchApiSolrBackend.php...
Applied patch src/Plugin/search_api/backend/SearchApiSolrBackend.php cleanly.
root@asad-Vostro-3550:/var/www/html/git/search_api_solr# 
mkalkbrenner’s picture

Did anyone double check if it works with the database backend?

mpp’s picture

@mkalkbrenner, just tested it with the db backend and it's working fine. The issue is only related to the SearchApiSolrBackend when only one value is selected.

mkalkbrenner’s picture

FileSize
596 bytes

I created a test only patch on top of #2775497: Run \Drupal\search_api\Tests\ViewsTest on Solr Backend.

But this test succeeds! Can you tell me some more details about your setup?

mpp’s picture

It's a search_api_solr view.

PHP 7 (tested with php 5.6 that's not the issue), Drupal 8.1.7 with Solr 6 and 2 languages enabled.
Created an index with some node types and some fields among which language.
Created a search view that shows rendered entities on this index with a filter Item language: The item's language.

  • mkalkbrenner committed 32807b3 on 8.x-1.x
    Issue #2773019 by mkalkbrenner: Added test for interface language views...
idhard’s picture

i can confirm the same bug , and the patch #3 worked out . thanks!

mkalkbrenner’s picture

FileSize
1.35 KB

I still can't reproduce the issue, in other words I always get numeric index keys.
Nevertheless the patch makes sense as it is more robust, even for future usages.
But we if we do the array_ahift(), we have to it for the other operators as well, not just for one particular operator.
I attached an enhanced patch.

  • mkalkbrenner committed 2afbdfd on 8.x-1.x
    Issue #2773019 by mkalkbrenner, mpp: Undefined offset: 0 in...
mkalkbrenner’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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