Forum search on Engage

Posted on Tuesday 10. November 2009 by Lars Hejgaard Sørensen at 14:40

On the old developer site we received a lot of well-deserved criticism of the poor searching abilities in the forum, so this was one of the points I wanted to change for the new site. I wanted to be able to search in all forums, single forums and display only one result per thread by using the global search on the site. So I had to somehow implement search of Forum V2 in Search, Weighted, which turned out to be a bit more challenging than initially anticipated, but still not impossible:)

The Search, Weighted modules supports search in custom modules by registering the table (or view for that matter) that holds the data for the module. Check out this article for further details on implementing search in custom modules. But since Forum V2 data is stored in two tables, ForumV2Thread and Forumv2Post, and the latter could in theory contain an unlimited amount of records, not even running the search on a view would do the trick.

So, I admit, I had to go for a slightly dirtier way. I added a new field to the ForumV2Thread table called ForumV2ThreadCustomSummary. I then set up a trigger on the table to store all relevant information in this field whenever an INSERT, UPDATE or DELETE action was performed on the ForumVPost table. The Trigger first removes the content of ForumV2ThreadContentSummary and then writes the content of ForumV2ThreadHeadline, ForumV2ThreadDescription, and ForumV2ThreadText to the field.

Then I go through all records in the ForumV2Post table that have ForumV2PostThreadID equals to the record that affected the trigger

That way all relevant data in ForumV2Thread and ForumV2Post is stored in one single field that Search Weighted can use to search. You’ll find the complete code for this trigger attached to this article.

I could have achieved the same effect by creating a Stored Procedure, but I figured that using this approach I would get better performance on the actual search and have the bulk of the work done when a new forum entry is made.

Implementing search

Using the Dynamicweb Developer module I registered a pro forma module called forumV2Search and implemented search in this module from the recommendations in the article mentioned earlier. This new module cannot be attached to a module, and there’s no script associated with this module, so it’s practically dead besides allowing search on it.

Module registration

I entered the appropriate values to implement the search for this module, and now I had a way to search the content of Forum V2 which normally is not supported.

Search setup

Next step was making a way to search only in a specific forum. I could have used off-the-shelf functionality by setting up individual search pages for each forum, which would have been hell to maintain although they may not change very often. Instead I used an undocumented feature in the Search V1 module that allows me to overrule the paragraph settings.

This is the normal form used for searching the Engage site.

The fields look like something we often see in Dynamicweb URLs, but let’s just look at the briefly.

Name Meaning
ID The target page we want to navigate to.
PID The ID of the paragraph from where we want to load the paragraph settings.
M The module we want to use. When specified, only this paragraph will be shown on the page.
Q The phrase we want to search for


By measuring the CategoryID parameter in the query string we’re able to determine that we are in a specific forum category. We assume that the CategoryID parameter is only used in ForumV2, so if this parameter is present, we make a few additions to the form.

Let’s just look at the meaning of the new fields.

Name Meaning
SearchV1ForumV2Search By applying the value “Specified” we state that we want to search the custom module called SearchV1ForumV2Search
SearchV1ForumV2Search The current category. We get this from the requests paramteres of the template class
SearchV1ForumV2SearchPageID The page where the ForumV2 module is attached so we can navigate from the search result to the actual entry
SearhV1SearchPages By leaving this blank, we exclude search in page content allowing us to search only forum content


The final output of the form is then:

These fields have the exact same naming as the appropriate configuration fields of the Search Weighted module – you can see those using “View source” on the module paragraph setup page. The Search Weighted module checks for these fields in the Request collection when performing searches on custom modules, thus allowing us to manipulate with the settings directly in our template.

I hope that after reading this article you’ll find better use for the Search Weighted module in relation to custom modules. I this example we mix standard and custom search data and even split it up to display custom data exclusively, all by using one single search box on the web site. The latter example alone is quite a time saver if you’re satisfied with standard output of the Search Weighted module.

Attached files

Copyright 2010 Dynamicweb Software