final move of files
[web.mtrack] / Zend / Search / Lucene / Search / Highlighter / Default.php
1 <?php\r
2 /**\r
3  * Zend Framework\r
4  *\r
5  * LICENSE\r
6  *\r
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
14  *\r
15  * @category   Zend\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
21  */\r
22 \r
23 /** Zend_Search_Lucene_Search_Highlighter_Interface */\r
24 require_once 'Zend/Search/Lucene/Search/Highlighter/Interface.php';\r
25 /**\r
26  * @category   Zend\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
31  */\r
32 class Zend_Search_Lucene_Search_Highlighter_Default implements Zend_Search_Lucene_Search_Highlighter_Interface\r
33 {\r
34     /**\r
35      * List of colors for text highlighting\r
36      *\r
37      * @var array\r
38      */\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
44 \r
45     /**\r
46      * Index of current color for highlighting\r
47      *\r
48      * Index is increased at each highlight() call, so terms matching different queries are highlighted using different colors.\r
49      *\r
50      * @var integer\r
51      */\r
52     protected $_currentColorIndex = 0;\r
53 \r
54     /**\r
55      * HTML document for highlighting\r
56      *\r
57      * @var Zend_Search_Lucene_Document_Html\r
58      */\r
59     protected $_doc;\r
60 \r
61     /**\r
62      * Set document for highlighting.\r
63      *\r
64      * @param Zend_Search_Lucene_Document_Html $document\r
65      */\r
66     public function setDocument(Zend_Search_Lucene_Document_Html $document)\r
67     {\r
68         $this->_doc = $document;\r
69     }\r
70 \r
71     /**\r
72      * Get document for highlighting.\r
73      *\r
74      * @return Zend_Search_Lucene_Document_Html $document\r
75      */\r
76     public function getDocument()\r
77     {\r
78         return $this->_doc;\r
79     }\r
80 \r
81     /**\r
82      * Highlight specified words\r
83      *\r
84      * @param string|array $words  Words to highlight. They could be organized using the array or string.\r
85      */\r
86     public function highlight($words)\r
87     {\r
88         $color = $this->_highlightColors[$this->_currentColorIndex];\r
89         $this->_currentColorIndex = ($this->_currentColorIndex + 1) % count($this->_highlightColors);\r
90 \r
91         $this->_doc->highlight($words, $color);\r
92     }\r
93 \r
94 }\r