Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Lucene.Net.ObjectMapping

Mapping of .NET objects to Lucene.Net Documents and vice versa.

Installation

Simply download the Lucene.Net.ObjectMapping NuGet package like this:

Install-Package Lucene.Net.ObjectMapping

You are ready to use the object mapping now.

How To Use It

Uses JSON Serialization to store the object in the Lucene.Net Document, and indexes each property (also nested properties) individually.

Any object that is JSON serializable (using Newtonsoft.Json) can be mapped to a Document, like this:

Document doc = myObject.ToDocument();

Similarly, a Document created like called out above can be converted back into an object like this:

MyClass myObject = doc.ToObject<MyClass>();
// or
object myObject = doc.ToObject();

Since the library stores the actual type of the object when creating a Document, we can always reconstruct the same type of object when deserializing using ToObject, provided that the types can be deserialized from JSON.

You can add your documents to your indices the usual way, or you can add an object to an IndexWriter like this:

myIndexWriter.Add(myObject);
// or
myIndexWriter.Add(myObject, myAnalyzer);

Updating existing documents is just as easy. Like the UpdateDocument method on the IndexReader, it will delete the documents that match the given query and then just add the new document. Use it like this:

myIndexWriter.Update(myObject, new TermQuery(new Term("Id", myObject.Id)));
// or
myIndexWriter.Update(myObject, new TermQuery(new Term("Id", myObject.Id)), myAnalyzer);

Please note that it is not necessary to filter for the document type in your query. The Update method does it automatically.

Search for Documents mapped from a specifc class using the extensions to the Searcher, e.g. like this:

mySearcher.Search<MyClass>(myQuery, numResultsToReturn, mySort);

There are other extensions to the Searcher to, also non-generic ones just in case.

Read More

You can read more about Lucene.Net.ObjectMapping on my blog.

Dependencies

This library depends on the following NuGet packages.

  • Lucene.Net
  • Lucene.Net.Contrib
  • Newtonsoft.Json

About

Mapping of .NET objects to Lucene.Net Documents and vice versa.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages