/** * Test the listener without setting an authorization service. * This should return an empty array. * * @return void */ public function testFilterTranslation() { $params = new ParamBag(['fq' => ['foo:value', 'baz:"foo:value"', 'foofoo:value', "foo\\:value", 'baz:value OR foo:value', '(foo:value)']]); $listener = new FilterFieldConversionListener(['foo' => 'bar', 'baz' => 'boo']); $backend = $this->getMockBuilder('VuFindSearch\\Backend\\Solr\\Backend')->disableOriginalConstructor()->getMock(); $event = new Event('pre', $backend, ['params' => $params]); $listener->onSearchPre($event); $fq = $params->get('fq'); $expected = ['bar:value', 'boo:"foo:value"', 'foofoo:value', "foo\\:value", 'boo:value OR bar:value', '(bar:value)']; $this->assertEquals($expected, $fq); }
/** * 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); }