[Zope-CVS] CVS: Products/ZCTextIndex - OkapiIndex.py:1.7 ZCTextIndex.py:1.9

Casey Duncan casey@zope.com
Wed, 15 May 2002 16:02:18 -0400


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

Modified Files:
	OkapiIndex.py ZCTextIndex.py 
Log Message:
Okapi index now works w/zope.

Removed QueryParser as a persistent attribute of the ZCTextIndex so that
it doesn't need to be persistent (It stores no state).

Updated tests. Functionally tested in Zope.


=== Products/ZCTextIndex/OkapiIndex.py 1.6 => 1.7 ===
                                         mass_weightedUnion
 
+import ZODB
+from Persistence import Persistent
+
 # Instead of storing floats, we generally store scaled ints.  Binary pickles
 # can store those more efficiently.  The default SCALE_FACTOR of 1024
 # is large enough to get about 3 decimal digits of fractional info, and
@@ -43,7 +46,7 @@
     # expensive.
     return int(f * scale + 0.5)
 
-class Index:
+class Index(Persistent):
 
     __implements__ = IIndex
 
@@ -78,6 +81,10 @@
         """Return the number of documents in the index."""
         return len(self._docwords)
 
+    def get_words(self, docid):
+        """Returns the wordids for a given docid"""
+        return WidCode.decode(self._docwords[docid])
+
     def index_doc(self, docid, text):
         wids = self._lexicon.sourceToWordIds(text)
         self._doclen[docid] = len(wids)
@@ -88,6 +95,7 @@
             self._add_wordinfo(wid, count, docid)
 
         self._docwords[docid] = WidCode.encode(wids)
+        return len(wids)
 
     def unindex_doc(self, docid):
         for wid in WidCode.decode(self._docwords[docid]):


=== Products/ZCTextIndex/ZCTextIndex.py 1.8 => 1.9 ===
         self.lexicon = lexicon
         self.index = index_factory(self.lexicon)
-        self.parser = QueryParser()
 
     ## Pluggable Index APIs ##
 
@@ -89,13 +88,13 @@
         if record.keys is None:
             return None
         query_str = ' '.join(record.keys)
-        tree = self.parser.parseQuery(query_str)
+        tree = QueryParser().parseQuery(query_str)
         results = tree.executeQuery(self.index)
         return  results, (self._fieldname,)
 
     def query(self, query, nbest=10):
         # returns a mapping from docids to scores
-        tree = self.parser.parseQuery(query)
+        tree = QueryParser().parseQuery(query)
         results = tree.executeQuery(self.index)
         chooser = NBest(nbest)
         chooser.addmany(results.items())