使用(最新的)Lucene8.7,可以在一个我无法修改的遗留应用程序中用lucene实用程序“路克”打开2009年左右的Lucene2.2生成的.cfs复合索引文件吗?或者,是否有可能从.idx中为卢克生成.cfs文件?.cfs是由Lucene2.2之上的罗盘生成的,而不是由lucene直接生成的,因此可以使用罗盘生成的索引,其中包括:
_b.cfs
segments.gen
segments_d
可能和solr在一起?
是否有任何示例可以使用罗盘打开基于文件的.cfs索引?
由于索引版本太旧,转换工具无法工作:
来自lucene\build\演示:
../core/lucene-core-8.7.0-SNAPSHOT.jar;../backward-codecs/lucene-backward-codecs-8.7.0-SNAPSHOT.jar -cp org.apache.lucene.index.IndexUpgrader -verbose path_of_old_index
搜索文件演示:
../core/lucene-core-8.7.0-SNAPSHOT.jar;../queryparser/lucene-queryparser-8.7.0-SNAPSHOT.jar;./lucene-demo-8.7.0-SNAPSHOT.jar -classpath org.apache.lucene.demo.SearchFiles -index path_of_old_index
两者都失败了,因为:
org.apache.lucene.index.IndexFormatTooOldException:格式版本不支持此版本的Lucene只支持用Version6.0及更高版本创建的索引。
在lucene中使用旧索引是可能的吗?如何使用旧的“编解码器”?如果可能的话也来自lucene.net?
当前lucene 8.7生成一个包含以下文件的索引:
segments_1
write.lock
_0.cfe
_0.cfs
_0.si
==========================================================================更新:令人惊讶的是,它似乎打开了非常古老的格式索引,lucene.net v.3.0.3来自nuget!
这样做似乎是为了从索引中提取所有术语:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Version = Lucene.Net.Util.Version;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
var reader = IndexReader.Open(FSDirectory.Open("C:\\Temp\\ftsemib_opzioni\\v210126135604\\index\\search_0"), true);
Console.WriteLine("number of documents: "+reader.NumDocs() + "\n");
Console.ReadLine();
TermEnum terms = reader.Terms();
while (terms.Next())
{
Term term = terms.Term;
String termField = term.Field;
String termText = term.Text;
int frequency = reader.DocFreq(term);
Console.WriteLine(termField +" "+termText);
}
var fieldNames = reader.GetFieldNames(IndexReader.FieldOption.ALL);
int numFields = fieldNames.Count;
Console.WriteLine("number of fields: " + numFields + "\n");
for (IEnumerator<String> iter = fieldNames.GetEnumerator(); iter.MoveNext();)
{
String fieldName = iter.Current;
Console.WriteLine("field: " + fieldName);
}
reader.Close();
Console.ReadLine();
}
}
}出于好奇,能不能找出它是什么索引版本?是否有基于文件系统索引的(旧)罗盘的例子?
发布于 2021-02-02 14:00:03
不幸的是,您不能使用旧的Codec来访问Lucene2.2中的索引文件。这是因为编解码器是在Lucene 4.0中引入的。在此之前,用于读取和写入索引文件的代码不是组合在一起的编解码器,而是整个Lucene库的固有部分。
因此,在Lucene 4.0之前的版本中,没有编解码器,只有文件读取和写入库中的代码。很难追踪所有这些代码,并创建一个可以插入Lucene的现代版本的编解码器。这不是一个不可能的任务,但它需要一个专家Lucene开发人员和大量的努力(即非常昂贵的努力)。
鉴于所有这些,这个问题的答案可能是有用的:How to upgrade lucene files from 2.2 to 4.3.1
更新
最好的选择是使用java的一个旧的3.x副本或Lucene.net ver3.0.3打开索引,然后添加并提交一个文档(这将创建第二个段),并进行优化,从而将两个段合并到一个新的段中。新的部分将是第3版。然后,您可以使用Lucene.Net 4.8Beta或JavaLucene4.x来做同样的事情(但提交被重新命名为ForceMerge,从第4版开始),以将索引转换为4.X索引。
然后,您可以使用Lucene8.x的当前java版本再次执行此操作,以将索引一直移动到8,因为当前版本的Java的编解码器一直到5.0,参见:https://github.com/apache/lucene-solr/tree/master/lucene/core/src/java/org/apache/lucene/codecs
但是,如果您确实再次收到您报告的错误:
这个版本的Lucene只支持用Version6.0及更高版本创建的索引。
然后,您必须再玩一个6.xJavaLucene版本的游戏,才能从5.x索引获得6.x索引。:-)
https://stackoverflow.com/questions/65943184
复制相似问题