diff roundup/backends/back_anydbm.py @ 825:0779ea9f1f18

More indexer work: - all String properties may now be indexed too. Currently there's a bit of "issue" specific code in the actual searching which needs to be addressed. In a nutshell: + pass 'indexme="yes"' as a String() property initialisation arg, eg: file = FileClass(db, "file", name=String(), type=String(), comment=String(indexme="yes")) + the comment will then be indexed and be searchable, with the results related back to the issue that the file is linked to - as a result of this work, the FileClass has a default MIME type that may be overridden in a subclass, or by the use of a "type" property as is done in the default templates. - the regeneration of the indexes (if necessary) is done once the schema is set up in the dbinit.
author Richard Jones <richard@users.sourceforge.net>
date Tue, 09 Jul 2002 03:02:53 +0000
parents 254b8d112eec
children 6d7a45c8464a
line wrap: on
line diff
--- a/roundup/backends/back_anydbm.py	Tue Jul 09 01:21:24 2002 +0000
+++ b/roundup/backends/back_anydbm.py	Tue Jul 09 03:02:53 2002 +0000
@@ -15,7 +15,7 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-#$Id: back_anydbm.py,v 1.38 2002-07-08 06:58:15 richard Exp $
+#$Id: back_anydbm.py,v 1.39 2002-07-09 03:02:52 richard Exp $
 '''
 This module defines a backend that saves the hyperdatabase in a database
 chosen by anydbm. It is guaranteed to always be available in python
@@ -66,6 +66,16 @@
         # ensure files are group readable and writable
         os.umask(0002)
 
+    def post_init(self):
+        """Called once the schema initialisation has finished."""
+        # reindex the db if necessary
+        if not self.indexer.should_reindex():
+            return
+        for klass in self.classes.values():
+            for nodeid in klass.list():
+                klass.index(nodeid)
+        self.indexer.save_index()
+
     def __repr__(self):
         return '<back_anydbm instance at %x>'%id(self) 
 
@@ -409,8 +419,9 @@
         self.databases = {}
 
         # now, do all the transactions
+        reindex = {}
         for method, args in self.transactions:
-            method(*args)
+            reindex[method(*args)] = 1
 
         # now close all the database files
         for db in self.databases.values():
@@ -418,6 +429,14 @@
         del self.databases
         # TODO: unlock the DB
 
+        # reindex the nodes that request it
+        for classname, nodeid in filter(None, reindex.keys()):
+            print >>hyperdb.DEBUG, 'commit.reindex', (classname, nodeid)
+            self.getclass(classname).index(nodeid)
+
+        # save the indexer state
+        self.indexer.save_index()
+
         # all transactions committed, back to normal
         self.cache = {}
         self.dirtynodes = {}
@@ -439,6 +458,9 @@
         # now save the marshalled data
         db[nodeid] = marshal.dumps(self.serialise(classname, node))
 
+        # return the classname, nodeid so we reindex this content
+        return (classname, nodeid)
+
     def _doSaveJournal(self, classname, nodeid, action, params):
         # serialise first
         if action in ('set', 'create'):
@@ -477,8 +499,7 @@
         for method, args in self.transactions:
             # delete temporary files
             if method == self._doStoreFile:
-                if os.path.exists(args[0]+".tmp"):
-                    os.remove(args[0]+".tmp")
+                self._rollbackStoreFile(*args)
         self.cache = {}
         self.dirtynodes = {}
         self.newnodes = {}
@@ -486,6 +507,15 @@
 
 #
 #$Log: not supported by cvs2svn $
+#Revision 1.38  2002/07/08 06:58:15  richard
+#cleaned up the indexer code:
+# - it splits more words out (much simpler, faster splitter)
+# - removed code we'll never use (roundup.roundup_indexer has the full
+#   implementation, and replaces roundup.indexer)
+# - only index text/plain and rfc822/message (ideas for other text formats to
+#   index are welcome)
+# - added simple unit test for indexer. Needs more tests for regression.
+#
 #Revision 1.37  2002/06/20 23:52:35  richard
 #More informative error message
 #

Roundup Issue Tracker: http://roundup-tracker.org/