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