I have not implemented anything yet but here is my plan for the built-in search function in MachCMS 1.1.
But first let me clarify something.
Hard pages are pages located on the hard disk in the pages folder.
Virtual pages are pages stored in a local database file. Previously these were referred to as WIKI type pages.
In hard pages, you can use the search functions like this:
$search = new Search;
$search->for(’chocolate’); // This will search all the pages for chocolate.
$search->showResults(); // Display the results of the most recent search in HTML.
$myResults = $search->getResults(); // Return array of results which you can use as you wish.
$search->displayForm(); // Display an HTML search box.
Now how is the search going to work? We are going to use indexing and caching for speed. Whenever virtual pages are saved the index will be updated and there will be a crawl script which goes through all the hard pages and updates the index as needed. The crawler can be run in the background or initiated at will.
The index will be stored in an SQLite database and so will the cache.
The cache will simply store searches and their results so that the index does not have to be searched through again.
Whenever the index is updated, and if the cache references that updated section that part of the cache is removed.
There will be some plugins included as part of this search function. The main reason being PHP code does not work in virtual pages and yet you might want to use search in them.
In hard pages you can still use the plugins but using the PHP classes is a lot more flexible.
Somewhat off topic but there is one more thing to be added about plugins.
What if a plugin wants input?
[plugin:[myPlugin(’input string’)]] For now only one parameter will be allowed. But how will it be delivered to the plugin?
In the PluginName.plugin folder, if your plugin excepts input you must have another file named start.php.
This simple PHP file will define a function which is called by load_plugin().
For example:
global $pluginInput = NULL;
function machcms_PluginName_start($myInput) {
global $pluginInput;
$pluginInput = $myInput;
}
Then in your PluginName.php file you can access the input as $pluginInput. Of course this start function can contain any valid PHP and so can do anything you want before the actual plugin is initiated.