public function testSetHighlighterAnalyzer() { $this->app->instance('filterClass1', $tokenFilterMock = m::mock('ZendSearch\\Lucene\\Analysis\\TokenFilter\\TokenFilterInterface')); $this->analyzer->shouldReceive('addFilter')->with($tokenFilterMock)->once(); $this->config->setHighlighterAnalyzer(); $this->assertEquals($this->analyzer, Analyzer::getDefault()); }
/** * Highlight matches in HTML fragment. * * @param string $html * @return string */ public function highlight($html) { $highlighted = ''; $lastQuery = $this->queryRunner->getLastQuery(); if (!empty($lastQuery)) { $this->analyzerConfig->setHighlighterAnalyzer(); $highlighted = $lastQuery->htmlFragmentHighlightMatches($html, 'utf-8', $this->highlighter); $this->analyzerConfig->setDefaultAnalyzer(); } return !empty($highlighted) ? $highlighted : $html; }
/** * * Create connection to index * * @param $path * @param AnalyzerConfig $config * @throws \Exception */ public function __construct($path, AnalyzerConfig $config) { $config->setDefaultAnalyzer(); $this->indexPath = $path; try { $this->index = Lucene::open($path); } catch (ExceptionInterface $e) { $this->index = Lucene::create($path); } catch (\Exception $e) { if (!file_exists($path)) { throw new \Exception("Couldn't connect to index of Zend Lucene. Directory '{$path}' doesn't exist.'"); } throw $e; } }