How to create a search engine based on Lucene in Zend Framework 2.5

As I promised, I have developed a very simple search engine based on Lucene. It works very well and you can see the code bellow.

This is my action:

public function searchAction()
// here I will require the Search form
$form = new SearchForm();
// here I will create a Lucene's index
$index = Lucene::create('/indexes');
$users = $this->getAlbumTable()->fetchAll(true);
foreach($users as $user)
$doc = new Document();
$doc->addField(Document\Field::Text('artist', $user->artist));
// here I will search in the saved Lecene's index
$term = $this->params()->fromQuery('query', false);
$term = "";
$index = Lucene::open('/indexes');
$results = $index->find($term);
return new ViewModel(array(
'results' => $results,
'form' => $form

In this month I'm going to develop a very big open source project in Zend Framework 2.5 where you will find out the entire code of my search engine based on Lucene!

Leave a Comment