Build your own search engine in PHP

Do you know how to build your own search engine in PHP? It is not that hard, because there are already some ready-to-use pieces, like Lucene. You just have to think how you want your search engine to work exactly and build the pieces together.Of course, you can't do in 15 minutes what others took years, but I want to give you just a few hints of how to create your own search functionality. You could use this to index the web, and if you do, let me know so I can stop using Google.But of course, this stuff can also be used to create your own vertical or horizontal search engine. The magic word is Lucene. Hey, I'm following livestream of The Next Web, for which day 2 will start at 10:30. So, read on and try writing some cool things, or watch the stream for some inspiration (many startups with short presentations) and get back later to convert your idea to reality. So what is this about? Recently, I wrote an article of using the Zend Framework in CakePHP. This is pretty easy, and I'm still trying Zend components for use in CakePHP. I wrote a little example site (locally) at which you can login using your openID and view some del.ici.ous stuff.Yesterday, I tried Zend_Search_Lucene. I just gave it a try, because it triggered my curiosity. Of course, you first have to integrate the Zend Framework in your CakePHP installation. I assume you already have a controller. In that controller, create a function search:function search($query = "cake") { vendor('Zend/Search/Lucene'); if ($query == "build") { $index = Zend_Search_Lucene::create('/tmp/my-index'); $url = ""; $doc = Zend_Search_Lucene_Document_Html::loadHTMLFile($url); $doc->addField(Zend_Search_Lucene_Field::Text('url', $url)); $index->addDocument($doc); $i = 1; foreach($doc->getLinks() as $link) { $current_doc = Zend_Search_Lucene_Document_Html::loadHTMLFile($url.$link); $current_doc->addField(Zend_Search_Lucene_Field::Text('url', $url.$link)); echo "{$link}"; $index->addDocument($current_doc); $i++; if ($i >= 10) break; } } $index = Zend_Search_Lucene::open('/tmp/my-index'); $hits = $index->find($query); $this->set('hits', $hits); }Two things, you create the index by calling /controller/search/build. The first URL is opened and added to the index. The first ten links in that page are also analyzed and add to the index.After you build your index, use it like /controller/search/php.So, this is a very short example of how to use CakePHP and the Zend Framework to create your own searchable index. You could use it to create your own search engine for the web, your website, or any other application with search functionality.Want me to help implementing this in your application? Just contact me!