如何确定lucene索引版本? [英] How to determine the lucene index version?

查看:87
本文介绍了如何确定lucene索引版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个shell脚本(csh),该脚本必须确定lucene索引版本,然后基于该脚本必须将索引升级到下一个版本.所以,如果lucene索引在2.x上,我必须将索引升级到3.x最后,索引需要升级到6.x.

I am writing a shell script (csh) that has to determine the lucene index version and then based on that it has to upgrade the index to next version. So, if the lucene indices are on 2.x, I have to upgrade the indices to 3.x Finally the indices need to be upgraded to 6.x.

由于升级索引是一个顺序过程(2.x-> 3.x-> 4.x-> 5.x-> 6.x),因此我必须事先了解索引版本,以便进行设置正确地升级classpath并升级.

Since upgrading indices is a sequential process(2.x->3.x->4.x->5.x->6.x), I have to know the indices version before hand so that I can set the classpath properly and upgrade.

请帮助我.

推荐答案

这不是一个很干净的解决方案,但是我可以通过

This is not a very clean solution but that is all I am able to find via SegmentInfos.

LuceneVersion->此提交使用了哪个Lucene代码版本,编写为三个vInt:主要,次要,错误修正

LuceneVersion --> Which Lucene code Version was used for this commit, written as three vInt: major, minor, bugfix

创建 IndexReader 时,它是具体的阅读器类之一,例如-

When you create your IndexReader, it is one of concrete reader classes like - StandardDirectoryReader and this class has a toString() method like below which is printing lucene version for each segment so you can simply call - toString() on IndexReader instance.

<代码>@Override公共字符串toString(){最后的StringBuilder缓冲区= new StringBuilder();buffer.append(getClass().getSimpleName());buffer.append('(');最后的String segmentFile = segmentInfos.getSegmentsFileName();如果(segmentsFile!= null){buffer.append(segmentsFile).append(:").append(segmentInfos.getVersion());}if(writer!= null){buffer.append(:nrt");}for(最终LeafReader r:getSequentialSubReaders()){buffer.append('');buffer.append(r);}buffer.append(')');返回buffer.toString();}

我想,整个索引的单一版本是没有意义的,因为索引也可能包含以前版本编写者提交的文档.

I guess, a single version for whole index doesn't make sense since an Index might have documents committed from previous version writers too.

使用较新的Lucene版本编写器提交的文档可以使用最新的版本阅读器进行搜索,前提是版本距离与Lucene定义的距离不远.

Documents committed with older lucene version writers can be searched using latest version readers provided version distance is not far as defined by Lucene.

您可以使用regex在Core Java中编写一个简单的逻辑,以提取最高的Lucene版本作为您的Lucene索引版本.

You might write a simple logic in Core Java using regex to extract highest lucene version as your lucene index version.

这篇关于如何确定lucene索引版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆