Blog

horizontal line graphic

Subscribe to Kevin Southworth's Blog  Subscribe to my RSS feed | Categories | Search

Modifying the DotNetNuke SearchResults module

Wednesday, January 24, 2007 @ 1:48 AM :: 317 Views :: 0 Comments ::
Categories: DotNetNuke

Today I was working on a client''s website, trying to integrate an event calendar system that we have with their DotNetNuke site search.  The DNN site search input and search results are actually two different modules.  The problem is that our events system is a separate application with its own database. The challenge was to make the DNN site search include the events from our external system in the search results in such a way that visitors wouldn''t know the difference between DNN results and our event system results.  There are probably numerous ways to accomplish this, but we needed a very quick turnaround time and it had to look like it was still part of DNN.  So here''s what I did:

  1. Created a  stored procedure in the events database that would accept a "searchWords" parameter and would return the relevant rows
  2. Downloaded the "source" version of DotNetNuke 3.2.2 from the dotnetnuke website www.dotnetnuke.com
  3. Opened the VS solution file inside "\Solutions\DotNetNuke.Providers"
  4. Opened "SearchDataStore.vb" inside the "Provider.Search.DataStore" project
  5. Appended my custom search code onto the end of the "GetSearchResults" function (which starts at line 336 of the .vb file) I inserted my code right before the return statement. The basic steps for this part are:
    1. Call your stored procedure or whatever code you''re going to use to do your custom search, passing it the "Criteria" variable (provided by DNN)
    2. Loop through your results and create a "SearchResultsInfo" object for each result and add it to the "Results" collection which is of type "SearchResultsInfoCollection"

    1 // create SqlConnection, SqlCommand, SqlReader, etc.

    2 SqlDataReader reader = new SqlReader()

    3 // Fill your DataReader, other code omitted...

    4 While (reader.Read())

    5     Dim eTitle As String

    6     Dim eDesc As String

    7     eTitle = reader.GetString(4)

    8     eDesc = reader.GetString(1)

    9 

   10     Dim myResult As New SearchResultsInfo

   11     myResult.Author = "Kevin S."

   12     myResult.AuthorName = "Kevin S."

   13     myResult.Guid = "111" //fake/placholder

   14     myResult.Image = 0

   15     myResult.ModuleId = 367 //should be a real moduleId

   16     myResult.Description = eDesc

   17     myResult.Occurrences = 1

   18     myResult.PubDate = reader.GetDateTime(2)

   19     myResult.Relevance = 1000

   20     myResult.TabId = 36 // should be a real tabId

   21     myResult.Title = eTitle

   22 

   23     Results.Add(myResult)

   24 End While

You''re done!  DNN will use the info you specify for each SearchResultsInfo object to build a URL and link your search results to the Tab you specified automatically.  As you can see a lot of the values I used are just placeholders/filler in this case, since my custom search results don''t really pertain to a particular "tab" or "moduleid".  I''m sure there are more "provider-like" ways to customize the DNN search without modifying the DNN core source code, but this was the quickest way I found today :)

Rating
Comments
Currently, there are no comments. Be the first to post one!
Click here to post a comment