Gokul's Blog

Lucene, .Net & Full Text Search in General

Leave a comment

This post is a work in progress

Update added a new presentation from ndc2012

https://github.com/synhershko/Talks/tree/master/LuceneNeatThings

Good articles:

Another good Search  Engine tool with .net Support: 
Using latest version of Lucene: http://www.wickedsoftware.net/lucene-net/lucene-net-refresher
How to store Key Fields (Link)
There are many out-of-date examples out there on deleting with an id field. The code below will work with Lucene.NET 2.4.It’s not necessary to open an IndexReader if you’re already using an IndexWriter or to access IndexSearcher.Reader. You can use IndexWriter.DeleteDocuments(Term), but the tricky part is making sure you’ve stored your id field correctly in the first place. Be sure and use Field.Index.NOT_ANALYZED as the index setting on your id field when storing the document. This indexes the field without tokenizing it, which is very important, and none of the other Field.Index values will work when used this way:

IndexWriter writer = new IndexWriter("\MyIndexFolder", new StandardAnalyzer()); var doc = new Document(); var idField = new Field("id", "MyItemId", Field.Store.YES, Field.Index.NOT_ANALYZED); doc.Add(idField); writer.AddDocument(doc); writer.Commit(); 

Now you can easily delete or update the document using the same writer:

Term idTerm = new Term("id", "MyItemId"); writer.DeleteDocuments(idTerm); writer.Commit();
Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s