Initialize Distributed Lucene
The NCache Distributed Lucene provides a scalable and reliable search capability to any application. Lucene enables efficient searching by indexing the documents, where indexes need to be created and stored in a directory.
Note
This feature is also available in NCache Professional.
The first step is to initialize the directory that stores the indexes. Unlike Lucene.NET, the NCacheDirectory
is used for maintaining the storage location of the indexes. In the NCacheDirectory
, the following parameters are passed:
CacheName: The cache name using Lucene.
IndexName: Every index is uniquely identified by a name. It creates a directory with the provided index name as there can be multiple indexes on a single cache. (By default, the path for the
NCacheDirectory
is C:\ProgramData\ncache\lucene-index for Windows and /user/share/ncache/lucene-index/ for Linux, but you can specify your own path as well at the time of the cache creation through the NCache Management Center and the Command Line Interface).
After passing the CacheName and IndexName, the NCacheDirectory
searches for the index path. Once the index path has been discovered, the NCacheDirectory
searches for the IndexName on that path. If the index name does not exist, it creates a directory with that name. After that, the NCacheDirectory
is opened on that index.
Note
The default path for index directory is C:\ProgramData\ncache\lucene-index\{CACHE_NAME}\data for Windows, and /user/share/ncache/lucene-index/{CACHE_NAME}/data for Linux.
Prerequisites
- To learn about the standard prerequisites required to work with all NCache client-side features, please refer to the given page on Client-Side API Prerequisites.
- Make sure that you have created and started a Lucene cache through the NCache Management Center or Command Line Interface.
- Make sure that your application is not using any native Lucene DLL/Reference.
- For API details, refer to: NCacheDirectory.
Initializing Directory
The following example opens the NCacheDirectory
on the cache named LuceneCache
// Specify the cache name that is used for Lucene
string cache = "LuceneCache";
// Specify the index name to create the indexes
string indexName = "ProductIndex";
// Create a directory and open it on the cache and the index path
Directory directory = NCacheDirectory.Open(cache, indexName);
Additional Resources
NCache provides a sample application for Distributed Lucene on GitHub.
See Also
.NET: Lucene.Net.Store namespace.