Mnogosearch Search Engine PHP5 Class
I love search engines. One of my favorites is the mnogosearch engine that I’ve been using since Mark Joyner’s Aesop.com. In this article, I present a some object-oriented PHP code that can be used to access the search results.
Recently, I had the chance to re-visit the need to create a vertical search engine portal for a project I’m working on. I was pleasently surprised to find out the mnogosearch is still one of the “better” search engines for small to medium sized sites – up to a few million documents (though I’ve scaled it well beyond that in the past ;->).
The PHP native extension has recently (late 2010) been updated with new features, and I was able to get it compiled and running – including a few test sites indexed – in just a few hours.
The php example code worked right out of the box. A problem, though, was that looking at the very functional style of coding, it was somewhat difficult to extract what actually was part of the search process and what was UI.
So, as a learning exercise I set out to create a basic “object oriented” wrapper around the extension. While the class is somewhat verbose, it does better encapsulate the actual functions and settings available within the extension.
This directly allows my ide (Nusphere PHPed) to tell me what functions I have available from the class (and underlying mnogosearch extension) directly from the IDE. It also helps with code completion, and makes displaying results in a template very easy.
I’ve uploaded the class, as well as a mostly-complete rewrite to github, you can find it here:
I’d call this a “version 0” piece of code – it works, but hasn’t been cleaned up, and is very much subject to change. The interface needs some features, should be a little more consistent, and the resultset code needs some more options. The updated search.php has a few places that need some work, most notably in [not] handling the cached files nor dictionaries / stopwords. Additional inline documentation could be a bonus improvement as well.
Feel free to clone the repository on github, and I’ll merge changes back as they are available.
If you are using mnogosearch, and if you find the extension class useful, please comment here.