Home » DotNetNuke - Module Development » DotNetNuke – Make Your Module Searchable

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

Like this Article? Subscribe to get every article sent to your email.

Related Post

  • DotNetNuke Modules – Creating Base ModulesDotNetNuke Modules – Creating Base Modules Now that we have DotNetNuke installed into Visual Studio we can go ahead and create our first modules. Actually, creating the modules is pretty simple. But it is even easier to do it […]
  • DotNetNuke Modules – Where Stuff Shows UpDotNetNuke Modules – Where Stuff Shows Up We continue our series on creating DotNetNuke modules today by showing you where the various components of the module we created last week show up in DotNetNuke.Remember, last […]
  • DotNetNuke Modules – Labels w/ no HelpDotNetNuke Modules – Labels w/ no Help While the bulk of the labels you use on a module will be DotNetNuke labels, occasionally you want to be able to put text on the screen that doesn't need context help and doesn't need to be […]
  • DotNetNuke – Modules – Portal Specific ModulesDotNetNuke – Modules – Portal Specific Modules Many of you won't care too much about creating Portal Specific Modules because you'll be creating modules for an environment that only has one portal. However, if you are creating a […]
  • DotNetNuke – Modules – Linking within the moduleDotNetNuke – Modules – Linking within the module Now that we have the module skeleton up and running and we have a data access layer, the next thing we need to look at is specific functions you may need to use from within your code. One […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer. His commitment to quality through test driven development, vast knowledge of C#, HTML, CSS and JavaScript as well as his ability to mentor younger programmers and his passion for Agile/Scrum as defined by the Agile Manifesto and the Scrum Alliance will certainly be an asset to your organization.