Page 1 of 1

Improve the search API for plugins

Posted: Thu Aug 06, 2015 11:48 am
by cmb
Hi everybody!

As of XH 1.6 the search functionality was moved from cmsimple/search.php to cmsimple/classes/Search.php. To still allow plugins to replace the search functionality, the core looks for cmsimple/search.php and if found uses this instead of the Search class.

This gives plugins great flexibility, but also requires the plugin author to duplicate much of the standard search functionality, and keep it up-to-date. Furthermore there are issues, if more than one plugin would want to extend the search, and generally it doesn't seem to be a good idea that during the installation of a plugin changes to the cmsimple/ folder have to be made (for once, it is too easy to forget to undo them when the plugin will be uninstalled).

I can imagine that there are several plugins for which it would make sense to extend the search to their own contents. For instance, Coco_XH delivers a custom search.php which also searches the co-contents. Other plugins that come to mind are Forum_XH, Realblog_XH (currently has an own search functionality), Calendar, etc.

IMO we should offer an easy way for interested plugins to hook into the search, so they can search their own contents, and return results, which are then added to the standard search results. Without having thought this completely through, it might be reasonable to have a class SearchResult which encapsulates a single hit (URL, title, description, priority), so a plugin could gather an array of SearchResults and pass it to the standard search. The registration (hook) might be simply done by calling a function, say XH_registerSearch($callable).

Thoughts?