QueryHit.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 Search
  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. */
  21. /**
  22. * @category Zend
  23. * @package Zend_Search_Lucene
  24. * @subpackage Search
  25. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. class Zend_Search_Lucene_Search_QueryHit
  29. {
  30. /**
  31. * Object handle of the index
  32. * @var Zend_Search_Lucene_Interface
  33. */
  34. protected $_index = null;
  35. /**
  36. * Object handle of the document associated with this hit
  37. * @var Zend_Search_Lucene_Document
  38. */
  39. protected $_document = null;
  40. /**
  41. * Number of the document in the index
  42. * @var integer
  43. */
  44. public $id;
  45. /**
  46. * Score of the hit
  47. * @var float
  48. */
  49. public $score;
  50. /**
  51. * Constructor - pass object handle of Zend_Search_Lucene_Interface index that produced
  52. * the hit so the document can be retrieved easily from the hit.
  53. *
  54. * @param Zend_Search_Lucene_Interface $index
  55. */
  56. public function __construct(Zend_Search_Lucene_Interface $index)
  57. {
  58. $this->_index = new Zend_Search_Lucene_Proxy($index);
  59. }
  60. /**
  61. * Convenience function for getting fields from the document
  62. * associated with this hit.
  63. *
  64. * @param string $offset
  65. * @return string
  66. */
  67. public function __get($offset)
  68. {
  69. return $this->getDocument()->getFieldValue($offset);
  70. }
  71. /**
  72. * Return the document object for this hit
  73. *
  74. * @return Zend_Search_Lucene_Document
  75. */
  76. public function getDocument()
  77. {
  78. if (!$this->_document instanceof Zend_Search_Lucene_Document) {
  79. $this->_document = $this->_index->getDocument($this->id);
  80. }
  81. return $this->_document;
  82. }
  83. /**
  84. * Return the index object for this hit
  85. *
  86. * @return Zend_Search_Lucene_Interface
  87. */
  88. public function getIndex()
  89. {
  90. return $this->_index;
  91. }
  92. }