Hello, Yura.
I have found that problem is about initialization of ScoreDoc object.
When I use existent ScoreDoc object created by java then everything is
okay. When I use ScoreDoc object created in python -> it produces
exception.
Check new attach.
YS> Hello, Andi.
YS> I just have added TopFieldDocs manual creation code. This code does
YS> recreate TopFieldDocs object using PyLucene classes ScoreDoc,
YS> SortField and TopFieldDocs. Check attached file.
YS> This example returns exeption:
YS> D:\workshop\blogz-src>d:\work\python24\python.exe RemoteSearch2.py
YS> in searchSorted
YS> ['"modified"!']
YS> 249 1.0
YS> 269 0.282842695713
YS> 4 0.34999999404
YS> 52 0.17499999702
YS> modified 3 True
YS> in searchSorted, finished
YS> Exception in thread "MultiSearcher thread #1"
YS> java.lang.ClassCastException: org.apache.lucene.search.ScoreDoc
YS> cannot be cast to
YS> org.apache.lucene.search.FieldDoc
YS> *** Got java.lang.NullPointerException while trying to print stack trace.
YS> 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>>
YS> Yura Smolsky,
YS>
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:
scoreDoc2 = ScoreDoc(scoreDoc.doc, scoreDoc.score)
scoreDocs.append(scoreDoc) # WILL WORK
#scoreDocs.append(scoreDoc2) # WILL NOT WORK
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