On Fri, 13 Mar 2009, Michael McCandless wrote:

I'm playing with 2.4.1 RC3 (on OS X 10.5.6) and found a few issues:

* 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.

Indeed, this fails (see example of Java stacktrace reporting):

  from lucene import *
  initVM(CLASSPATH)

  writer = IndexWriter(RAMDirectory(),StandardAnalyzer())
  doc = Document()
  field = Field('field', '', Field.Store.NO, Field.Index.NOT_ANALYZED)
  field.setValue('abc')
  doc.add(field)

  try:
      writer.addDocument(doc)
  except JavaError, e:
      e.getJavaException().printStackTrace()
      raise

  writer.close()

But the equivalent Java version works:

  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("abc");
          doc.add(field);
          writer.addDocument(doc);
          writer.close();

          System.err.println("done");
      }
  }


If, however, you replace the field.setValue('abc') call in the Python code with 
passing 'abc' to the constructor, it works too.
It looks like you found a bug with the setValue() wrapper.

I'm looking into it...

Andi..

Reply via email to