DotNetNuke – Make Your Module Searchable

tobj-0105 So far, you know everything you need to know to get a basic module up and running. There are a few items we still need to cover regarding the configuration of your module so that it can have different types of behavior with each instance, but before we get to that, there are a few more higher-level topics we need to discuss with regard to the main view module code. The first of those is how to make the module searchable.

In the original controller that the dotnetnuke module wizard created for you, the class inherits from the ISearchable interface. Because of this, the following method was also added to our controller:

public DotNetNuke.Services.Search.SearchItemInfoCollection
    GetSearchItems(DotNetNuke.Entities.Modules.ModuleInfo
                    ModInfo)
{
    return null;
}

This is the code we need to implement. Right now, it does nothing.

Our job is to create the SearchItemInfoCollection based on information that was passed in with the ModInfo parameter and return it from this method. For a simple module, this will be pretty easy.

The ModInfo parameter has a ModuleId hanging off of it that you can use to retrieve the data that will be in this instance of the module. Once you have the content, you create a SearchItemInfo object and pass in the module title, a description of the content, the user who created the content, the date the content was created, the moduleId, the content we want to be searchable, an optional parameter string and an optional image integer.

In many cases, your code will look like this:

SearchItemInfoCollection searchCollection =
    new SearchItemInfoCollection();
SearchItemInfo searchItem = new SearchItemInfo(title,
    description, author, DateTime.Now, ModInfo.ModuleID,
    string.Empty, Content, string.Empty);
searchCollection.Add(searchItem);
return searchCollection;

However, if your module takes parameters and could display different content based on those parameters, you will need to first retrieve all of the possible content from the database and put the searchItem and searchCollection.Add() code in a loop. This is where the searchKey parameter and the parameter string come in. (The parameter string parameter is called GUID… Charles or Joe, you want to jump in here and comment on why?)

Since each SearchItemInfo needs to be uniquely identifiable to the DNN search engine, we need to add something unique to the searchKey. It may just be a record number. When I created my store modules, I used TabID (also hanging off ModInfo) and ProductId (unique ID of the row I was adding) since it was possible for the row to exist on multiple tabs.

Since this is parameterized data, we need to tell the DNN search engine how to get to this data using a parameter. We do this by passing in the parameter information that will get us to this content. In my case, I set the itemid parameter to the productID to display the detail information of the product,

string guid = String.Format("itemid={0}", row.ProductID);

which I then passed into the GUID parameter so that my resulting searchItem constructor looks like:

SearchItemInfo searchItem = new SearchItemInfo(title,
    description, author, DateTime.Now, ModInfo.ModuleID,
    searchKey, Content, guid);

It’s been several years since I first figured this out, but I think it took me about a day to figure out that the GUID parameter was really a way to let the search engine pass a parameter to my data.

 

Other post in DotNetNuke - Module Development

Related Post

Comments are closed.