/** * Detect parser error response. * * @return void */ public function testDetectUndefinedFieldError() { $response = $this->createResponse('solr4-undefined-field-error'); $backend = $this->getMockForAbstractClass('VuFindSearch\\Backend\\BackendInterface'); $exception = HttpErrorException::createFromResponse($response); $params = ['backend_instance' => $backend]; $event = new Event(null, $exception, $params); $listener = new ErrorListener($backend); $listener->onSearchError($event); $this->assertTrue($exception->hasTag('VuFind\\Search\\ParserError')); }
/** * Create listeners. * * @param Backend $backend Backend * * @return void */ protected function createListeners(Backend $backend) { $events = $this->serviceLocator->get('SharedEventManager'); // Load configurations: $config = $this->config->get('config'); $search = $this->config->get($this->searchConfig); $facet = $this->config->get($this->facetConfig); // Highlighting $this->getInjectHighlightingListener($backend, $search)->attach($events); // Conditional Filters if (isset($search->ConditionalHiddenFilters) && $search->ConditionalHiddenFilters->count() > 0) { $this->getInjectConditionalFilterListener($search)->attach($events); } // Spellcheck if (isset($config->Spelling->enabled) && $config->Spelling->enabled) { if (isset($config->Spelling->simple) && $config->Spelling->simple) { $dictionaries = ['basicSpell']; } else { $dictionaries = ['default', 'basicSpell']; } $spellingListener = new InjectSpellingListener($backend, $dictionaries); $spellingListener->attach($events); } // Apply field stripping if applicable: if (isset($search->StripFields) && isset($search->IndexShards)) { $strip = $search->StripFields->toArray(); foreach ($strip as $k => $v) { $strip[$k] = array_map('trim', explode(',', $v)); } $mindexListener = new MultiIndexListener($backend, $search->IndexShards->toArray(), $strip, $this->loadSpecs()); $mindexListener->attach($events); } // Apply deduplication if applicable: if (isset($search->Records->deduplication)) { $this->getDeduplicationListener($backend, $search->Records->deduplication)->attach($events); } // Attach hierarchical facet listener: $this->getHierarchicalFacetListener($backend)->attach($events); // Apply legacy filter conversion if necessary: $facets = $this->config->get($this->facetConfig); if (!empty($facets->LegacyFields)) { $filterFieldConversionListener = new FilterFieldConversionListener($facets->LegacyFields->toArray()); $filterFieldConversionListener->attach($events); } // Attach hide facet value listener: if ($hfvListener = $this->getHideFacetValueListener($backend, $facet)) { $hfvListener->attach($events); } // Attach error listeners for Solr 3.x and Solr 4.x (for backward // compatibility with VuFind 1.x instances). $legacyErrorListener = new LegacyErrorListener($backend); $legacyErrorListener->attach($events); $errorListener = new ErrorListener($backend); $errorListener->attach($events); }