Recently we are building a totally new branch of #DNN #Blog #Module – SunBlogNuke based on DNN 7.1 core framework. As you know, DNN7 indeed introduced lots of awesome features, including advanced url rewrite solution. There are more topic about DNN7, however, we just share some interesting things about new class "ModuleSearchBase".

In the beginning, we found the sample code from Html/Text module and built the new search logic. Everything runs well excerpt that the blog post url of search result item always direct to the blog home/main page. It looks weird and we don’t know why. Fortunately, DNN is called “Open Source” without special documents , then finally we can look into the source code and check out how it works.

Deeping into the source code, we found that actually the url of search result item may be built by url or QueryString as the coding below:

if (string.IsNullOrEmpty(searchResult.Url))
    searchResult.Url = Globals.NavigateURL(module.TabID, string.Empty, searchResult.QueryString);

And the source code also tells us how to convert the old "SearchItemInfo" into the new SearchDocument object as follows:

/// -----------------------------------------------------------------------------
/// <summary>
/// Converts a SearchItemInfo into a SearchDocument.
/// 
/// SearchItemInfo object was used in the old version of search.
/// </summary>
/// -----------------------------------------------------------------------------
public SearchDocument ConvertSearchItemInfoToSearchDocument(SearchItemInfo searchItem)
{
    var moduleController = new ModuleController();
    var module = moduleController.GetModule(searchItem.ModuleId);

    var searchDoc = new SearchDocument
    {
        // Assigns as a Search key the SearchItems' GUID, if not it creates a dummy guid.
        UniqueKey = (searchItem.SearchKey.Trim() != string.Empty) ? searchItem.SearchKey : Guid.NewGuid().ToString(),
        QueryString = searchItem.GUID,
        Title = searchItem.Title,
        Body = searchItem.Content,
        Description = searchItem.Description,
        ModifiedTimeUtc = searchItem.PubDate,
        AuthorUserId = searchItem.Author,
        TabId = searchItem.TabId,
        PortalId = module.PortalID,
        SearchTypeId = ModuleSearchTypeId,
        CultureCode = module.CultureCode,
        //Add Module MetaData
        ModuleDefId = module.ModuleDefID,
        ModuleId = module.ModuleID
    };

    return searchDoc;
}

So our problem fixed by adding the field “QueryString” when building the object SearchDocument:

var searchDoc = new SearchDocument
{
    PortalId = modInfo.PortalID,
    UniqueKey = item.EntryID.ToString(),
    QueryString = "entryid=" + item.EntryID.ToString(), // Used to creare Url for the document
    Title = item.Title + " - " + item.CurrentBlog.Title,
    Description = description,
    Body = item.Content,
    ModifiedTimeUtc = item.LastModifiedOnDate.ToUniversalTime(),
    Tags = new List<string>(item.Tags.Split(',')),
    AuthorUserId = item.CreatedByUserID
};

BTW, our blogging module #SunBlogNuke v7.0 will be released soon and it provides unique friendly url based DNN Advanced Url Solution.

Related resources:

http://www.dnnsoftware.com/community-blog/cid/154913/integrating-with-search-introducing-modulesearchbase

http://www.dnnsoftware.com/wiki/page/modulesearchbase