Cuyahoga's Search Implementation

written by SilkRoad on Sunday, January 06 2008

  As new content, such as as a new article, forum topic, or blog post is added to a website it must also be added to the search index to enable users to search for it. Some websites keep their search indexes updated with a scheduling mechanism that periodically scans and indexes all of a websites content. The Cuyahoga website framework uses a different approach. It provides the ability to instantly index content as it is added to a website by triggering events with C# delegates. This post explains how Lucene.Net is used by Cuyahoga.

New content is added through an admin page the base class of which executes the code below upon initialization. The entire class can be viewed here from Koders a code search web application that is also powered by Lucene.Net.

// Optional indexing event handlers
if (this._module is ISearchable 
    && Boolean.Parse(Config.GetConfiguration()["InstantIndexing"]))        
{
    ISearchable searchableModule = (ISearchable)this._module;
    searchableModule.ContentCreated += 
                     new IndexEventHandler(searchableModule_ContentCreated);
    searchableModule.ContentUpdated += 
                     new IndexEventHandler(searchableModule_ContentUpdated);  
    searchableModule.ContentDeleted += 
                     new IndexEventHandler(searchableModule_ContentDeleted);
}

Cuyahoga has a modular architecture and functionality like fourms, and articles are implemented as seperate module components. Im interested in learning how Cuyahoga implements a plug-in architecture and may post my notes on it here later, but for now all we are concerned with is that in order for a module to allow its contents to be searched it must implement the ISearchable interface:

namespace Cuyahoga.Core.Search
{
    public interface ISearchable
    {
        event IndexEventHandler ContentCreated;
        event IndexEventHandler ContentUpdated;
        event IndexEventHandler ContentDeleted;
        SearchContent[] GetAllSearchableContent();
    }
}

Cuyahoga's Articles module, for instance, has events for content creation, deletion, and updates as well as a method that converts its content into a SearchContent object(described in a previous post).  When a new article is added the article module's SaveArticle method converts the article's text into SearchContect object, and passes it to its ContentCreated event as a paramter. This triggers the admin page's event handler which hands it off to a class that uses the Lucene.Net APIs to update the index with the new content. 

Similar Posts

  1. Search in C# with Lucene.Net / DotLucene
  2. Breaking Apart at the Seams
  3. Project Management Software

Comments are closed

Options:

Size

Colors