1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: hyperdb.py,v 1.71 2002-07-09 03:02:52 richard Exp $
18+ # $Id: hyperdb.py,v 1.72 2002-07-09 21:53:38 gmcm Exp $
1919
2020__doc__ = """
2121Hyperdatabase implementation, especially field types.
@@ -785,24 +785,28 @@ def lookup(self, keyvalue):
785785
786786 # XXX: change from spec - allows multiple props to match
787787 def find (self , ** propspec ):
788- """Get the ids of nodes in this class which link to a given node .
788+ """Get the ids of nodes in this class which link to the given nodes .
789789
790- 'propspec' consists of keyword args propname=nodeid
790+ 'propspec' consists of keyword args propname={ nodeid:1,}
791791 'propname' must be the name of a property in this class, or a
792792 KeyError is raised. That property must be a Link or Multilink
793793 property, or a TypeError is raised.
794794
795- 'nodeid' must be the id of an existing node in the class linked
796- to by the given property, or an IndexError is raised.
795+ Any node in this class whose 'propname' property links to any of the
796+ nodeids will be returned. Used by the full text indexing, which knows
797+ that "foo" occurs in msg1, msg3 and file7, so we have hits on these issues:
798+ db.issue.find(messages={'1':1,'3':1}, files={'7':1})
797799 """
798800 propspec = propspec .items ()
799- for propname , nodeid in propspec :
801+ for propname , nodeids in propspec :
800802 # check the prop is OK
801803 prop = self .properties [propname ]
802804 if not isinstance (prop , Link ) and not isinstance (prop , Multilink ):
803805 raise TypeError , "'%s' not a Link/Multilink property" % propname
804- if not self .db .hasnode (prop .classname , nodeid ):
805- raise ValueError , '%s has no node %s' % (prop .classname , nodeid )
806+ #XXX edit is expensive and of questionable use
807+ #for nodeid in nodeids:
808+ # if not self.db.hasnode(prop.classname, nodeid):
809+ # raise ValueError, '%s has no node %s'%(prop.classname, nodeid)
806810
807811 # ok, now do the find
808812 cldb = self .db .getclassdb (self .classname )
@@ -811,16 +815,26 @@ def find(self, **propspec):
811815 node = self .db .getnode (self .classname , id , db = cldb )
812816 if node .has_key (self .db .RETIRED_FLAG ):
813817 continue
814- for propname , nodeid in propspec :
818+ for propname , nodeids in propspec :
815819 # can't test if the node doesn't have this property
816820 if not node .has_key (propname ):
817821 continue
822+ if type (nodeids ) is type ('' ):
823+ nodeids = {nodeids :1 }
818824 prop = self .properties [propname ]
819- property = node [propname ]
820- if isinstance (prop , Link ) and nodeid == property :
821- l .append (id )
822- elif isinstance (prop , Multilink ) and nodeid in property :
825+ value = node [propname ]
826+ if isinstance (prop , Link ) and nodeids .has_key (value ):
823827 l .append (id )
828+ break
829+ elif isinstance (prop , Multilink ):
830+ hit = 0
831+ for v in value :
832+ if nodeids .has_key (v ):
833+ l .append (id )
834+ hit = 1
835+ break
836+ if hit :
837+ break
824838 return l
825839
826840 def stringFind (self , ** requirements ):
@@ -1185,6 +1199,22 @@ def Choice(name, db, *options):
11851199
11861200#
11871201# $Log: not supported by cvs2svn $
1202+ # Revision 1.71 2002/07/09 03:02:52 richard
1203+ # More indexer work:
1204+ # - all String properties may now be indexed too. Currently there's a bit of
1205+ # "issue" specific code in the actual searching which needs to be
1206+ # addressed. In a nutshell:
1207+ # + pass 'indexme="yes"' as a String() property initialisation arg, eg:
1208+ # file = FileClass(db, "file", name=String(), type=String(),
1209+ # comment=String(indexme="yes"))
1210+ # + the comment will then be indexed and be searchable, with the results
1211+ # related back to the issue that the file is linked to
1212+ # - as a result of this work, the FileClass has a default MIME type that may
1213+ # be overridden in a subclass, or by the use of a "type" property as is
1214+ # done in the default templates.
1215+ # - the regeneration of the indexes (if necessary) is done once the schema is
1216+ # set up in the dbinit.
1217+ #
11881218# Revision 1.70 2002/06/27 12:06:20 gmcm
11891219# Improve an error message.
11901220#
0 commit comments