Hello, Andi.

I just have added TopFieldDocs manual creation code. This code does
recreate TopFieldDocs object using PyLucene classes ScoreDoc,
SortField and TopFieldDocs. Check attached file.
This example returns exeption:

D:\workshop\blogz-src>d:\work\python24\python.exe RemoteSearch2.py
in searchSorted
['"modified"!']
249 1.0
269 0.282842695713
4 0.34999999404
52 0.17499999702
modified 3 True
in searchSorted, finished
Exception in thread "MultiSearcher thread #1" java.lang.ClassCastException: 
org.apache.lucene.search.ScoreDoc cannot be cast to
org.apache.lucene.search.FieldDoc
*** Got java.lang.NullPointerException while trying to print stack trace.
4

AV> I verified, by modifying the RemoteSearcher.py code you sent me yesterday 
that
AV> 'searchSorted' is working properly. The code is attached.

AV> Andi..

AV> On Sat, 5 Feb 2005, Yura Smolsky wrote:

>> Hello, pylucene-dev.
>>
>> I use ParallelMultiSearcher and I construct manually variables passed
>> to search, searchSorted methods of Searchable implementation.
>> I got this exception when I use sort and ParallerMultiSearcher:
>>
>> scoreDoc: 261
>> scoreDoc: 211
>> ... skipped ...
>> scoreDoc: 142
>> scoreDoc: 144
>> Exception in thread "MultiSearcher thread #1"
>> java.lang.ClassCastException: org.apache.lucene.search.ScoreDoc
>> cannot be cast to
>> org.apache.lucene.search.FieldDoc
>>   at 0x012ce0ae (Unknown Source)
>>   ... skipped
>> hits: 18
>>
>> if I do not use sort or if I use Searchable implementation through
>> searchSorted then everything is ok.
>> I do not understand this.. Who is messing the data?..
>> Maybe method searchSorted of implementation of Searchable generates
>> "bad" PyLucene classes?..
>>
>> Thanks in advance.
>>
>> Yura Smolsky
AV> 



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):
        print 'in searchSorted'
        tfd = self.local.search(query, filter, n, sort)
        print [str(sf) for sf in tfd.fields]

        scoreDocs = []
        for scoreDoc in tfd.scoreDocs:
            scoreDocs.append(ScoreDoc(scoreDoc.doc, scoreDoc.score))
            print scoreDoc.doc, scoreDoc.score
        
        sortFields = []
        for sortField in tfd.fields:
            sortFields.append(SortField(sortField.getField(), 
sortField.getType(), sortField.getReverse()))
            print sortField.getField(), sortField.getType(), 
sortField.getReverse()

        tfd2 = TopFieldDocs(tfd.totalHits, scoreDocs, sortFields)

        print 'in searchSorted, finished'
        return tfd2
    
    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)
    
a = StandardAnalyzer()
searcher = IndexSearcher("index/index03")

remoteS = RemoteSearcher(searcher)


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


query = QueryParser.parse("angel", "content", a)


sort = Sort()
sort.setSort([SortField("modified", SortField.STRING, True)])
hits = parallel.search(query, sort)

print hits.length()
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev

Reply via email to