final move of files
[web.mtrack] / Zend / Search / Lucene / Search / Highlighter / Default.php
diff --git a/Zend/Search/Lucene/Search/Highlighter/Default.php b/Zend/Search/Lucene/Search/Highlighter/Default.php
new file mode 100644 (file)
index 0000000..ed59b35
--- /dev/null
@@ -0,0 +1,94 @@
+<?php\r
+/**\r
+ * Zend Framework\r
+ *\r
+ * LICENSE\r
+ *\r
+ * This source file is subject to the new BSD license that is bundled\r
+ * with this package in the file LICENSE.txt.\r
+ * It is also available through the world-wide-web at this URL:\r
+ * http://framework.zend.com/license/new-bsd\r
+ * If you did not receive a copy of the license and are unable to\r
+ * obtain it through the world-wide-web, please send an email\r
+ * to license@zend.com so we can send you a copy immediately.\r
+ *\r
+ * @category   Zend\r
+ * @package    Zend_Search_Lucene\r
+ * @subpackage Search\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ * @version    $Id: Default.php 16971 2009-07-22 18:05:45Z mikaelkael $\r
+ */\r
+\r
+/** Zend_Search_Lucene_Search_Highlighter_Interface */\r
+require_once 'Zend/Search/Lucene/Search/Highlighter/Interface.php';\r
+/**\r
+ * @category   Zend\r
+ * @package    Zend_Search_Lucene\r
+ * @subpackage Search\r
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)\r
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License\r
+ */\r
+class Zend_Search_Lucene_Search_Highlighter_Default implements Zend_Search_Lucene_Search_Highlighter_Interface\r
+{\r
+    /**\r
+     * List of colors for text highlighting\r
+     *\r
+     * @var array\r
+     */\r
+    protected $_highlightColors = array('#66ffff', '#ff66ff', '#ffff66',\r
+                                        '#ff8888', '#88ff88', '#8888ff',\r
+                                        '#88dddd', '#dd88dd', '#dddd88',\r
+                                        '#aaddff', '#aaffdd', '#ddaaff',\r
+                                        '#ddffaa', '#ffaadd', '#ffddaa');\r
+\r
+    /**\r
+     * Index of current color for highlighting\r
+     *\r
+     * Index is increased at each highlight() call, so terms matching different queries are highlighted using different colors.\r
+     *\r
+     * @var integer\r
+     */\r
+    protected $_currentColorIndex = 0;\r
+\r
+    /**\r
+     * HTML document for highlighting\r
+     *\r
+     * @var Zend_Search_Lucene_Document_Html\r
+     */\r
+    protected $_doc;\r
+\r
+    /**\r
+     * Set document for highlighting.\r
+     *\r
+     * @param Zend_Search_Lucene_Document_Html $document\r
+     */\r
+    public function setDocument(Zend_Search_Lucene_Document_Html $document)\r
+    {\r
+       $this->_doc = $document;\r
+    }\r
+\r
+    /**\r
+     * Get document for highlighting.\r
+     *\r
+     * @return Zend_Search_Lucene_Document_Html $document\r
+     */\r
+    public function getDocument()\r
+    {\r
+       return $this->_doc;\r
+    }\r
+\r
+    /**\r
+     * Highlight specified words\r
+     *\r
+     * @param string|array $words  Words to highlight. They could be organized using the array or string.\r
+     */\r
+    public function highlight($words)\r
+    {\r
+       $color = $this->_highlightColors[$this->_currentColorIndex];\r
+       $this->_currentColorIndex = ($this->_currentColorIndex + 1) % count($this->_highlightColors);\r
+\r
+       $this->_doc->highlight($words, $color);\r
+    }\r
+\r
+}\r