On Fri, 13 Mar 2009, Michael McCandless wrote:
* I'm attempting to re-use a field, by changing its value, and then
adding the document to an index:
lucene.initVM(lucene.CLASSPATH)
writer = lucene.IndexWriter(lucene.RAMDirectory(),
lucene.StandardAnalyzer())
doc = lucene.Document()
field = lucene.Field('field', '', lucene.Field.Store.NO,
lucene.Field.Index.NOT_ANALYZED)
field.setValue('abc')
doc.add(field)
writer.addDocument(doc)
writer.close()
However, unexpectedly I hit a Java NullPointerException in the
writer.addDocument. I hit a different exception if I use
lucene.Field.Index.ANALYZED instead. The corresponding code in
Lucene should work fine I think.
Two bugs at work here:
1. Because of the order in which the wrappers for setValue() were
generated and because JCC let's you pass a python string for a Java
byte array (I should probably remove that since JArray('byte')([...])
is the way to do this now), your setValue('abc') call gets passed to
the Java Field.setValue(byte[]) overload.
2. Because of a probable Java Lucene bug, that fails to take and a
NullPointerException is thrown during indexing.
The following Java code illustrates the error:
import java.io.IOException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
public class t02 {
public static void main(String[] args)
throws IOException
{
IndexWriter writer = new IndexWriter(new RAMDirectory(),
new StandardAnalyzer());
Document doc = new Document();
Field field = new Field("field", "",
Field.Store.NO,
Field.Index.NOT_ANALYZED);
field.setValue(new byte[] { 'a', 'b', 'c' });
doc.add(field);
writer.addDocument(doc);
writer.close();
System.err.println("done");
}
}
Mike, what do you think ?
Andi..