This project is read-only.

Example: Indexing a Document

These are some basic examples of indexing documents using Lucandra.NET. You can also have a look at the unit tests in the solution for more examples.

Prior to indexing data, you will need to create a LucandraWriter, passing the name of your index. The Cassandra endpoint will be taken from the internal connection pool and the keyspace will be automatically chosen based on your Lucandra.NET configuration in your config file.

// Instantiate and open the LucandraWriter.
var indexWriter = new LucandraWriter("MyIndexName");

// Instantiate a Lucene analyzer (you can use any analyzer).
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29);


Document with Single-Valued Fields

var doc = new Document();
doc.Add(new Field("subject", "RE: uninteresting e-mail", Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("body", "This is a very uninteresting e-mail message", Field.Store.NO, Field.Index.ANALYZED));
indexWriter.AddDocument(doc, analyzer);


Document with Multi-Valued Fields

var doc = new Document();
doc.Add(new Field("author", "Someone Cool", Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("title", "A book by Someone Cool", Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("dedication", "Someone Cool's Mom", Field.Store.YES, Field.Index.ANALYZED));
doc.Add(new Field("dedication", "Someone Cool's Dad", Field.Store.YES, Field.Index.ANALYZED));
indexWriter.AddDocument(doc, analyzer);

Last edited Nov 24, 2010 at 9:17 AM by cylwit, version 3

Comments

No comments yet.