Common.php 2.5 KB

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