B Add document to the index.
This function creates a Zend_Search_Lucene document, called $doc and then we add each field to the
document (#1), before calling addDocument() (#2). As we are going to be adding documents for every page
on the website, we should make the creation of the document as easy as possible. We will extend
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Zend_Search_Lucene_Document so that we can instantiate the object with the right data in one line of code.
This is shown in listing 8.2.
Listing 8.2: Extending Zend_Search_Luncene_Document for easier creation
class Places_Search_Lucene_Document extends Zend_Search_Lucene_Document
{
public function __construct($class, $key, $title,
$contents, $summary, $createdBy, $dateCreated)
{
$this->addField(Zend_Search_Lucene_Field::Keyword(
'docRef', "$class:$key"));
$this->addField(Zend_Search_Lucene_Field::UnIndexed(
'class', $class));
$this->addField(Zend_Search_Lucene_Field::UnIndexed(
'key', $key));
$this->addField(Zend_Search_Lucene_Field::Text(
'title', $title));
$this->addField(Zend_Search_Lucene_Field::UnStored(
'contents', $contents));
$this->addField(Zend_Search_Lucene_Field::UnIndexed(
'summary', $summary));
$this->addField(Zend_Search_Lucene_Field::Keyword(
'createdBy', $createdBy));
$this->addField(Zend_Search_Lucene_Field::Keyword(
'dateCreated', $dateCreated));
}
}
Using the new Places_Search_Lucene_Document class is now very easy as shown in listing 8.
Pages:
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228