標籤:Lucene style blog color io os ar 使用 java
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 can‘t 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的索引修複