It turns out that this is not that difficult, once you know what to do. After a lot of digging around in other classes, I've figure out the below. I'm working with CMSMS 1.5.4 and before I did the following my custom module was not seen by the Search module.
In order to make your module's content appear in the search results, you need to implement the following two methods in your module.
SearchReindex(&$module) and SearchResult($returnid, $id, $result_type = '')
Here is a description of the arguments for each method and what they're expected to return
SearchReindex:
It has one argument, which is a reference to an instance of the Search module object. The Search module has one method that you'll be using, 'AddWords', which requires at least the following four arguments:
1) Name of your module
2) Unique ID for your content
3) a string identifying this type of content (such as 'program' or 'sports_score')
4) a string describing the content. This is the string that will be searched against to return this content. Note that this string is never visible to site visitors. Its just important to get all the words you want related to this row in here
So, say your module is called SportsScores. It has a database backend with rows that contain the name of the game, some arbitrary description of the game, and two VARCHAR columns identifying the teams playing (yes, this is not an optimal way of handling this data, but for the sake of this example...). Given this situation, you might want to implement SearchReindex in your module in the following manner:
Code: Select all
function SearchReindex(&$module)
{
$sql = ... (sql code to get all the rows you want to be visible to the site's search)
$db =& $this->GetDb();
$rows =& $db->GetAll($sql);
$module_name = $this->GetName();
// Now iterate through all returned rows
foreach ($rows as $item)
{
$unique_id = $item['sport_score_id']; // Keep track of a unique identifier for this piece of data
$descriptive_string = $item['game_name'].' '.$item['game_description'].' '.$item['team_one'].' '.$item['team_two'];
$module->AddWords($this->GetName(), $item['sport_score_id'], 'sport_score', $descriptive_string, NULL);
}
}
Now that we've told the search module what content our module will be providing, we need to tell the search module how to deal with the results we get. This is through the 'SearchResult' method in our module.
The SearchResult method receives three arguments and must return an array
Code: Select all
function SearchResult($returnid, $id, $result_type = '')
{
$result = array();
if ($result_type === 'sport_score') // Make sure this is an item we know how to deal with
{
$sql = ... // generate SQL to retreive the data associate with the $id
$db =& $this->GetDb();
$row = $db->GetRow($sql);;
if ($row) // Make sure we have a valid result
{
// If we have a valid result, we need to return an array with
// the following three items in it: the name of our module, a descriptive name of our content, and the URL for our content
$result[0] = $this->GetFriendlyName(); // The user displayable name of the module that handles this content
$result[1] = $row['name']; // The user displayable name of this content, such as 'Chicago White Sox vs. Boston Red Sox'
$result[2] = ... // URL that the this link should take the site user to. Content will depend on whether you have clean URLS enabled
}
}
// Return the result, either an empty array if we don't want to, or don't know how to
// deal with this result, or our array of the above three items if we do
return $result;
}
And, presto, our content will show up in the site search.
Feel free to PM me if you have any questions