Hardlight Homepage Welcome Guest  |  Login   
  Search  
  Index |  Recent Threads |  Who's Online |  User List |  Register |  My Profile |  Search |  Help


Quick Go »
Total posts in this thread: 1 [Add To My Favorites] [Watch this Thread] [Post new Thread]
Author
Previous Thread This topic has been viewed 5214 times and has 0 replies Next Thread
Male Roger
Stranger



Joined: Jun 1, 2006
Posts: 3
Status: Offline

Corrupt Lucene Index Reply to this Post
Reply with Quote

Hi, I am trying to create a lucene index, but when I try to view it in LUKE, it says that the index is corrupt. Any ideas as to why this is??!?



package org.apache.lucene.demo;



/**
* Copyright 2004 The Apache Software Foundation
*
* Licensed 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 java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Date;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;

/** Index all text files under a directory. */
public class IndexFiles {

private IndexFiles() {}

static final File IndexDir = new File("C:\\bump5");



/** Index all text files under a directory. */
public static void main(String[] args) {
String usage = "java org.apache.lucene.demo.IndexFiles <root_directory>";
if (args.length == 0) {
System.err.println("Usage: " + usage);
System.exit(1);
}

if (IndexDir.exists()) {
System.out.println("Cannot save index to '" +IndexDir+ "' directory, please delete it first");
System.exit(1);
}

String readDir = "C:\\enron";

final File docDir = new File(readDir);
if (!docDir.exists() || !docDir.canRead()) { //if it does not exist and u cant read..
System.out.println("Document directory '" +docDir.getAbsolutePath()+ "' does not exist or is not readable, please check the path");
System.exit(1);

}

Date start = new Date();
try {
IndexWriter writer = new IndexWriter(IndexDir, new StandardAnalyzer(), true);
System.out.println("Indexing to directory '" +IndexDir+ "'...");
indexDocs(writer, docDir); //calls the indexDocs method
System.out.println("Optimizing...");
writer.optimize();
writer.close();
Date end = new Date();
System.out.println(end.getTime() - start.getTime() + " total milliseconds");

} catch (IOException e) {
System.out.println(" caught a " + e.getClass() +
"\n with message: " + e.getMessage());
}
}


static void indexDocs(IndexWriter writer, File file)//indexing documents method
throws IOException {
// do not try to index files that cannot be read
if (file.canRead()) {
if (file.isDirectory()) {
String[] files = file.list();
// an IO error could occur
if (files != null) {
for (int i = 0; i < files.length; i++) {

indexDocs(writer, new File(file, files));
}
}
} else {
System.out.println("adding " + file);
try {
Document doc= new Document();
writer.addDocument(doc);
//writer.addDocument(FileDocument.Document(file));


doc.add(new Field( "keyword", "test1", Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.add(new Field( "keyword", "test0", Field.Store.YES, Field.Index.UN_TOKENIZED));
InputStream stream = new FileInputStream(file);
doc.add(new Field( "keyword", new InputStreamReader(stream)));
}

// at least on windows, some temporary files raise this exception with an "access denied" message
// checking if the file can be read doesn't help
catch (FileNotFoundException fnfe) {
;
}
}
}
}

}
[Jun 29, 2006 1:01:36 AM] Print Post    Email is hidden to Guest Report threaten post: please login first  Go to top 
[Show Printable Version] [Post new Thread]