StreamWriter.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 Index
  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_Index_SegmentInfo */
  22. require_once 'Zend/Search/Lucene/Index/SegmentInfo.php';
  23. /** Zend_Search_Lucene_Index_SegmentWriter */
  24. require_once 'Zend/Search/Lucene/Index/SegmentWriter.php';
  25. /**
  26. * @category Zend
  27. * @package Zend_Search_Lucene
  28. * @subpackage Index
  29. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Search_Lucene_Index_SegmentWriter_StreamWriter extends Zend_Search_Lucene_Index_SegmentWriter
  33. {
  34. /**
  35. * Object constructor.
  36. *
  37. * @param Zend_Search_Lucene_Storage_Directory $directory
  38. * @param string $name
  39. */
  40. public function __construct(Zend_Search_Lucene_Storage_Directory $directory, $name)
  41. {
  42. parent::__construct($directory, $name);
  43. }
  44. /**
  45. * Create stored fields files and open them for write
  46. */
  47. public function createStoredFieldsFiles()
  48. {
  49. $this->_fdxFile = $this->_directory->createFile($this->_name . '.fdx');
  50. $this->_fdtFile = $this->_directory->createFile($this->_name . '.fdt');
  51. $this->_files[] = $this->_name . '.fdx';
  52. $this->_files[] = $this->_name . '.fdt';
  53. }
  54. public function addNorm($fieldName, $normVector)
  55. {
  56. if (isset($this->_norms[$fieldName])) {
  57. $this->_norms[$fieldName] .= $normVector;
  58. } else {
  59. $this->_norms[$fieldName] = $normVector;
  60. }
  61. }
  62. /**
  63. * Close segment, write it to disk and return segment info
  64. *
  65. * @return Zend_Search_Lucene_Index_SegmentInfo
  66. */
  67. public function close()
  68. {
  69. if ($this->_docCount == 0) {
  70. return null;
  71. }
  72. $this->_dumpFNM();
  73. $this->_generateCFS();
  74. return new Zend_Search_Lucene_Index_SegmentInfo($this->_directory,
  75. $this->_name,
  76. $this->_docCount,
  77. -1,
  78. null,
  79. true,
  80. true);
  81. }
  82. }