Common.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Search_Lucene
  17. * @subpackage Analysis
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /** Define constant used to provide correct file processing order */
  23. /** @todo Section should be removed with ZF 2.0 release as obsolete */
  24. if (!defined('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED')) {
  25. define('ZEND_SEARCH_LUCENE_COMMON_ANALYZER_PROCESSED', true);
  26. }
  27. /** Zend_Search_Lucene_Analysis_Analyzer */
  28. require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
  29. /** Zend_Search_Lucene_Analysis_Token */
  30. require_once 'Zend/Search/Lucene/Analysis/Token.php';
  31. /** Zend_Search_Lucene_Analysis_TokenFilter */
  32. require_once 'Zend/Search/Lucene/Analysis/TokenFilter.php';
  33. /**
  34. * Common implementation of the Zend_Search_Lucene_Analysis_Analyzer interface.
  35. * There are several standard standard subclasses provided by Zend_Search_Lucene/Analysis
  36. * subpackage: Zend_Search_Lucene_Analysis_Analyzer_Common_Text, ZSearchHTMLAnalyzer, ZSearchXMLAnalyzer.
  37. *
  38. * @todo ZSearchHTMLAnalyzer and ZSearchXMLAnalyzer implementation
  39. *
  40. * @category Zend
  41. * @package Zend_Search_Lucene
  42. * @subpackage Analysis
  43. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  44. * @license http://framework.zend.com/license/new-bsd New BSD License
  45. */
  46. abstract class Zend_Search_Lucene_Analysis_Analyzer_Common extends Zend_Search_Lucene_Analysis_Analyzer
  47. {
  48. /**
  49. * The set of Token filters applied to the Token stream.
  50. * Array of Zend_Search_Lucene_Analysis_TokenFilter objects.
  51. *
  52. * @var array
  53. */
  54. private $_filters = array();
  55. /**
  56. * Add Token filter to the Analyzer
  57. *
  58. * @param Zend_Search_Lucene_Analysis_TokenFilter $filter
  59. */
  60. public function addFilter(Zend_Search_Lucene_Analysis_TokenFilter $filter)
  61. {
  62. $this->_filters[] = $filter;
  63. }
  64. /**
  65. * Apply filters to the token. Can return null when the token was removed.
  66. *
  67. * @param Zend_Search_Lucene_Analysis_Token $token
  68. * @return Zend_Search_Lucene_Analysis_Token
  69. */
  70. public function normalize(Zend_Search_Lucene_Analysis_Token $token)
  71. {
  72. foreach ($this->_filters as $filter) {
  73. $token = $filter->normalize($token);
  74. // resulting token can be null if the filter removes it
  75. if ($token === null) {
  76. return null;
  77. }
  78. }
  79. return $token;
  80. }
  81. }