如何在Lucene.NET4.8中使用高压缩

如何在Lucene.NET4.8中使用高压缩,lucene,lucene.net,Lucene,Lucene.net,我正在尽量压缩索引大小,有什么帮助吗? 公共类LuceneIndexer { 专用Analyzer_Analyzer=新的ArabicAnalyzer(Lucene.Net.Util.LuceneVersion.Lucene_48); 私有字符串_indexath; 专用目录_indexDirectory; 公共索引编写器(IndexWriter);; 公共LuceneIndexer(字符串索引XPath) { 这是.\u indepath=indepath; _indexDirectory=

我正在尽量压缩索引大小,有什么帮助吗?

公共类LuceneIndexer
{
专用Analyzer_Analyzer=新的ArabicAnalyzer(Lucene.Net.Util.LuceneVersion.Lucene_48);
私有字符串_indexath;
专用目录_indexDirectory;
公共索引编写器(IndexWriter);;
公共LuceneIndexer(字符串索引XPath)
{
这是.\u indepath=indepath;
_indexDirectory=newsimplefsdirectory(new System.IO.DirectoryInfo(_indexPath));
}
public void BuildCompleteIndex(IEnumerable文档)
{
IndexWriterConfig IndexWriterConfig=新的IndexWriterConfig(Lucene.Net.Util.LuceneVersion.lucene48,_分析器){OpenMode=OpenMode.CREATE_或_APPEND};
indexWriterConfig.MaxBufferedDocs=2;
indexWriterConfig.RAMBufferSizeMB=128;
indexWriterConfig.MaxThreadState=2;
_indexWriter=新的indexWriter(_indexDirectory,indexWriterConfig);
_indexWriter.AddDocuments(文件);
_indexWriter.Flush(真,真);
_indexWriter.Commit();
_index writer.Dispose();
}
公共IEnumerable搜索(字符串搜索项、字符串搜索字段、整数限制)
{
IndexReader IndexReader=DirectoryReader.Open(_indexDirectory);
var searcher=新索引搜索器(indexReader);
var termQuery=new termQuery(new Term(searchField,searchTerm));//Lucene.Net.Util.LuceneVersion.lucene48,searchField,_分析器
var hits=searcher.Search(termQuery,limit).ScoreDocs;
var documents=新列表();
foreach(命中率中的var命中率)
{
documents.Add(searcher.Doc(hit.Doc));
}
_analyzer.Dispose();
归还文件;
}
}

首先要知道的是“Lucene索引”有很多方面。当不使用复合文件时,这会在创建的各种文件中体现出来。只看其中的两个,我们可以讨论被称为posting的倒排索引,我们可以讨论存储的文档。在这两种方法中,我所能说的关于反转索引的压缩没有任何现成的可调设置

高压缩模式与存储字段相关。如果您不存储字段,并且只使用Lucene.Net创建反向索引,那么为存储字段启用高压缩不会减少“Lucene索引”的大小

也就是说,如果您正在存储字段,并且希望对存储的字段数据使用高压缩,那么您需要创建自己的编解码器,该编解码器对存储字段启用高压缩。要做到这一点,您首先需要一个已启用高压缩的存储字段类。下面是这两个类,后面是一个单元测试,它使用了我为您编写的这个新编解码器。我还没有在大量数据上尝试过这段代码以查看效果,我把它留给您作为练习,但这应该为您指明了使用高压缩来压缩存储字段的方法

/*
*根据一个或多个许可证颁发给Apache软件基金会(ASF)
*贡献者许可协议。请参阅随附的通知文件
*本作品提供了有关版权所有权的更多信息。
*ASF根据Apache许可证2.0版将此文件许可给您
*(以下简称“许可证”);除非符合以下要求,否则不得使用此文件
*执照。您可以通过以下方式获得许可证副本:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
*除非适用法律要求或书面同意,软件
*根据许可证进行的分发是按“原样”进行分发的,
*无任何明示或暗示的保证或条件。
*请参阅许可证以了解管理权限和权限的特定语言
*许可证下的限制。
*/
公共密封类Lucene41存储字段压缩格式:压缩存储字段格式{
/// 
///唯一的构造器。
public Lucene41StoredFieldsHighCompressionFormat()
:base(“Lucene41StoredFieldsHighCompression”,压缩模式。高压缩,1矢量格式;
公共覆盖密封的PostingsFormat PostingsFormat=>PostingsFormat;
公共覆盖密封字段Infosformat FieldInfosFormat=>FieldInfosFormat;
公共覆盖密封段InfoFormat SegmentInfoFormat=>segmentInfosFormat;
公共覆盖密封LiveDocsFormat LiveDocsFormat=>LiveDocsFormat;
/// 
///返回应用于写入的日志格式
///新的市场细分。
/// 
///默认实现总是返回“Lucene41”
/// 
[MethodImpl(MethodImplOptions.AggressiveInline)]
公共虚拟发布格式GetPostingsFormatForField(字符串字段){
//LuceNet-specific-lazy初始化编解码器,以确保在重写时获得正确的类型。
if(defaultFormat==null){
defaultFormat=Lucene.Net.Codecs.PostingsFormat.ForName(“Lucene41”);
}
返回默认格式;
}
/// 
///返回应用于写入的docvalues格式
///新的市场细分。
/// 
///默认实现总是返回“Lucene45”
/// 
[MethodImpl(MethodImplOptions.AggressiveInline)]
公共虚拟DocValuesFormat GetDocValuesFormatForField(字符串字段){
//LuceNet-specific-lazy初始化编解码器,以确保在重写时获得正确的类型。
如果(defaultDVFormat==null){
defaultDVFormat=Lucene.Net.Codecs.DocValuesFormat.ForName(“Lucene45”);
Codec.SetCodecFactory(new DefaultCodecFactory {
    CustomCodecTypes = new Type[] { typeof(Lucene46HighCompressionCodec) }
});