Aricie
The DNN Expert for your web project
Aricie Blog

Providers in LuceneSearch: part 3 - going solo

Jan 03 2013

Previously...

For the third part of our series on LuceneSearch providers, we will look into the standalone provider system which allows you to add data coming from different sources into Lucene without being tied to a module. Your providers can add content from a filesystem, a database, index data coming from twitter, pretty much whatever you can think of.

Creating a standalone provider

At its root, the standalone provider is very simple to create: just declare a class that will implement the ILuceneStandAloneSearchable interface. This interface contains a method that will let you return a SearchItemInfoCollection just as the ISearchable interface does.

    class TeamCreditsProvider : ILuceneStandAloneSearchable
    {
        public SearchItemInfoCollection GetSearchItems(int portalId)
        {
            var results = new SearchItemInfoCollection();
            results.Add(new SearchItemInfo() 
            { 
                Title = "Samy", 
                Description = "Team member information",
                Content = "There could be a short bio here"
            });
            return results;
        }
    }

However, returning the SearchItemInfo class is fairly limiting since you will only be able to fill in the basic fields of your search structure. Using the LuceneSearchItemInfo will be a better way to return custom data; here is the above provider changed to set the url to the Aricie website:

    class TeamCreditsProvider : ILuceneStandAloneSearchable
    {
        public SearchItemInfoCollection GetSearchItems(int portalId)
        {
            var results = new SearchItemInfoCollection();
            results.Add(new LuceneSearchItemInfo(portalId)
            { 
                Title = "Samy", // Title of our search item
                Description = "Team member information",
                Content = "There could be a short bio here",
                ForcedUrl = "http://www.aricie.com" // we set the search item url to the Aricie website
            });
            return results;
        }
    }
Your items must be tied to a portal to be displayed in the search results. However your provider can add the same items to each portal if you want to return the same data on all portals.

That is all there is about a standalone provider; you can use whichever codebase to add data to your search index by bringing in third party libraries or custom code so pulling data from whichever source will depend on what you feel more comfortable with. You can add or change some behaviors to the provider:

  • Implementing the ILuceneFieldGlossary interface allows you to define the fields that will be used by your porvider, just as you would for a standard provider.
  • In our second article we saw the difference between first-pass indexing and second-pass indexing (ie. upgrading); you can do the same for your standalone provider by implementing the ILuceneStandAloneProgressiveSearchable interface. This interface lets you do both steps with a standalone provider.

Configuring a standalone provider

The standalone provider is configured by the same fields already used for the configuration of standard providers. However, since standalone providers are not tied to any module, DotNetNuke cannot display their data. LuceneSearch lets you configure custom details view for the standalone providers so you can display custom items to the users. The two fields that will be added to the configuration are :

  • LinkToDetails: this setting is a boolean which lets you toggle the details view for the items indexed by this provider.
  • DefaultDetailsTemplate: you can define a template using the same token system as the results use; in the near future the template system will be consolidated at a unique place but for now it lives in the confriguration file.

Conclusion

In these three posts we took a comprehensive look at how providers work and how you can write your own to add the data you need to your website. There are some providers which will be added in the future, such as reflexive providers that are able to look at what is being indexed in order to add some more data to the search index; they can be used to spider the data being returned and index the content of documents or extenal links. In fact there's already such a provider existing in LuceneSearch but since its integartion is not yet completed we'll look at it in a possible next part for this series.

Bloggers
Jesse's blog
 Jesse
 1  9  12/6/2014
Musings without a muse
 samyb
 6  101  1/3/2013
Stephane DNN Blog
 Stéphane TETARD
 1  5  4/23/2012
Categories