[Zope-CVS] CVS: Products/ZCTextIndex - ZCTextIndex.py:1.1.2.4

Jeremy Hylton jeremy@zope.com
Wed, 1 May 2002 18:48:32 -0400


Update of /cvs-repository/Products/ZCTextIndex
In directory cvs.zope.org:/tmp/cvs-serv28327

Modified Files:
      Tag: TextIndexDS9-branch
	ZCTextIndex.py 
Log Message:
Integrate NBest into ZCTextIndex




=== Products/ZCTextIndex/ZCTextIndex.py 1.1.2.3 => 1.1.2.4 ===
 from Products.ZCTextIndex.Lexicon import Lexicon
+from Products.ZCTextIndex.NBest import NBest
 from Products.ZCTextIndex.QueryEngine import QueryEngine
 from Products.ZCTextIndex.QueryParser import QueryParser
 
@@ -32,7 +33,11 @@
     def _apply_index(self, req):
         pass # XXX
 
-    def query(self, query):
+    def query(self, query, nbest=10):
         # returns a mapping from docids to scores
         tree = self.parser.parseQuery(query)
-        return self.engine.executeQuery(self.index, tree)
+        results = self.engine.executeQuery(self.index, tree)
+        chooser = NBest(nbest)
+        for item, score in results.items():
+            chooser.add(item, score)
+        return chooser.getbest()