Hi,
I am relativly new to Lucene and I am trying to index
the docs, as and when they are uploaded to the system,
by calling the following code: I keep getting 'segment
file not found error (thru debugger), when I was
expecting it to create those index files.
Can anybody look into the following code and tell me
what is my mistake/errors? Any help on this is
appreciated. Thanks,
Vinu
-------------
package com.proj.search;
import java.io.*;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionError;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.standard.*;
import org.apache.lucene.document.*;
public class FileIndexer {
public static void indexDoc( File file, String
indexFile, ActionErrors errors) {
IndexWriter writer = null;
try {
File f;
boolean create = true;
// create index if the directory does not exist
if ((f = new File(indexFile)).exists() &&
f.isDirectory()) {
create = false;
} else {
create = true;
}
writer = new IndexWriter(indexFile, new
StandardAnalyzer(), create);
writer.mergeFactor = 20;
// now add this document to the Indexing proces:
writer.addDocument(Document(file));
writer.optimize();
} catch (Exception e) {
errors.add("unableToIndex", new
ActionError("errors.search.lucene.index.unable"));
} finally {
close(writer);
}
}
// close writer
public static void close(IndexWriter writer) {
if(null != writer) {
try {
writer.close();
} catch(Exception e) {
}
}
}
// Lucene can only index objects of type Document.
public static Document Document(File file) {
FileInputStream fis=null;
Reader reader = null;
Document doc = null;
if (null !=file) {
try{
fis=new FileInputStream(file);
reader = new BufferedReader(new
InputStreamReader(fis));
doc = new Document();
doc.add(Field.Text("content", reader));
} catch (Exception e) {
}
}
return doc;
}
}
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>