The search result is an array of
Zend_Search_Lucene_Search_QueryHit objects. Each of these has two
properties: $hit->id is a document number within the index and
$hit->score is a score of the hit in a search result. The results are
ordered by score (descending from highest score).
The Zend_Search_Lucene_Search_QueryHit object also exposes each
field of the Zend_Search_Lucene_Document found in the search as a
property of the hit. In the following example, a hit is returned with two fields from
the corresponding document: title and author.
<?php
$index = Zend_Search_Lucene::open('/data/my_index');
$hits = $index->find($query);
foreach ($hits as $hit) {
echo $hit->score;
echo $hit->title;
echo $hit->author;
}
Stored fields are always returned in UTF-8 encoding.
Optionally, the original Zend_Search_Lucene_Document object can
be returned from the Zend_Search_Lucene_Search_QueryHit.
You can retrieve stored parts of the document by using the
getDocument() method of the index object and then get them by
getFieldValue() method:
<?php
$index = Zend_Search_Lucene::open('/data/my_index');
$hits = $index->find($query);
foreach ($hits as $hit) {
// return Zend_Search_Lucene_Document object for this hit
echo $document = $hit->getDocument();
// return a Zend_Search_Lucene_Field object
// from the Zend_Search_Lucene_Document
echo $document->getField('title');
// return the string value of the Zend_Search_Lucene_Field object
echo $document->getFieldValue('title');
// same as getFieldValue()
echo $document->title;
}
The fields available from the Zend_Search_Lucene_Document object
are determined at the time of indexing. The document fields are either indexed, or
index and stored, in the document by the indexing application
(e.g. LuceneIndexCreation.jar).
Note that the document identity ('path' in our example) is also stored in the index and must be retrieved from it.




