There are some full examples in the test project at https://github.com/themotleyfool/Lucene.Net.Linq/tree/master/source/Lucene.Net.Linq.Tests/Samples.
Once you've configured your mappings and initialized your provider, you make updates by opening a session:
var directory = new RAMDirectory();
var provider = new LuceneDataProvider(directory, Version.LUCENE_30);
using (var session = provider.OpenSession<Article>())
{
session.Add(new Article {Author = "John Doe", BodyText = "some body text", PublishDate = DateTimeOffset.UtcNow});
}
You can also update existing documents. Simply retrieve the item from the session, and the session will detect if a modification was made:
using (var session = provider.OpenSession<Article>())
{
var item = session.Query().Single(i => i.Id == someId);
item.Name = "updated";
}
Or you can delete documents:
using (var session = provider.OpenSession<Article>())
{
var item = session.Query().Single(i => i.Id == someId);
session.Delete(item);
}
When the session is disposed, all pending changes in the session are written to the index and then committed. This is done within a synchronization context to ensure all changes in the session are committed and seen atomically when queries are being executed on other threads.