2
0

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