By JCM Team on Wednesday, 01 February 2012
Category: February

Developing a Smart Search Plugin

With the Joomla! 2.5 release, a new search component has been included to improve the search engine in Joomla! sites. Based on JXtended's Finder, Smart Search is quite the powerful tool and can be used to improve search results and show the user exactly what they want. Out of the box, Smart Search will work for most core data, but third party developers will have to create their own Finder plugins to interact with Smart Search. Not to worry, I'll help you get started with that now!

What do the Finder plugins do?

The Finder plugins are where the logic is built to search for items and automatically update them during normal site use. Without these plugins, data from a component cannot be indexed and processed during searches from the Smart Search component. This same requirement exists for the "classic" Search component to enable data to be searched.

What do the Finder plugins need?

Each plugin will have its own unique requirements, but there is some code that each plugin requires to allow for proper functioning. In lieu of posting numerous code snippets, I'll instead link you to the Finder plugin for com_content articles at GitHub: https://github.com/joomla/joomla-cms/blob/master/plugins/finder/content/content.php. I encourage you to follow along with the code as I describe it here.

Class Properties and External Dependencies

As you can see just below the file doc block, there are two files that are required to be loaded. The jimport call loads the JComponentHelper class, and this class is used in the index method. Next, the require_once statement loads the Finder plugin's parent class, FinderIndexerAdapter. All Finder plugins must extend this class in order to function properly.

Now, I'll explain each of the class properties set in this plugin, as well as a few properties in the parent class to be aware of:

Additional properties in the parent FinderIndexerAdapter class are:

Class Functions and Parent Information

Next, I'll describe each of the functions in this class as well as important methods to be aware of in the parent FinderIndexerAdapter class. Except for the Finder plugin for working with com_categories, each of these functions feeds into a parent class which contains generic code to update the index properties of an item. Developers who wish to override these functions should carefully review what the parent classes do so that their data is properly handled in all instances.

Methods that developers should be aware of from the parent FinderIndexerAdapter class are:

Note that this is by no means a complete listing of the full API for the Smart Search component, but just a highlight of methods that developers need to be aware of at a minimum to write functioning plugins for their components.

I Have Questions!!!

Undoubtedly, there will be a question or three that will be asked about Smart Search. Obviously, the best resources to use will be the Joomla! Forums (http://forum.joomla.org) and Joomla! WIKI (http://docs.joomla.org). Several pages already exist on the WIKI with information about Smart Search, and I personally frequent the forums and read many of the threads and am willing to help answer questions about Smart Search. So, don't be shy, ask away!

Leave Comments