We need this on retrieval in order
to be able to create a url to the correct page in the results list.
docRef Keyword A unique identifier for this record. We need this so we can find it for updates or deletions.
title Text This is the title of the data and will be used for searching on and display within the results.
contents UnStored This is the main content which is used for search and is not displayed.
summary UnIndexed The summary contains information about the search result to display within the results. It is not used
for searching.
createdBy Text The author of the record is used for searching and display. We use the Keyword type as we want to
preserve the author??™s name exactly when searching.
dateCreated Keyword The date created is used for searching and display. We use the keyword type as we do not want
Lucene to parse the data.
The basic code for creating the Zend_Search_Lucene_Document to be indexed is the same no matter what type
of data we are going to be indexing. It looks something like the code in Listing 8.1
Listing 8.1: Adding a document to the search index.
function addToIndex($index, $class, $key, $title, $contents,
$summary, $createdBy, $dateCreated)
{
$doc = new Zend_Search_Lucene_Document(); A
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('class', 1
$class)); 1
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('key', 1
$key)); 1
$this->addField(Zend_Search_Lucene_Field::Keyword('docRef', 1
"$class:$key")); 1
$doc->addField(Zend_Search_Lucene_Field::Text('title', 1
$title)); 1
$doc->addField(Zend_Search_Lucene_Field::UnStored('contents', 1
$contents)); 1
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('summary', 1
$summary)); 1
$doc->addField(Zend_Search_Lucene_Field::Keyword('createdBy', 1
$createdBy)); 1
$doc->addField(Zend_Search_Lucene_Field::Keyword('dateCreated', 1
$dateCreated)); 1
$index->addDocument($doc); 2
}
A Create the search document.
Pages:
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227