7 * This source file is subject to the new BSD license that is bundled
\r
8 * with this package in the file LICENSE.txt.
\r
9 * It is also available through the world-wide-web at this URL:
\r
10 * http://framework.zend.com/license/new-bsd
\r
11 * If you did not receive a copy of the license and are unable to
\r
12 * obtain it through the world-wide-web, please send an email
\r
13 * to license@zend.com so we can send you a copy immediately.
\r
16 * @package Zend_Search_Lucene
\r
17 * @subpackage Search
\r
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
\r
19 * @license http://framework.zend.com/license/new-bsd New BSD License
\r
20 * @version $Id: Default.php 16971 2009-07-22 18:05:45Z mikaelkael $
\r
23 /** Zend_Search_Lucene_Search_Highlighter_Interface */
\r
24 require_once 'Zend/Search/Lucene/Search/Highlighter/Interface.php';
\r
27 * @package Zend_Search_Lucene
\r
28 * @subpackage Search
\r
29 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
\r
30 * @license http://framework.zend.com/license/new-bsd New BSD License
\r
32 class Zend_Search_Lucene_Search_Highlighter_Default implements Zend_Search_Lucene_Search_Highlighter_Interface
\r
35 * List of colors for text highlighting
\r
39 protected $_highlightColors = array('#66ffff', '#ff66ff', '#ffff66',
\r
40 '#ff8888', '#88ff88', '#8888ff',
\r
41 '#88dddd', '#dd88dd', '#dddd88',
\r
42 '#aaddff', '#aaffdd', '#ddaaff',
\r
43 '#ddffaa', '#ffaadd', '#ffddaa');
\r
46 * Index of current color for highlighting
\r
48 * Index is increased at each highlight() call, so terms matching different queries are highlighted using different colors.
\r
52 protected $_currentColorIndex = 0;
\r
55 * HTML document for highlighting
\r
57 * @var Zend_Search_Lucene_Document_Html
\r
62 * Set document for highlighting.
\r
64 * @param Zend_Search_Lucene_Document_Html $document
\r
66 public function setDocument(Zend_Search_Lucene_Document_Html $document)
\r
68 $this->_doc = $document;
\r
72 * Get document for highlighting.
\r
74 * @return Zend_Search_Lucene_Document_Html $document
\r
76 public function getDocument()
\r
82 * Highlight specified words
\r
84 * @param string|array $words Words to highlight. They could be organized using the array or string.
\r
86 public function highlight($words)
\r
88 $color = $this->_highlightColors[$this->_currentColorIndex];
\r
89 $this->_currentColorIndex = ($this->_currentColorIndex + 1) % count($this->_highlightColors);
\r
91 $this->_doc->highlight($words, $color);
\r