PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Creating a New Index

Index creation and updating capabilities are implemented within the Zend_Search_Lucene component, as well as the Java Lucene project. You can use either of these options to create indexes that Zend_Search_Lucene can search.

The PHP code listing below provides an example of how to index a file using Zend_Search_Lucene indexing API:

<?php
// Create index
$index Zend_Search_Lucene::create('/data/my-index');

$doc = new Zend_Search_Lucene_Document();

// Store document URL to identify it in the search results
$doc->addField(Zend_Search_Lucene_Field::Text('url'$docUrl));

// Index document contents
$doc->addField(Zend_Search_Lucene_Field::UnStored('contents'$docContent));

// Add document to the index
$index->addDocument($doc);

Newly added documents are immediately searchable in the index.

Zend Framework