[pylucene-dev] Working with getFieldNames()

Andi Vajda vajda at osafoundation.org
Sat Aug 26 17:51:08 PDT 2006


On Sat, 26 Aug 2006, Kevin Ollivier wrote:

> My environment: Python 2.4, PyLucene 2.0.0, tested on FC1 and Mac OS X 10.4.7 
> Intel
>
> I've come across a slightly odd problem, and I'm not sure what I'm doing 
> wrong. Basically, the issue is that no matter what constant I pass for the 
> parameter, calls to myIndexReader.getFieldNames() return an empty list. I get 
> the same results on Linux and Mac OS X, but the test for this feature does 
> appear to pass just fine, and on top of that, I can query fields in the index 
> without problems.
>
> Here's a code snippet, where self.indexdir is the directory containing the 
> PyLucene index:
>
> reader = PyLucene.IndexReader.open(self.indexdir)
> info["NumDocs"] = reader.numDocs()
> info["Fields"] = reader.getFieldNames(PyLucene.IndexReader.FieldOption.ALL)
>
> Since the test passes, I'm fairly certain I've got a problem in my code 
> somewhere, but I was wondering if anyone may have come across this behavior 
> before or knows what kind of mistake could cause it to happen. Aside from 
> this issue, searching, indexing, etc. seems to work just fine (and I get a 
> valid value for numDocs() as well).

Problem found and fixed. Classes that contain static variables that point at 
java object instances need to be initialized before their static variables can 
be used. I had forgotten to do that for the IndexReader.FieldOption class so 
all its constants were NULL.

This is fixed in the patch attached and is also checked into svn.

Andi..
-------------- next part --------------
Index: lucene.cpp
===================================================================
--- lucene.cpp	(revision 288)
+++ lucene.cpp	(working copy)
@@ -13236,6 +13236,7 @@
     JvInitClass(&org::apache::lucene::search::Similarity::class$);
     JvInitClass(&org::apache::lucene::store::FSDirectory::class$);
     JvInitClass(&org::apache::lucene::index::IndexReader::class$);
+    JvInitClass(&org::apache::lucene::index::IndexReader$FieldOption::class$);
     JvInitClass(&org::apache::lucene::index::IndexWriter::class$);
     JvInitClass(&org::apache::lucene::index::IndexFileNames::class$);
     JvInitClass(&org::apache::lucene::analysis::el::GreekCharsets::class$);


More information about the pylucene-dev mailing list