lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Aditi Goyal" <aditigupt...@gmail.com>
Subject Re: java.lang.NullPointerExcpetion while indexing on linux
Date Wed, 20 Aug 2008 10:29:38 GMT
Thanks Mike. I found the problem.
The problem was that I was not converting the value of the fields to utf-8
and hence while adding it to doc it was getting stored as None.
So, when I did doc.get('fieldA') , instead of giving the blank or any other
string, it was giving out None.

To overcome this, I first converted the string to utf-8 format and then
field.setValue() and then doc.add(field), It seems to be working fine.,


However, I have one question. When I do a feild.setValue() and then
doc.add() will it replace the value of the field in the doc or add a new
field with the similar name and the new value? Since i am reusing the doc
and i am not reinitialising the doc anywhere and since you told that
doc.removeField() is an expensive operation.

Thanks,
Aditi


On Tue, Aug 19, 2008 at 5:39 PM, Michael McCandless <
lucene@mikemccandless.com> wrote:

>
> On quick look that code looks fine, though removeField is an expensive
> operation and unnecessary for this.
>
> We really need the full traceback of the exception.
>
> Mike
>
>
> Aditi Goyal wrote:
>
>  Thanks Michael and Ian for your valuable response.
>> I am attaching a small default code. Please have a look and tell me where
>> am
>> I going wrong.
>>
>> import lucene
>> from lucene import Document, Field, initVM, CLASSPATH
>>
>> doc = Document()
>> fieldA = Field('fieldA', "", Field.Store.YES, Field.Index.UN_TOKENIZED)
>> fieldB = Field('fieldB', "", Field.Store.YES, Field.Index.TOKENIZED)
>> fieldC = Field ('fieldC', "", Field.Store.YES, Field.Index.TOKENIZED)
>>
>> doc.add(fieldA)
>> doc.add(fieldB)
>> doc.add(fieldC)
>>
>> def get_fields():
>>   if doc.getField('FieldA') is not None:
>>       doc.removeField('FieldA')
>>   if doc.getField('FieldB') is not None:
>>       doc.removeField('FieldB')
>>   if doc.getField('FieldC') is not None:
>>       doc.removeField('FieldC')
>>
>>   fieldA.setValue("abc")
>>   doc.add(fieldA)
>>   fieldB.setValue("xyz")
>>   doc.add(fieldB)
>>   fieldC.setValue("123")
>>   doc.add(fieldC)
>>
>>   return doc
>>
>>
>> def add_document():
>>   doc = get_fields()
>>   writer = lucene.IndexWriter(index_directory, analyzer, create_path)
>>   writer.addDocument(doc)
>>   writer.close()
>>
>> This writer.addDocument is throwing an exception saying
>> java.lang.NullPointerException
>>
>> Thanks,
>> Aditi
>>
>> On Tue, Aug 19, 2008 at 3:25 PM, Michael McCandless <
>> lucene@mikemccandless.com> wrote:
>>
>>
>>> Ian Lea wrote:
>>>
>>> I don't think you need to remove the field and then add it again, but
>>>
>>>> I've no idea if that is relevant to your problem or not.
>>>>
>>>>
>>> That's right: just leave the Field there and change its value (assuming
>>> the
>>> doc you are changing to still uses that field).
>>>
>>> A full stack trace would be more help, and maybe an upgrade to 2.3.2,
>>>
>>>> and maybe a snippet of your code, and what is JCC?
>>>>
>>>>
>>> JCC generates the necessary C/C++ glue code for Python to directly invoke
>>> Java code.  The Chandler project created this for PyLucene because they
>>> were
>>> having trouble with GCJ:
>>>
>>>  http://blog.chandlerproject.org/author/vajda/
>>>
>>> Mike
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
>>> For additional commands, e-mail: java-user-help@lucene.apache.org
>>>
>>>
>>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message