Multiple Index Search with Lucene.NET

One of the issues I have run across lately is running a query across multiple Lucene.NET indexes. Although a rather simple exercise, something I had trouble finding help on none the less.

I'm going to assume you have already performed a search across a single index and just start from where you would create load multiple index and search.

To Start out we would need to create a Searchable object. In this exercise we will just assume that there are two indexs located in c:\index1 and c:\index2.

As mentioned before first we create an array of the searchable obj.

Lucene.Net.Search.
Searchable[] _searchables = new Searchable[2];

Next we have to create two index searcher and assign them two the searchables object

_searchables[0] = new IndexSearcher(@"c:\index1");
_searchables[1] = new IndexSearcher(@"c:\index2");

After that we can create a MultSearcher using the array of searchables for the constructor.
Lucene.Net.Search.MultiSearcher searcher = new MultiSearcher(_searchables);

We can now create our 'Hits' object and do our search.
Lucene.Net.Search.Hits hits = searcher.Search(compoundQuery);

After this it's just a matter or building your results.

Happy Coding.


Posted by: Rick Sammons
Posted on: 6/28/2009 at 7:48 PM
Tags: , ,
Categories: Lucene.NET
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed