[pylucene-dev] why does iterating Hits and IndexReaders give (i, doc)?

Andi Vajda vajda at osafoundation.org
Wed May 10 11:14:04 PDT 2006


On Wed, 10 May 2006, Steven Bethard wrote:

> I couldn't figure out the rationale for having Hits and IndexReader
> objects generate index/document tuples when iterated instead of simply
> generating the documents.  This makes the distinctly unlike Python
> lists, where to get such behavior you'd use enumerate like::
>
>   for i, doc in enumerate(hits):
>       ...
>
> I assume this was discussed somewhere, but I couldn't find the
> discussion.  Could someone point me there?

The reason is that when iterating hits you might need the hit number to access 
more information from the hits such as the score of the hit. In other words, a 
enumeration of hits is more than an enumeration of docs.

In PyLucene 2.0, I've changed it so that it works more like the new Java 
Lucene HitIterator class and returns a Hit object from which the doc, score, 
etc... can be accessed. In order to remain backwards compatible with the 
earlier form, the Hit object expands into (i, doc) when asked to do so (it 
implements a sequence of two elements).

PyLucene 2.0 is available from PyLucene's svn repository trunk. Its actual 
release is waiting for Java Lucene 2.0 to be released which hasn't happened 
yet.

Andi..


More information about the pylucene-dev mailing list