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.
Andi..
I'm using pylucene-3.0.3-1.
Trimmed/pseudo sample (real code is on a different system):
import lucene
indexMetaDataDict = {"one":"two", "three":"four"}
writer = lucene.IndexWriter(store, analyzer, True,
lucene.IndexWriter.MaxFieldLength.UNLIMITED)
## do document indexing
writer.optimize()
writer.commit(indexMetaDataDict)
writer.close()
If the "writer.commit(indexMetaDataDict)" line is commented out, it
works fine.
If its not, I get the InvalidArgsError back for that line.
Thanks much,
-eric