[Dev] PyLucene Question

Andi Vajda vajda at osafoundation.org
Sat May 29 20:23:19 PDT 2004


The compiler complains because swig generated a constructor for an abstract
class. The trick is to wrap the swig declaration of the class with %nodefault;
%makedefault;. See the PyLucene.i file for other examples and the swig
documentation for more details.

So I added the IndexReader class and the classes it needed such as Term,
TermDocs, TermEnum and TermPositions. I removed the methods using arrays and
::java::util::Collection because I haven't written type conversion routines
for those yet.

The thing that stumped me though are the delete methods on IndexReader.
Because 'delete' is a keyword in C++, gcjh renames these methods to 'delete$',
something python and swig don't like so I used %rename for the python/swig
side and renamed 'delete$' to 'deleteTerm' but there still is a dynamic linker
problem later on though as the 'delete$' methods are not correctly resolved:

undefined symbols:
 org::apache::lucene::index::IndexReader::delete$(org::apache::lucene::index::Term*)
 org::apache::lucene::index::IndexReader::delete$(int)

There are relevant, yet slightly different delete$ symbols in _PyLucene.so
though, so there could be a bug in gcc/gcj and the linker here.

Any idea on how to solve that one would be welcome.
These latest changes are checked in, with the additions untested. I checked it
in so that you could proceed and elucidate the 'delete' riddle :)
(The 'delete$' methods are commented out).

Andi..

On Sat, 29 May 2004, darryl wrote:

> Hey all,
>
> I just subscribed to this list so my apologies if this type of question
> is off base.
> I've been playing with PyLucene and noticed that it has not wrapped the
> IndexReader class yet. Now as far as I can tell, this is necessary to
> actually
> delete documents from the index. I tried adding it myself to the swig
> interface
> file PyLucene.i but when i build I get the following:
>
> /usr/bin/g++ -shared -o build_release/_PyLucene.so -O2 -fPIC
> -Ibuild_release/classes -I/usr/include/python2.3 PyLucene_wrap.cxx
> build_release/lucene.o build_release/reader.java.o
> build_release/reader.cpp.o -lgcj
> PyLucene_wrap.cxx: In function `PyObject* _wrap_new_IndexReader(PyObject*,
>   PyObject*)':
> PyLucene_wrap.cxx:2105: error: cannot allocate an object of type `
>   org::apache::lucene::index::IndexReader'
> PyLucene_wrap.cxx:2105: error:   because the following virtual functions
> are
>   abstract:
> build_release/classes/org/apache/lucene/index/IndexReader.h:60: error:
> virtual
>   jint org::apache::lucene::index::IndexReader::numDocs()
> build_release/classes/org/apache/lucene/index/IndexReader.h:61: error:
> virtual
>   jint org::apache::lucene::index::IndexReader::maxDoc()
> build_release/classes/org/apache/lucene/index/IndexReader.h:62: error:
> virtual
>   org::apache::lucene::document::Document*
>   org::apache::lucene::index::IndexReader::document(__java_int)
> build_release/classes/org/apache/lucene/index/IndexReader.h:63: error:
> virtual
>   jboolean org::apache::lucene::index::IndexReader::isDeleted(__java_int)
> build_release/classes/org/apache/lucene/index/IndexReader.h:64: error:
> virtual
>   jboolean org::apache::lucene::index::IndexReader::hasDeletions()
> build_release/classes/org/apache/lucene/index/IndexReader.h:65: error:
> virtual
>   JArray<jbyte>*
>   org::apache::lucene::index::IndexReader::norms(java::lang::String*)
> build_release/classes/org/apache/lucene/index/IndexReader.h:66: error:
> virtual
>   void org::apache::lucene::index::IndexReader::setNorm(__java_int,
>   java::lang::String*, __java_byte)
> build_release/classes/org/apache/lucene/index/IndexReader.h:68: error:
> virtual
>   org::apache::lucene::index::TermEnum*
>   org::apache::lucene::index::IndexReader::terms()
> build_release/classes/org/apache/lucene/index/IndexReader.h:69: error:
> virtual
>   org::apache::lucene::index::TermEnum*
>
> org::apache::lucene::index::IndexReader::terms(org::apache::lucene::index::Term*)
>
> build_release/classes/org/apache/lucene/index/IndexReader.h:70: error:
> virtual
>   jint
>
> org::apache::lucene::index::IndexReader::docFreq(org::apache::lucene::index::Term*)
>
> build_release/classes/org/apache/lucene/index/IndexReader.h:72: error:
> virtual
>   org::apache::lucene::index::TermDocs*
>   org::apache::lucene::index::IndexReader::termDocs()
> build_release/classes/org/apache/lucene/index/IndexReader.h:74: error:
> virtual
>   org::apache::lucene::index::TermPositions*
>   org::apache::lucene::index::IndexReader::termPositions()
> build_release/classes/org/apache/lucene/index/IndexReader.h:77: error:
> virtual
>   void org::apache::lucene::index::IndexReader::doDelete(__java_int)
> build_release/classes/org/apache/lucene/index/IndexReader.h:80: error:
> virtual
>   void org::apache::lucene::index::IndexReader::undeleteAll()
> build_release/classes/org/apache/lucene/index/IndexReader.h:83: error:
> virtual
>   void org::apache::lucene::index::IndexReader::doClose()
> build_release/classes/org/apache/lucene/index/IndexReader.h:86: error:
> virtual
>   java::util::Collection*
>   org::apache::lucene::index::IndexReader::getFieldNames()
> build_release/classes/org/apache/lucene/index/IndexReader.h:87: error:
> virtual
>   java::util::Collection*
>   org::apache::lucene::index::IndexReader::getFieldNames(__java_boolean)
> make: *** [build_release/_PyLucene.so] Error 1
>
>
>
> Now if I go and delete the virtual functions from IndexReader.h (which
> is autogenerated) and edit the
> makefile to not autogenerate IndexReader.h the build goes fine. Is there
> some swig magic that i'm missing?
> Any clues? It seems to me that, going forward, IndexReader is an
> important part of the package.
>
> By the way, I also noticed that latest cvs has:
>
> "made compiling of PyLucene with DbDirectory conditional"
>
> Good stuff. I had yanked that out myself.
>
> Cheers,
> darryl
>
> --
>
> http://randomthoughts.vandorp.ca/WK/blog
>
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> Open Source Applications Foundation "Dev" mailing list
> http://lists.osafoundation.org/mailman/listinfo/dev
>



More information about the Dev mailing list