lucene-pylucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andi Vajda <va...@apache.org>
Subject Re: Using IndexWriter.commit(Map<String,String> commitUserData) in pylucene
Date Thu, 20 Jan 2011 03:15:11 GMT

On Wed, 19 Jan 2011, Eric Hall wrote:

> On Wed, Jan 19, 2011 at 11:05:28AM -0800, Andi Vajda wrote:
>>
>> On Wed, 19 Jan 2011, Eric Hall wrote:
>>
>>> 	I'd like to store some index metadata using
>>>
>>> 	IndexWriter.commit(Map<String,String> commitUserData)
>>>
>>> 	I've set up a python dict with string to string mappings,
>>> but if I use that I get an InvalidArgsError.  Is there a different
>>> python type to use in this call?
>>
>> Yes, use a Java HashMap for which there is a Python wrapper in PyLucene:
>>
>>  >>> import lucene
>>  >>> lucene.initVM()
>>   <jcc.JCCEnv object at 0x10040a0d8>
>>  >>> a = lucene.HashMap().of_(lucene.String, lucene.String)
>>  >>> a.put('foo', 'bar')
>>  >>> a
>>   <HashMap: {foo=bar}>
>>
>> The use of the of_() method is optional but it conveys the <String, String>
>> part and helps with enforcing the generic parameter and return type for the
>> map's methods.
>>
>> If you'd rather use a Python dict directly, see the example in PyLucene's
>> python/collections.py module where a Python set is wrapped by a class
>> called JavaSet. The same could be implemented for the java.util.Map
>> interface.
>
> 	Tha HashMap()... method works fine for storing the metadata, and luke
> shows that its there.  Of course getting the metadata back for later
> comparison/display is also useful, and seemed like it would be
> straightforward....  Naturally its not working using:
>
> 	indexMetaDataHashMap = reader.getCommitUserData()
>
> 	I get an empty hashmap back from the above.  I also tried using:
>
> 	indexCommit = reader.getIndexCommit
> 	indexMetaDataHashMap = indexCommit.getUserData()
>
> with the same result (empty hashmap).  Is there a different way to do this?
>

If you're getting a HashMap back then the PyLucene side of things is 
working. If it's empty it could mean that you're doing something wrong 
Lucene-wise or that you found a bug there. Could it be that you opened the 
IndexReader before the IndexWriter got committed ? If so, reopen() it after 
commit or move the opening code. If not, you may want to ask about this on 
the Lucene user list at java-user@lucene.apache.org.

Andi..

Mime
View raw message