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

Other Related Items:

Transcend IDE Flash Module Vertical - Solid state drive - 512 MB - internal - IDETranscend IDE Flash Module Vertical - Solid state drive - 512 MB - internal - IDETranscend's IDE Flash Modules are specially designed for use in the demanding industrial environments where industrial PCs, Set-Top Boxes and other computer systems must operate. IDE Flash Modules are a convenient and easy to use solution for expanding an industrial computer's memory capacity.
Beginner's ASP.NET in C# 2003 on DVDBeginner's ASP.NET in C# 2003 on DVDASP.NET 2003 represents an important technology for building enterprise level web applications. Learn the basics of ASP.NET development as you watch a... Read More >
Beginner's ASP.NET in VB.NET 2003 on DVDBeginner's ASP.NET in VB.NET 2003 on DVDASP.NET (VB.NET) 2003 represents an important technology for building enterprise level web applications. Learn the basics of ASP.NET development as yo... Read More >

Related Post

Comments are closed.

DotNetNuke Sponsor

 

Most Valuable Blogger
Sponsor