<?php
require_once "Zend/Search/Lucene.php";
The above code will create a directory folder for search index. There are five files for it:
1. read.lock.file
2. write.lock.file
3. segments_1
4. segments_2
5. segments_gen
$doc->addField(Zend_Search_Lucene_Field::Keyword('link', '<a href="#">Boo</a>'));
$doc->addField(Zend_Search_Lucene_Field::Text('title', 'Hello World'));
$doc->addField(Zend_Search_Lucene_Field::Unstored('contents', 'This is description'));
$index->addDocument($doc);
$index->commit();
echo $index->count()." Documents indexed";
For displaying the result:
$index = new Zend_Search_Lucene('lola');
$query = 'World';
$hits = $index->find($query);
echo "Index contains: ".$index->count()." documents.<br/>";
echo "Search for: \"".$query."\" returned \"".count($hits)."\" hits";
foreach($hits as $hit){
echo "<ul>";
echo "<li>".$hit->link."</li>";
echo "<li>".$hit->title."</li>";
echo "<li>".$hit->score."</li>";
echo "</ul>";
}
This example does not work. :(
ReplyDelete"Notice: Undefined variable: doc". You should define $doc variable. :)
$doc = new Zend_Search_Lucene_Document();
ReplyDelete