I found a script written back in 2006 that tested the iSearchable interface to see what the module is supplying to the DNN Search Provider. Unfortunately this script didn’t work for me so I spent a few days trying to find out why it worked and how to make it work again.
Here is an updated version (in C#) that works with DNN 5.x – Tested with Community Edition.
File: DNNSearch.aspx
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”DNNSearch.aspx.cs” Inherits=”DNNSearch2″ %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head id=”Head1″ runat=”server”>
<title>Speerio ISearchable Test</title>
<style>
body, p {font-family: Verdana; font-size: 9pt}
</style>
</head>
<body>
<p><font size=”4″>DNNSearch Script – by <a href=”http://www.speerio.net”>Speerio, Inc.</a>, Updated by Info66.net</p>
<p><font color=”red” size=”4″>WARNING: Do not leave this script installed on a production system.</font></p>
<form id=”Form2″ method=”post” runat=”server”>
<p>Tab ID: <asp:TextBox ID=”TabId” Runat=”server”></asp:TextBox></p>
<p>Module ID: <asp:TextBox ID=”ModuleId” Runat=”server”></asp:TextBox></p>
<asp:Button ID=”Results” Runat=”server” Text=”Get Search Results” /></p>
<p>To test for user-specific results, add code to GetSearchItems() to check for userid=N in querystring.</p>
<p><b>Search Results:</b></p>
<asp:Label ID=”SearchResults” Runat=”server” />
</form>
</body>
</html>
File: DNNSearch.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DotNetNuke;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;
using DotNetNuke.Common;
using DotNetNuke.Framework.Providers;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Services.Exceptions;
using System.Text;
public partial class DNNSearch2 : System.Web.UI.Page
{
void Results_Click(object sender, EventArgs e)
{
int moduleId = -1;
try
{
moduleId = Convert.ToInt32(ModuleId.Text);
}
catch
{
}
int tabId = -1;
try
{
tabId = Convert.ToInt32(TabId.Text);
}
catch
{
}
if ((moduleId > -1) && (tabId > -1))
GetSearchResults(moduleId, tabId);
else
SearchResults.Text = “Both Module ID and Tab ID are required”;
}
void GetSearchResults(int moduleId, int tabId)
{
ModuleController moduleController = new ModuleController();
ModuleInfo moduleInfo = moduleController.GetModule(moduleId, tabId);
StringBuilder sb = new StringBuilder();
if (moduleInfo == null)
{
SearchResults.Text = “No module found with ModuleID=” + moduleId.ToString() + ” and TabID=” + tabId.ToString();
return;
}
if (moduleInfo.BusinessControllerClass == “”)
{
SearchResults.Text = “The Business Controller Class in the database is blank.”;
}
else
{
try
{
object bizController = DotNetNuke.Framework.Reflection.CreateObject(moduleInfo.BusinessControllerClass, moduleInfo.BusinessControllerClass);
if (bizController == null)
{
SearchResults.Text = “The Business Controller Class <b>” + moduleInfo.BusinessControllerClass + “</b> could not be instantiated.”;
}
else
{
ISearchable iS = (ISearchable)bizController;
SearchItemInfoCollection results = iS.GetSearchItems(moduleInfo);
if (results != null)
{
int counter = 0;
foreach (SearchItemInfo searchItem in results)
{
if (moduleInfo.ModuleID == searchItem.ModuleId)
{
sb.Append(“<p>Title: “ + searchItem.Title);
sb.Append(“<br>GUID: “ + searchItem.GUID);
sb.Append(“<br>Date: “ + searchItem.PubDate.ToLongDateString());
sb.Append(“<br>Description: ” + searchItem.Description + “</p>”);
}
else
{ // If SearchModuleId == 0, no worky worky… =( — Added because of this
sb.Append(“<p>ModuleId = “ + moduleInfo.ModuleID.ToString());
sb.Append(“<br />SearchModuleId = ” + searchItem.ModuleId.ToString());
sb.Append(“<br />Title: “ + searchItem.Title);
sb.Append(“<br />GUID: “ + searchItem.GUID);
sb.Append(“<br />Date: “ + searchItem.PubDate.ToLongDateString());
sb.Append(“<br />Description: ” + searchItem.Description + “</p>”);
}
counter++;
}
SearchResults.Text = counter.ToString() + ” results found.<br>” + sb.ToString();
}
else
{
SearchResults.Text = “No search results.”;
}
}
}
catch (Exception e)
{
SearchResults.Text = “Error: “ + e.Message + “<br><br>” + e.StackTrace;
}
}
}
override protected void OnInit(EventArgs e)
{
Results.Click += new EventHandler(Results_Click);
base.OnInit(e);
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
Original Article and Script is located at the DotNetNuke Community Blogs and posted by Nik Kalyani - (I just modified it to work with DotNetNuke 5. I still don’t know why the original didn’t work as the object that failed is in the source code still.)
Download Files: ASPX, CS