[pylucene-dev] iteration and downcasting...

Andi Vajda vajda at osafoundation.org
Mon Nov 26 14:34:00 PST 2007


On Mon, 26 Nov 2007, Bill Janssen wrote:

> I seem to have a lot of this in my JCC PyLucene code:
>
>    # don't use iteration because it doesn't downcast properly
>    # for hit in hits:
>    for i in range(len(hits)):
>        doc = hits.doc(i)
>
> Instead of
>
>    for hit in hits:
>        doc = hit.getDocument()
>
> which I'd prefer.  Am I doing something wrong?

Yes and no.

     for hit in hits:
         doc = Hit.cast_(hit).getDocument()

would do the trick.

Once Java Lucene switches to Java 1.5 and declares that a HitIterator 
returns Hit objects instead of Object objects, jcc can be changed to take 
advantage of that new information to apply the correct wrapper.

Andi..


More information about the pylucene-dev mailing list