From e7debdf9e3c8875db9632370387ac47176b9f6b3 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 22 Oct 2007 14:22:24 +0000 Subject: [PATCH] LUCENE-1020: created basic tool to check an index, print details of each segment, and fix the index by removing broken segments git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@587107 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/CheckIndex.java | 302 ++++++++++++++++++ 1 file changed, 302 insertions(+) create mode 100644 src/java/org/apache/lucene/index/CheckIndex.java diff --git a/src/java/org/apache/lucene/index/CheckIndex.java b/src/java/org/apache/lucene/index/CheckIndex.java new file mode 100644 index 00000000000..258ea65e5d8 --- /dev/null +++ b/src/java/org/apache/lucene/index/CheckIndex.java @@ -0,0 +1,302 @@ +package org.apache.lucene.index; + +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import org.apache.lucene.store.FSDirectory; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.IndexInput; +import org.apache.lucene.document.Document; + +import java.text.NumberFormat; +import java.util.Collection; +import java.util.Iterator; + +/** + * Basic tool to check the health of an index and write a + * new segments file that removes reference to problematic + * segments. There are many more checks that this tool + * could do but does not yet, eg: reconstructing a segments + * file by looking for all loadable segments (if no segments + * file is found), removing specifically specified segments, + * listing files that exist but are not referenced, etc. + */ + +public class CheckIndex { + + public static void main(String[] args) throws Throwable { + + boolean doFix = false; + for(int i=0;i