You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by MM...@LEVI.com on 2003/07/14 11:11:00 UTC
Delete files
Hi, I am new in Lucene. I have a problem with my code. Somebody can help me
why I can't delete some files.Maybe I missing something. Thanks in advance.
Regards,
Michel
Here the two code that I use for indexing files and for delete files: the
error message is the following: java.io.IOException: Index locked for
write: Lock@C:\yo\write.lock
at org.apache.lucene.index.IndexReader.delete(Unknown Source)
at indice.deletefile.main(deletefile.java:15)
Exception in thread "main"
package indice;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import java.io.*;
public class IndexarFile {
public static void main(String[] args) throws Exception{
String indexPath = "c:\\yo";
IndexWriter writer;
String f = "c:\\PROCEDURES\\BCNDMPRD.xls";
writer = new IndexWriter(indexPath, new SimpleAnalyzer(),
false);
//for (int i=0; i<args.length; i++) {
//System.out.println("Indexando file " + args[i]);
//InputStream file = new FileInputStream(args[i]);
InputStream file = new FileInputStream(f);
Document doc = new Document();
doc.add(Field.UnIndexed("path", f));
doc.add(Field.Text("body", (Reader)new
InputStreamReader(file)));
writer.addDocument(doc);
file.close();
//}
writer.close();
}
}
package indice;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.analysis.SimpleAnalyzer;
//import org.apache.lucene.document.Document;
/**import org.apache.lucene.document.Field;
import java.io.*;*/
public class deletefile {
public static void main(String[] args) throws Exception{
String path = "c:\\yo";
IndexWriter iw = new IndexWriter(path, new SimpleAnalyzer(),
false);
IndexReader reader = IndexReader.open(path);
reader.delete(1);
reader.close();
iw.optimize();
iw.close();
System.out.println("reader.numDocs() : " + reader.numDocs());
System.out.println("reader.indexExists() : " +
reader.indexExists(path));
}
}
Re: Delete files
Posted by Victor Hadianto <vi...@nuix.com.au>.
On Mon, 14 Jul 2003 07:11 pm, MMachado@LEVI.com wrote:
> Hi, I am new in Lucene. I have a problem with my code. Somebody can help me
> why I can't delete some files.Maybe I missing something. Thanks in advance.
You have IndexWriter opened while trying to delete document. Use IndexReader
to delete document and then open IndexWriter to optimize.
> Regards,
>
> Michel
victor
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org