Your SlideShare is downloading. ×
0
Relationship Building
Defining and Querying Complex Relationships
          Between Your Content

              Alec P. Mit...
Existing Tools

• Archetypes Reference Engine
• External SQL database
• zc.relationship + plone.relations
• ???
Benefits of AT
          References
• Can relate any AT content to any other AT
  content.
• There are nice widgets availab...
Disadvantages of AT
       References
• Requires mixin base classes. Essentially only
  works with AT content.
• Reference...
Benefits of an RDBMS-
   based Solution
• Can support arbitrarily complex
  relationships and queries.
• Can be performance...
Disadvantages of an
RDBMS-based Solution

• Entirely DIY
• Requires an external database
• Need to create some 1-to-1 mapp...
What is zc.relationship
• A low-level ZODB index for querying
  relationships
 • Highly optimized for simple relationship
...
What is plone.relations
• A local utility built on zc.relationship, which
  is applicable to a wide variety of relationshi...
What is
    plone.app.relations
• A content-centric API for defining and
  querying relationships:
     src = IRelationship...
Relationship Sources

• IRelationshipSource
 • Create (createRelationship), supports
    multiple targets
 • Query (getTar...
Relationship Targets
• IRelationshipTarget
 • Same query methods and parameters as
    IRelationshipSource + getSources
• ...
Brief Code Example
>>> class IFriendship(IDCWorkflowableRelationship):
...     “””A friendship”””
>>> source = IRelationsh...
What Can You Do With It?
 • Model any non-container relationships you
   might need.
  • Social Networking (user   user,
 ...
What Have I Done With It?
 • The Daily Reel (http://www.thedailyreel.com)
  • Social network for online video creators
   ...
Brief UI Demo
Shortcomings
• Relationships are inherently asymmetric,
  with sources and targets on unequal footing.
• Relationships are...
When to Use
        Something Else
• Efficient sorting on a large result set of
  relationships.
• Complex queries. Current...
The Future?

• Support for explicit ordering of relationships
• API providing permission based filtering
• UI (schema field,...
Thank You!
• Special thanks to
 • Balazs Ree
 • Gary Poster and Zope Corporation
 • Whit Morriss
 • Ramon Navarro Bosch
 •...
Upcoming SlideShare
Loading in...5
×

Alec Mitchell Relationship Building Defining And Querying Complex Relationships Between Your Content

2,901

Published on

The current story for relating content in Plone, via Archetypes reference fields, is limited and known to have poor performance in some cases. This talk will focus on the integration of Zope 3 tools for handling relationships (intids, zc.relationship) in Zope 2 via plone.app.relations. In particular I will be comparing the merits of these tools against existing methods (Archetypes references, using a separate RDBMS for content relationships), discussing particular applications for which they may be useful, and some areas in which they fall short. The comparison to existing relationship modeling tools will cover performance, flexibility, and convenience. To illustrate the relative convenience, I will give a brief overview of the plone.app.relations API, from the lower level index and relationship container to the high level API for making queries and defining relationships. The discussion of applications will focus on a some real world uses. These include social networking, defining complex taxonomies, having content appear attached to multiple locations, and other things for which Plone typically would not be suitable (these tools are in use at http://www.thedailyreel.com). In particular, I'll discuss how the default relationship attributes and query methods from the API can be used to model each of these applications. Finally, I'll discuss the areas in which these tools may fall short in terms of performance and flexibility, and where an RDBMS or specialized catalog may be necessary.

Published in: Business, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,901
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
119
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "Alec Mitchell Relationship Building Defining And Querying Complex Relationships Between Your Content"

  1. 1. Relationship Building Defining and Querying Complex Relationships Between Your Content Alec P. Mitchell
  2. 2. Existing Tools • Archetypes Reference Engine • External SQL database • zc.relationship + plone.relations • ???
  3. 3. Benefits of AT References • Can relate any AT content to any other AT content. • There are nice widgets available to manipulate relationships. • Uses the familiar ZCatalog internally. • Relationships can provide complex behaviors.
  4. 4. Disadvantages of AT References • Requires mixin base classes. Essentially only works with AT content. • References are intrinsic to their source, and generally defined as part of the content schema. • General purpose ZCatalog not entirely optimized for relationship queries. • API tends is somewhat inconsistent, and test coverage is sub-optimal.
  5. 5. Benefits of an RDBMS- based Solution • Can support arbitrarily complex relationships and queries. • Can be performance tuned for specific use- cases. • Can be used to relate anything to anything else.
  6. 6. Disadvantages of an RDBMS-based Solution • Entirely DIY • Requires an external database • Need to create some 1-to-1 mapping between RDBMS keys and ZODB content.
  7. 7. What is zc.relationship • A low-level ZODB index for querying relationships • Highly optimized for simple relationship queries across large data-sets. • Default configuration allows relationships between arbitrary persistent objects. • Index can be configured to index complex relationships, which may include non- ZODB objects. • Provides transitive searches.
  8. 8. What is plone.relations • A local utility built on zc.relationship, which is applicable to a wide variety of relationship models. • A relationship class that models many-to- many content relationships. • Some optional aspects of the relationship are also indexed: • Relationship Type • Relationship State • Relationship Context
  9. 9. What is plone.app.relations • A content-centric API for defining and querying relationships: src = IRelationshipSource(ob) src.createRelationship(target=ob2) src.getTargets() ... • A set of optional adapters and subscribers • DCWorkflow for relationships • “Holding” relationships • Relationships which are copied when their source is copied.
  10. 10. Relationship Sources • IRelationshipSource • Create (createRelationship), supports multiple targets • Query (getTargets, isLinked, getRelationshipChains, getRelatonships) • Modify (deleteRelationship, getRelationships)
  11. 11. Relationship Targets • IRelationshipTarget • Same query methods and parameters as IRelationshipSource + getSources • ISymmetricRelation • Query (isLinked, getRelationships, getRelations) • No transitivity, for now
  12. 12. Brief Code Example >>> class IFriendship(IDCWorkflowableRelationship): ... “””A friendship””” >>> source = IRelationshipSource(ob1) >>> rel = source.createRelationship(ob2, relation=’friend’, ... interfaces=(IFriendship,)) >>> list(source.getRelationships(relation=’friend’)) [<Relationship ‘friend’ from (<Demo ob1>,) to (<Demo ob2>,)] >>> list(rel.targets), list(rel.sources) ([<Demo ob2>], [<Demo ob1>]) >>> list(source.getTargets()) [<Demo ob2>] >>> list(source.getRelationshipChains(target=ob2, maxDepth=5)) [(<Relationship ‘friend’ from (<Demo ob1>,) to (<Demo ob2>,)>,)] >>> target = IRelationshipTarget(ob2) >>> list(target.getSources(relation-’friend’)) [<Demo ob1>] >>> target.isLinked(source=ob1) True >>> list(ISymmetricRelation(ob1).getRelations()) [<Demo ob2>] >>> list(ISymmetricRelation(ob2).getRelations()) [<Demo ob1>] >>> wf_rel = IDCWorkflowRelation(rel) >>> wf_rel.workflow_id = ‘friend_workflow’ >>> wf.doAction(‘approve’) >>> wf.state ‘approved’
  13. 13. What Can You Do With It? • Model any non-container relationships you might need. • Social Networking (user user, user group/workspace) • User Favorites (user content) • Placeless Content • Taxonomies or Complex Vocabularies • Related Content
  14. 14. What Have I Done With It? • The Daily Reel (http://www.thedailyreel.com) • Social network for online video creators • Contacts (user relationships with approval) • Crews (discussion groups) • Videos which “belong” to crews and users (placeless content) • Favorite Content
  15. 15. Brief UI Demo
  16. 16. Shortcomings • Relationships are inherently asymmetric, with sources and targets on unequal footing. • Relationships are unordered • Requires persistent sources/targets/ contexts. • Uses IntIds: fast but limits the number of indexed objects to sys.maxint. • No user-space tools/UI, yet.
  17. 17. When to Use Something Else • Efficient sorting on a large result set of relationships. • Complex queries. Currently there’s only ‘==’ (for source/target, state, context) • Non-ZODB objects • Don’t have time to make your own UI (stick with AT for now)
  18. 18. The Future? • Support for explicit ordering of relationships • API providing permission based filtering • UI (schema field, formlib widget) • Move general code downstream into zc.relationship
  19. 19. Thank You! • Special thanks to • Balazs Ree • Gary Poster and Zope Corporation • Whit Morriss • Ramon Navarro Bosch • The Daily Reel • Vincenzo and the conference organizers • And now we sprint!!
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×