[Checkins] SVN: zc.relationship/trunk/src/zc/relationship/ fix a
bug that caused the transitive query factory to be required when it
Fred L. Drake, Jr.
fdrake at gmail.com
Mon Jun 12 19:41:44 EDT 2006
Log message for revision 68609:
fix a bug that caused the transitive query factory to be required when it
was not needed
Changed:
U zc.relationship/trunk/src/zc/relationship/README.txt
U zc.relationship/trunk/src/zc/relationship/index.py
-=-
Modified: zc.relationship/trunk/src/zc/relationship/README.txt
===================================================================
--- zc.relationship/trunk/src/zc/relationship/README.txt 2006-06-12 22:37:21 UTC (rev 68608)
+++ zc.relationship/trunk/src/zc/relationship/README.txt 2006-06-12 23:41:44 UTC (rev 68609)
@@ -621,6 +621,60 @@
This is reasonably useful as is, to test basic assertions. It also works with
transitive searches, as we will see below.
+
+An even simpler example
+-----------------------
+
+(This was added to test that searching for a simple relationship works
+even when the transitive query factory is not set.)
+
+Let's create a very simple relation type, using strings as the source
+and target types:
+
+ >>> class IStringRelation(interface.Interface):
+ ... name = interface.Attribute("The name of the value.")
+ ... value = interface.Attribute("The value associated with the name.")
+
+ >>> class StringRelation(persistent.Persistent, Contained):
+ ... interface.implements(IStringRelation)
+ ...
+ ... def __init__(self, name, value):
+ ... self.name = name
+ ... self.value = value
+
+ >>> app[u"string-relation-1"] = StringRelation("name1", "value1")
+ >>> app[u"string-relation-2"] = StringRelation("name2", "value2")
+
+ >>> transaction.commit()
+
+We can now create an index that uses these:
+
+ >>> from BTrees import OOBTree
+
+ >>> sx = index.Index(
+ ... ({"element": IStringRelation["name"],
+ ... "load": None, "dump": None, "btree": OOBTree},
+ ... {"element": IStringRelation["value"],
+ ... "load": None, "dump": None, "btree": OOBTree},
+ ... ))
+
+ >>> app["sx"] = sx
+ >>> transaction.commit()
+
+And we'll add the relations to the index:
+
+ >>> app["sx"].index(app["string-relation-1"])
+ >>> app["sx"].index(app["string-relation-2"])
+
+Getting a relationship back out should be very simple. Let's look for
+all the values associates with "name1":
+
+ >>> query = sx.tokenizeQuery({"name": "name1"})
+ >>> list(sx.findValues("value", query))
+ ['value1']
+
+
+
Searching for empty sets
------------------------
Modified: zc.relationship/trunk/src/zc/relationship/index.py
===================================================================
--- zc.relationship/trunk/src/zc/relationship/index.py 2006-06-12 22:37:21 UTC (rev 68608)
+++ zc.relationship/trunk/src/zc/relationship/index.py 2006-06-12 23:41:44 UTC (rev 68609)
@@ -470,7 +470,7 @@
if transitiveQueriesFactory is None:
transitiveQueriesFactory = self.defaultTransitiveQueriesFactory
if transitiveQueriesFactory is None:
- if maxDepth != 1:
+ if maxDepth != 1 and maxDepth is not None:
raise ValueError(
'if maxDepth != 1, transitiveQueriesFactory must be '
'available')
More information about the Checkins
mailing list