首页 > 代码库 > Solr4.8.0源码分析(13)之LuceneCore的索引修复

Solr4.8.0源码分析(13)之LuceneCore的索引修复

Solr4.8.0源码分析(13)之LuceneCore的索引修复

题记:今天在公司研究elasticsearch,突然看到一篇博客说elasticsearch具有索引修复功能,顿感好奇,于是点进去看了下,发现原来是Lucene Core自带的功能,于是就回家先学习下,正好也跟之前看的索引文件的格式相应。有空也研究下Lucene的一些小工具。

 

索引的修复主要是用到CheckIndex.java这个类,可以直接查看类的Main函数来了解下。

1. CheckIndex的使用

首先使用以下命令来查看lucenecore.jar怎么使用:

 1 192:lib rcf$ java -cp lucene-core-4.8-SNAPSHOT.jar -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex  2  3 ERROR: index path not specified 4  5 Usage: java org.apache.lucene.index.CheckIndex pathToIndex [-fix] [-crossCheckTermVectors] [-segment X] [-segment Y] [-dir-impl X] 6  7   -fix: actually write a new segments_N file, removing any problematic segments 8   -crossCheckTermVectors: verifies that term vectors match postings; THIS IS VERY SLOW! 9   -codec X: when fixing, codec to write the new segments_N file with10   -verbose: print additional details11   -segment X: only check the specified segments.  This can be specified multiple12               times, to check more than one segment, eg -segment _2 -segment _a.13               You cant use this with the -fix option14   -dir-impl X: use a specific FSDirectory implementation. If no package is specified the org.apache.lucene.store package will be used.15 16 **WARNING**: -fix should only be used on an emergency basis as it will cause17 documents (perhaps many) to be permanently removed from the index.  Always make18 a backup copy of your index before running this!  Do not run this tool on an index19 that is actively being written to.  You have been warned!20 21 Run without -fix, this tool will open the index, report version information22 and report any exceptions it hits and what action it would take if -fix were23 specified.  With -fix, this tool will remove any segments that have issues and24 write a new segments_N file.  This means all documents contained in the affected25 segments will be removed.26 27 This tool exits with exit code 1 if the index cannot be opened or has any28 corruption, else 0.

当敲java -cp lucene-core-4.8-SNAPSHOT.jar -ea:org.apache.lucene... org.apache.lucene.index.CheckIndex 这个就能看到相当于help的信息啦,但是为什么这里用这么一串奇怪的命令呢?

今天太晚了,明天继续学习

Solr4.8.0源码分析(13)之LuceneCore的索引修复