There were several bugs here that I now fixed. One issue has to do with method overloads and python. In python you can have only one method called 'search' on a class. There are three on Java Lucene's Searchable interface.
So, I renamed the python search methods one needs to define on a python searchable implementation as follows:


   void search(jquery, jfilter, jhitcollector);
becomes
   def searchAll(self, query, filter, hitCollector):

   TopDocs *search(jquery, jfilter, jint);
becomes (no rename)
   def search(self, query, filter, n):

   TopFieldDocs *search(jquery, jfilter, jint, Sort *);
becomes
   def searchSorted(self, query, filter, n, sort):

I attached a new version of your RemoteSearcher.py file for reference.
The latest fixes are checked in.

Andi..


On Fri, 14 Jan 2005, Yura Smolsky wrote:

Hello, Andi.

I have tried to implement Searchable interface and pass it to the
MultiSearcher instance, but it produces exception from java.

d:\work\python24\python.exe RemoteSearcher.py
Traceback (most recent call last):
 File "RemoteSearcher.py", line 42, in ?
   parallel = MultiSearcher([remoteS])
 File "d:\work\python24\lib\site-packages\PyLucene.py", line 1418, in __init__
   newobj = _PyLucene.new_MultiSearcher(*args)
ValueError: java.lang.NullPointerException
  at 0x1013720e (Unknown Source)
  at 0x10137702 (Unknown Source)
  at 0x101377b3 (Unknown Source)
  at 0x10136f6d (Unknown Source)
  at 0x1011d34d (Unknown Source)
  at 0x1017680d (Unknown Source)
  at 0x101186f2 (Unknown Source)
  at 0x10066df9 (Unknown Source)
  at 0x100f8d24 (Unknown Source)


What am I doing wrong?

Andi, is there a way to port interface Searchable, so I will implement
this interface on python?

AV> I just added support for Searchable, with the ability to extend it from AV> python. This is only minorly useful since the only place a Searchable is taken AV> as input by Lucene/PyLucene is when constructing a MultiSearcher.

AV> Still, I added support for the methods defined on Searchable and inherited 
by
AV> its various java implementations that were until now missing.

AV> This is only available from the PyLucene subversion source repository.

AV> When 'extending' a java lucene class or 'implementing' a java lucene
AV> interface, you're not really extending or implementing anything as far as
AV> java is concerned. All PyLucene is setup to do is take a custom python
AV> implementation of a java lucene protocol (just a set of methods) and wrap 
them
AV> in a java extension of the class or implementation of the interface in
AV> question whose job is to call into this python implementation's method. For
AV> this to work, such a java-calling-into-python wrapper class has to first be
AV> defined in PyLucene and PyLucene.i has to also be setup to recognize the
AV> python protocol implementations passed in to wrap them.

AV> Currently, in PyLucene, there are a number such wrapper classes setup. Which
AV> ones were setup is based on what I could see would be useful, or required in
AV> terms of abstract lucene classes needing implementations to be usable.

AV> Such 'reverse swigging' is a bunch of handcrafted boilerplate code as you 
can
AV> see for yourself in the cpp and java directories of the PyLucene source 
tree.

AV> I doubt that just extending PyLucene's export of Searchable is going to give
AV> you a RemoteSearchable. It is not that simple, in particular, I did do
AV> anything about the serializability of any of swig wrappers around the Lucene
AV> objects as passed to python.

AV> Andi..


Yura Smolsky,
#!/usr/bin/python2.4

from PyLucene import *

class RemoteSearcher(object):
    def __init__(self, local):
        self.local = local
    
    def close(self):
        self.local.close()
    
    def docFreq(self, term):
        return self.local.docFreq(term)
  
    def maxDoc(self):
        return self.local.maxDoc()
    
    def searchAll(self, query, filter, hitCollector):
        return self.local.search(query, filter, hitCollector)
    
    def search(self, query, filter, n):
        return self.local.search(query, filter, n)
    
    def searchSorted(self, query, filter, n, sort):
        return self.local.search(query, filter, n, sort)
    
    def doc(self, i):
        return self.local.doc(i)
    
    def rewrite(self, original):
        return self.local.rewrite(original)
    
    def explain(self, query, doc):
        return self.local.explain(query, doc)
    
dir = FSDirectory.getDirectory("index", False)
a = StandardAnalyzer()
searcher = IndexSearcher(dir)

remoteS = RemoteSearcher(searcher)


# create MultiSearcher with one Searcher
parallel = MultiSearcher([remoteS])


query = QueryParser.parse("lisp", "contents", a)

hits = parallel.search(query)
print hits.length()
_______________________________________________
pylucene-dev mailing list
[EMAIL PROTECTED]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to