[Zope-CVS] CVS: Products/FieldedTextIndex - index.py:1.3 test.py:1.2

Casey Duncan casey at zope.com
Wed Dec 10 01:14:11 EST 2003


Update of /cvs-repository/Products/FieldedTextIndex
In directory cvs.zope.org:/tmp/cvs-serv28903

Modified Files:
	index.py test.py 
Log Message:
Add lexiconId method for use by managment view
Add tests for lexiconId and getEntryForObject
Fix mgmt view to use new API
Make sure total doc length is updated at index-time, otherwise querys with results throw a division by zero error.
Functional test searching all fields w/real content. It works 8)


=== Products/FieldedTextIndex/index.py 1.2 => 1.3 ===
--- Products/FieldedTextIndex/index.py:1.2	Wed Dec 10 00:02:32 2003
+++ Products/FieldedTextIndex/index.py	Wed Dec 10 01:13:40 2003
@@ -96,6 +96,11 @@
         """Return a list of the field names in the index"""
         return self._fields[:]
     
+    security.declareProtected(Permissions.search_zcatalog, 'fieldNames')
+    def lexiconId(self):
+        """Return the id of the lexicon for this index"""
+        return self._lexicon.getId()
+    
     ## Pluggable Index API ##
     
     def index_object(self, docid, obj, theshold=None):
@@ -148,7 +153,9 @@
         self._docweight[docid] = len(frequencies)
         self._docwords[docid] = field2words # map: fieldid -> compressed wids
         self.document_count.change(1)
-        return len(frequencies)
+        count = len(frequencies)
+        self._change_doc_len(count)
+        return count
         
     '''
     def _reindex_object(self, docid, source):


=== Products/FieldedTextIndex/test.py 1.1.1.1 => 1.2 ===
--- Products/FieldedTextIndex/test.py:1.1.1.1	Mon Dec  8 01:25:00 2003
+++ Products/FieldedTextIndex/test.py	Wed Dec 10 01:13:40 2003
@@ -19,9 +19,11 @@
 from unittest import TestCase, TestSuite, main, makeSuite
 
 import ZODB
+from Acquisition import aq_base
 from OFS.SimpleItem import SimpleItem
 from BTrees.Length import Length
-from Products.ZCTextIndex.Lexicon import Lexicon, Splitter
+from Products.ZCTextIndex.Lexicon import Splitter
+from Products.ZCTextIndex.ZCTextIndex import PLexicon
 from Products.FieldedTextIndex.index import FieldedTextIndex
 
 
@@ -35,7 +37,7 @@
 
     def setUp(self):
         self.test = SimpleItem()
-        self.test.lexicon = Lexicon(Splitter())
+        self.test.lexicon = PLexicon('lexicon', '', Splitter())
         self.test.index = FieldedTextIndex('test', 'fields', self.test.lexicon)
         self.test.REQUEST = SimpleItem()
         self.index = self.test.index
@@ -55,7 +57,7 @@
             lexicon_id = 'lexicon'
         index = FieldedTextIndex(
             'extra', 'ymmit', extra=extra, caller=self.test)
-        self.assert_(index._lexicon is self.test.lexicon)
+        self.assert_(aq_base(index._lexicon) is aq_base(self.test.lexicon))
         self.assertEqual(index.getId(), 'extra')
         self.assertEqual(index.source_name, 'ymmit')
     
@@ -214,6 +216,22 @@
         self.failIf(self.index._wordfields)
         self.failIf(self.index._docwords)
         self.failIf(self.index.fieldNames())
+    
+    def test_lexiconId(self):
+        self.assertEqual(self.index.lexiconId(), 'lexicon')
+    
+    def test_getEntryForObject(self):
+        self.index_one(1)
+        self.index_two(2)
+        entry = self.index.getEntryForObject(1)
+        fnames = entry.keys()
+        fnames.sort()
+        self.assertEqual(fnames, ['izzy', 'title'])
+    
+    def test_getEntryForObject_defaults(self):
+        self.assert_(self.index.getEntryForObject(1) is None)
+        stufs = []
+        self.assert_(self.index.getEntryForObject(1, stufs) is stufs)
 
         
 def test_suite():




More information about the Zope-CVS mailing list