[Zope3-checkins] CVS: Zope3/lib/python/Zope/TextIndex - TextIndexInterfaces.py:1.2 TextIndexWrapper.py:1.2
Guido van Rossum
guido@python.org
Wed, 4 Dec 2002 05:25:41 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/TextIndex
In directory cvs.zope.org:/tmp/cvs-serv18288/lib/python/Zope/TextIndex
Modified Files:
TextIndexInterfaces.py TextIndexWrapper.py
Log Message:
Give query() arguments start and count sensible defaults.
=== Zope3/lib/python/Zope/TextIndex/TextIndexInterfaces.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/TextIndex/TextIndexInterfaces.py:1.1 Tue Dec 3 11:25:54 2002
+++ Zope3/lib/python/Zope/TextIndex/TextIndexInterfaces.py Wed Dec 4 05:25:41 2002
@@ -43,12 +43,12 @@
class IQuerying(Interface):
- def query(querytext, start, count):
+ def query(querytext, start=0, count=None):
"""Execute a query.
querytext: unicode, the query expression
start: the first result to return (0-based)
- count: the maximum number of results to return
+ count: the maximum number of results to return (default: all)
return: ([(docid, rank), ...], total)
The return value is a triple:
=== Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py 1.1 => 1.2 ===
--- Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py:1.1 Tue Dec 3 11:45:23 2002
+++ Zope3/lib/python/Zope/TextIndex/TextIndexWrapper.py Wed Dec 4 05:25:41 2002
@@ -55,12 +55,14 @@
# Methods implementing IQuerying
- def query(self, querytext, start, count):
+ def query(self, querytext, start=0, count=None):
parser = QueryParser(self.lexicon)
tree = parser.parseQuery(querytext)
results = tree.executeQuery(self.index)
- if results is None:
+ if not results:
return [], 0
+ if count is None:
+ count = max(0, len(results) - start)
chooser = NBest(start + count)
chooser.addmany(results.items())
batch = chooser.getbest()