background preloader

Lucene

Facebook Twitter

ElasticSearch - Open Source, Distributed, RESTful Search Engine. Lucene.Net. Searcharoo Home. Getting to know Lucene.Net. This is the first post in a series of posts in which I'll describe my investigations of Lucene.Net and subsequently my implementation of it as a search engine on this site.

Getting to know Lucene.Net

This post will deal with the very basics of Lucene, namely performing a very basic search in a console application. Lucene is an open source search engine written in Java and Lucene.Net is a port of it to the .NET platform. You can download it here. Once downloaded you'll find the Lucene.Net assembly in the src\Lucene.Net\bin\Release folder. It is also included in my sample project which is downloadable here. The objective My objective for this post will be to perform the following steps: 1. Importing necessary namespaces The following code will require us to import the following namespaces. using System; Getting to know Lucene.Net part two.

In a previous post (from here on after refered to as "part one") I described a console application that demonstrated the very basics of working with Lucene.NET.

Getting to know Lucene.Net part two

In this second we'll get to know Lucene.NET a little bit better by rewriting that console application so that it will: Persist the index to a directory on a harddrive and Enable us to manually input text that will be indexed and Perform searches from the console Setting up the directory and analyzer The first thing that we'll have to do is import some necessary namespaces and set up a directory for us to work with.

You might recall from part one that a directory is a place where Lucene stores the data we add to it, the Documents. A FSDirectory is created by invoking the static FSDirectory.GetDirectory()-method. We'll also add a StandardAnalyzer as a member variable as it will be used by several of our methods. using System; Getting to know Lucene.Net part three - time to crawl. In previous posts (part one and part two) I talked about adding documents to an index, performing a simple search and saving the index onto a harddrive.

Getting to know Lucene.Net part three - time to crawl

In part two the end result was a simple application that let us add documents and perform searches. In this third post it's time to something atleast semi-usefull, adding real content to the index :) As I mentioned in part one my goal with this series is to implement Lucene.NET as a search engine for this blog. One way to do that would be to listen for events fired by the BlogFactory-class when blog entries and comments are added, updated and removed and then update the index. This would however mean that the search engine wouldn't find other pages that doesn't display entries and if we where to add let's say a forum we would have to modify the search engine to listen to events from the ForumFactory to.

As usual I won't describe every single detail in this post but provide a working sample project. Setting up the solution SetPreferences();