转自:http://blog.sematext.com/2010/02/09/lucandra-a-cassandra-based-lucene-backend/
GitHub地址:http://github.com/tjake/Lucandra/blob/master/README
关于Lucandra的介绍:
What is Cassandra?
- It has no single point of failure, and
- Adding nodes to the cluster is as simple as pointing it to any one live node
Cassandra also has built-in multi-master writes, replication, rack awareness, and can handle downed nodes gracefully. Cassandra has a thriving community and is currently being used at companies like Facebook, Digg and Twitter to name a few.
Enter Lucandra
Lucandra is a Cassandra backend for Lucene. Since Cassandra’s original use within Facebook was for search, integrating Lucene with Cassandra seemed like a “no brainer”. Lucene’s core design makes it fairly simple to strip away and plug in custom Analyzer, Writer, Reader, etc. implementations. Rather than trying to build a Lucene Directory interface on top of Lucene as some backends do (DbDirectory for example), our approach was to implement a an IndexReader and IndexWriter directly on top of Cassandra.
Term Key ColumnName Value
"indexName/field/term" => { documentId , positionVector }
Document Key
"indexName/documentId" => { fieldName , value }
Lucandra in Action
Using Lucandra is extremely simple and switching a regular Lucene search application to use Lucandra is a matter of just several lines of code. Let’s have a look.
First we need to create the connection to Cassandra
import lucandra.CassandraUtils;
import lucandra.IndexReader;
import lucandra.IndexWriter;
...
Cassandra.Client client = CassandraUtils.createConnection();
Next, we create Lucandra’s IndexWriter and IndexReader, and Lucene’s own IndexSearcher.
IndexWriter indexWriter = new IndexWriter("bookmarks", client);
IndexReader indexReader = new IndexReader("bookmarks", client);
IndexSearcher indexSearcher = new IndexSearcher(indexReader);
From here on, you work with IndexWriter and IndexSearcher just like you in vanilla Lucene. Look at the BookmarksDemo for the complete class.


发表评论