Common.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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-2009 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. /** Zend_Search_Lucene_Analysis_Analyzer */
  23. require_once 'Zend/Search/Lucene/Analysis/Analyzer.php';
  24. /**
  25. * Common implementation of the Zend_Search_Lucene_Analysis_Analyzer interface.
  26. * There are several standard standard subclasses provided by Zend_Search_Lucene/Analysis
  27. * subpackage: Zend_Search_Lucene_Analysis_Analyzer_Common_Text, ZSearchHTMLAnalyzer, ZSearchXMLAnalyzer.
  28. *
  29. * @todo ZSearchHTMLAnalyzer and ZSearchXMLAnalyzer implementation
  30. *
  31. * @category Zend
  32. * @package Zend_Search_Lucene
  33. * @subpackage Analysis
  34. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. */
  37. abstract class Zend_Search_Lucene_Analysis_Analyzer_Common extends Zend_Search_Lucene_Analysis_Analyzer
  38. {
  39. /**
  40. * The set of Token filters applied to the Token stream.
  41. * Array of Zend_Search_Lucene_Analysis_TokenFilter objects.
  42. *
  43. * @var array
  44. */
  45. private $_filters = array();
  46. /**
  47. * Add Token filter to the Analyzer
  48. *
  49. * @param Zend_Search_Lucene_Analysis_TokenFilter $filter
  50. */
  51. public function addFilter(Zend_Search_Lucene_Analysis_TokenFilter $filter)
  52. {
  53. $this->_filters[] = $filter;
  54. }
  55. /**
  56. * Apply filters to the token. Can return null when the token was removed.
  57. *
  58. * @param Zend_Search_Lucene_Analysis_Token $token
  59. * @return Zend_Search_Lucene_Analysis_Token
  60. */
  61. public function normalize(Zend_Search_Lucene_Analysis_Token $token)
  62. {
  63. foreach ($this->_filters as $filter) {
  64. $token = $filter->normalize($token);
  65. // resulting token can be null if the filter removes it
  66. if ($token === null) {
  67. return null;
  68. }
  69. }
  70. return $token;
  71. }
  72. }