初始化分布式 Lucene
NCache 分布式 Lucene 为任何应用程序提供了可扩展且可靠的搜索功能。 Lucene 通过对文档建立索引来实现高效搜索,其中需要创建索引并将其存储在目录中。
备注
此功能也可用于 NCache Professional.
第一步是初始化存储索引的目录。 与 Lucene.NET 不同, NCacheDirectory
用于维护索引的存储位置。 在里面 NCacheDirectory
,传递以下参数:
缓存名称: 使用 Lucene 的缓存名称。
索引名称:每个索引都由一个名称唯一标识。 它使用提供的索引名称创建一个目录,因为单个缓存上可以有多个索引。 (默认情况下,路径为
NCacheDirectory
is C:\ ProgramData \ncache\lucene索引 对于Windows和Windows /用户/分享/ncache/lucene索引/ 对于 Linux,但您也可以在创建缓存时通过 NCache 管理中心和命令行界面。)
通过后 缓存名称 和 索引名称是, NCacheDirectory
搜索 索引路径。 一旦 索引路径 已被发现, NCacheDirectory
搜索 索引名称 在那条路上。 如果索引名称不存在,它会创建一个具有该名称的目录。 在那之后 NCacheDirectory
在该索引上打开。
备注
索引目录的默认路径是 C:\ ProgramData \ncache\lucene-index\{CACHE_NAME}\data 对于 Windows,以及 /用户/分享/ncache/lucene-index/{CACHE_NAME}/数据 对于 Linux。
先决条件
- 了解与所有人员合作所需的标准先决条件 NCache 客户端功能请参考给定页面 客户端 API 先决条件.
- 确保您已经通过 NCache 管理中心 or 命令行界面.
- 确保您的应用程序没有使用任何本机 Lucene DLL/Reference。
- 有关 API 详细信息,请参阅: NCache目录.
初始化目录
下面的例子打开 NCacheDirectory
在名为的缓存上 Lucene缓存
// 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);
更多资讯
NCache 提供了分布式 Lucene 的示例应用程序 GitHub上.
参见
.NET: Lucene.Net.Store 命名空间。