Lucine.Net

Tutorial:

http://www.d80.co.uk/post/2011/03/29/LuceneNet-Tutorial.aspx

The basic library can be installed via NuGet

There is a simple https://github.com/ajorkowski/AzureDataCacheDirectory that should just work.

This uses the Azure Cache service to store the Lucene Indexes.

I am planning to test this on the local emulated cache to see if it works.

This is a minor update to the supplied sample (Lucene has fixed the naming conventions to confirm to C# norms):

using Lucene.Net.Analysis;
using System.IO;

using Directory = Lucene.Net.Store.Directory;
using Version = Lucene.Net.Util.Version;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;

var fordFiesta = new Document();
fordFiesta.Add(new Field(“Id”, “1”, Field.Store.YES, Field.Index.NOT_ANALYZED));
fordFiesta.Add(new Field(“Make”, “Ford”, Field.Store.YES, Field.Index.ANALYZED));
fordFiesta.Add(new Field(“Model”, “Fiesta”, Field.Store.YES, Field.Index.ANALYZED));

var fordFocus = new Document();
fordFocus.Add(new Field(“Id”, “2”, Field.Store.YES, Field.Index.NOT_ANALYZED));
fordFocus.Add(new Field(“Make”, “Ford”, Field.Store.YES, Field.Index.ANALYZED));
fordFocus.Add(new Field(“Model”, “Focus”, Field.Store.YES, Field.Index.ANALYZED));

var vauxhallAstra = new Document();
vauxhallAstra.Add(new Field(“Id”, “3”, Field.Store.YES, Field.Index.NOT_ANALYZED));
vauxhallAstra.Add(new Field(“Make”, “Vauxhall”, Field.Store.YES, Field.Index.ANALYZED));
vauxhallAstra.Add(new Field(“Model”, “Astra”, Field.Store.YES, Field.Index.ANALYZED));

using (RAMDirectory directory = new RAMDirectory())
{
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30);

var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
writer.AddDocument(fordFiesta);
writer.AddDocument(fordFocus);
writer.AddDocument(vauxhallAstra);

writer.Optimize();
writer.Close();

IndexReader indexReader = IndexReader.Open(directory, true);
using (Searcher indexSearch = new IndexSearcher(indexReader))
{
var queryParser = new QueryParser(Version.LUCENE_30, “Make”, analyzer);
var query = queryParser.Parse(“Ford”);

Console.WriteLine(“Searching for: ” + query.ToString());
TopDocs resultDocs = indexSearch.Search(query, indexReader.MaxDoc);

Console.WriteLine(“Results Found: ” + resultDocs.TotalHits);

var hits = resultDocs.ScoreDocs;
foreach (var hit in hits)
{
var documentFromSearcher = indexSearch.Doc(hit.Doc);
Console.WriteLine(documentFromSearcher.Get(“Make”) + ” ” + documentFromSearcher.Get(“Model”));
}

}
}

I have a sample app that uses the Azure Cache As A Service version:

https://github.com/chriseyre2000/Study/tree/master/azure/Lucene/

You need to supply your own cache service id and authentication string.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s