Add search to a custom cmsms module
-
- Forum Members
- Posts: 40
- Joined: Thu Jul 31, 2008 12:16 pm
Add search to a custom cmsms module
I have a CMSMS module which I developed myself. It was my first module, so I know I'm not using all the built-in hooks, and there are some less-than-elegant pieces of code, but the code has a reasonable amount of comments and is modular. I'm available to explain any code that is impenetrable.
A little info on the module itself:
The module itself is an image gallery. Galleries can be created and deleted with different slot counts and different image orientation. All info is strored in a db except for images and thumbnails. Gallery slots can be populated, cleared and moved (one row to the left or right at a time). Each slot has a text field that can either be a description or a url (the url often points to another sub-gallery).
All I need is for the description to be searchable by the default CMSMS search module. Please give your price or ask any questions. Please note that the job is still at quote stage and will go ahead only if quote is accepted by client.
A little info on the module itself:
The module itself is an image gallery. Galleries can be created and deleted with different slot counts and different image orientation. All info is strored in a db except for images and thumbnails. Gallery slots can be populated, cleared and moved (one row to the left or right at a time). Each slot has a text field that can either be a description or a url (the url often points to another sub-gallery).
All I need is for the description to be searchable by the default CMSMS search module. Please give your price or ask any questions. Please note that the job is still at quote stage and will go ahead only if quote is accepted by client.
Re: Add search to a custom cmsms module
What version of CMSMS are you using. Isnt latest finding content in the module already?
Ronny
Ronny
-
- Forum Members
- Posts: 40
- Joined: Thu Jul 31, 2008 12:16 pm
Re: Add search to a custom cmsms module
It is currently running on 1.4.1.
The description field is not currently showing up in search results. My understanding is that a module needs to programatically add data to the search index - ref http://forum.cmsmadesimple.org/index.ph ... 087.0.html
The description field is not currently showing up in search results. My understanding is that a module needs to programatically add data to the search index - ref http://forum.cmsmadesimple.org/index.ph ... 087.0.html
Re: Add search to a custom cmsms module
OK... programatically ... I am not sure about that. But I recall that latest version, so the 1.5.4 version should have all content searchable... I dont know if a module should do something specific for that...
Ronny
Ronny
-
- Forum Members
- Posts: 40
- Joined: Thu Jul 31, 2008 12:16 pm
Re: Add search to a custom cmsms module
Thanks Ronny, I will upgrade my test system to the latest version and see what happens. I'm doubtful that the search module would blindly index everything that another module puts in a database, because sometimes there would be database fields that you would not want to be indexed, so I think there will probably be coding involved. I am open to correction. I'm interested in hearing any other opinions on this.
Edit: I just installed the module on a new local install of CMSMS 1.5.4 and created a gallery. Search does not index the descriptive text. I still need someone to do the modification.
Edit: I just installed the module on a new local install of CMSMS 1.5.4 and created a gallery. Search does not index the descriptive text. I still need someone to do the modification.
Last edited by turniphead on Wed Apr 15, 2009 11:06 am, edited 1 time in total.
Re: Add search to a custom cmsms module
You may get better results if you provide a link to the module or load your module into the developers forge for others to look at.
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
-
- Forum Members
- Posts: 40
- Joined: Thu Jul 31, 2008 12:16 pm
Re: Add search to a custom cmsms module
tyman00 - I'm reluctant to put the module in the developers forge as I wouldn't want an innocent user to waste time installing it. There are currently some hacks/shortcuts including hardcoded file paths and code which is dependent on certain styles in the stylesheet and jquery.js links in the template. The original module was rushed through for a client, and I intended to make it suitable for public consumption at a later date.
Re: Add search to a custom cmsms module
I see, I am sure those unsuspecting innocent users appreciate that. I was only suggesting that because those that may be able to help you are reluctant to speak up since they don't know what your module looks like.
If all else fails, use a bigger hammer.
M@rtijn wrote: This is a community. This means that we work together and have the same goal (a beautiful CMS), not that we try to put people down and make their (voluntary) job as difficult as can be.
-
- Forum Members
- Posts: 40
- Joined: Thu Jul 31, 2008 12:16 pm
Re: Add search to a custom cmsms module
I take your point. I'm pretty sure the solution is only a couple of lines of code where I populate or update a gallery slot, it would look something like this (which is taken from the forum link I posted earlier):
I actually added code similar to this and I see that the search module database tables are updated. The problem is that the search module has no real documentation. I've looked at the module help and looked at the addwords function code in the search module source, but the code isn't commented and I don't understand the parameters that addwords uses.
Code: Select all
$module =& $this->GetModuleInstance('Search');
if ($module != FALSE)
{
$text = $params['term'].' '.$params['definition'];
$module->AddWords($this->GetName(), $term_id, 'gloassary', $text, NULL); // the last one is the expiry date
}
Re: Add search to a custom cmsms module
What is your status on this? If you pm me the module I can see what I can find.
Re: Add search to a custom cmsms module
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:
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
And, presto, our content will show up in the site search.
Feel free to PM me if you have any questions
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);
}
}
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;
}
Feel free to PM me if you have any questions