[pylucene-dev] Hits.__iter__

tsuraan at tsuraan.net tsuraan at tsuraan.net
Tue Apr 18 07:10:46 PDT 2006


In PyLucene 1.9 (haven't checked the new 2.0 stuff yet), Hits.__iter__ 
uses a HitsEnumeration object that returns each document in the hits 
list.  Would it make more sense for __iter__ to be implemented with the 
Hits.iterator() method (also not exposed in PyLucene 1.9)?  Doing this 
would be a bit more consistent with what a Java Lucene user would 
expect, and it lets us get the score for each document as well as the 
document itself, using the clean Python looping syntax.

currently:

hits = searcher.search(query)
for i in range(hits.length()):
   print hits.doc(i)
   print hits.score(i)

Using a more Java-Lucene-ish way:

hits = searcher.search(query)
for hit in hits:
   print hit.getDocument()
   print hit.getScore()

Anyhow, I'd like it more that way...



More information about the pylucene-dev mailing list