2
0

Common.php 2.9 KB

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