hi,
The following code works for me:
hope this helps?!
best,
Marc
----------------
class AssociationFilter(object):
"""
create a PyLucene Query filter to compute an association score
between two items
"""
def __init__(self, source, target):
self._source = source
self._target = target
def bits(self, reader):
bits = PyLucene.BitSet(reader.maxDoc())
for id in [self._source, self._target]:
termDocs = reader.termDocs(PyLucene.Term('uid', id))
docs, freqs = termDocs.read(1)
if len(docs) == 1:
bits.set(docs[0])
return bits
filter = AssociationFilter(queryID, answerID)
hits = searcher.search(query, filter)
On 23-aug-2007, at 17:19, [EMAIL PROTECTED] wrote:
Is it possible to create a ConstantScoreQuery using a python-
defined filter? I'm trying the following, and I get the pasted error:
>>> class MyFilter(object):
... def bits(self, reader):
... return BitSet()
...
>>> f=MyFilter()
>>> q=ConstantScoreQuery(f)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pybackend.thirdparty.PyLucene.lnxpyd.PyLucene.InvalidArgsError:
(<type 'PyLucene.ConstantScoreQuery'>, '__init__',
(<__main__.MyFilter object at 0xb7cda14c>,))
So, my other thought was maybe I need to inherit from the PyLucene
Filter object, but that doesn't work either:
>>> class MyFilter(Filter):
... def bits(self, reader):
... return BitSet()
...
>>> f=MyFilter()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
pybackend.thirdparty.PyLucene.lnxpyd.PyLucene.InvalidArgsError:
(<class '__main__.MyFilter'>, '__init__', ())
So, am I missing something, or is ConstantScoreQuery currently only
capable of using built-in filters?
I'm using PyLucene 2.1.0-1 on Gentoo Linux with gcc 4.1.2; all
tests and sample code works for me.
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev
_______________________________________________
pylucene-dev mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/pylucene-dev