Building a site tree with the ZCatalog
Hi there I use Zope 2.10.5 and I want to create a site tree using the ZCatalog instead of iterating recursive trough the entire object tree. I have the following site structure (all things are folders): - about --- company --- staff ----- homepages ------- phelps --- phonebook --- jobs - research --- ocean ----- atlantic ----- pacific --- lake --- river My ZCatalog contains these entries: - /research - /research/ocean - /research/ocean/pacific - /research/ocean/atlantic - /research/lake - /research/river - /about - /about/company - /about/staff - /about/staff/homepages - /about/staff/homepages/phelps - /about/staff/phonebook - /about/jobs - /about What I need is a list of these entries ordered according to the site structure. I would like to get this list: ['/about', '/about/company', '/about/staff', '/about/staff/homepages', '/about/staff/homepages/phelps', '/about/phonebook', '/about/jobs', '/research', '/research/ocean', '/research/ocean/atlantic', '/research/ocean/pacific', '/research/lake', '/research/river' ] My Zcatalog is configured as follows: Indexes: - path - position - title - id Metadata: - physical_path - title - id The index 'position' contains the a folder's position in it's parent folder. In my example the folder "phonebook" contains "3" for position because it is in the 3rd position inside it's parent folder ("about"). Is it possible to build an ordered site tree with the ZCatalog only and if so, any ideas how I can do that? Regards Nico
On 21.10.2008 16:27 Uhr, Nico Grubert wrote:
Hi there
I use Zope 2.10.5 and I want to create a site tree using the ZCatalog instead of iterating recursive trough the entire object tree.
I have the following site structure (all things are folders):
- about --- company --- staff ----- homepages ------- phelps --- phonebook --- jobs - research --- ocean ----- atlantic ----- pacific --- lake --- river
My ZCatalog contains these entries: - /research - /research/ocean - /research/ocean/pacific - /research/ocean/atlantic - /research/lake - /research/river - /about - /about/company - /about/staff - /about/staff/homepages - /about/staff/homepages/phelps - /about/staff/phonebook - /about/jobs - /about
What I need is a list of these entries ordered according to the site structure. I would like to get this list: ['/about', '/about/company', '/about/staff', '/about/staff/homepages', '/about/staff/homepages/phelps', '/about/phonebook', '/about/jobs', '/research', '/research/ocean', '/research/ocean/atlantic', '/research/ocean/pacific', '/research/lake', '/research/river' ]
My Zcatalog is configured as follows: Indexes: - path - position - title - id Metadata: - physical_path - title - id
The index 'position' contains the a folder's position in it's parent folder. In my example the folder "phonebook" contains "3" for position because it is in the 3rd position inside it's parent folder ("about").
Is it possible to build an ordered site tree with the ZCatalog only and if so, any ideas how I can do that?
Look at the ExtendedPathIndex implementation of Plone (can be used outside Plone). -aj
On Tue, Oct 21, 2008 at 17:22, Andreas Jung <lists@zopyx.com> wrote:
Look at the ExtendedPathIndex implementation of Plone (can be used outside Plone).
And how do you think ExtendedPathIndex help with sorting here? In this case, some custom sorting would be required in a python method or view. -- Martijn Pieters
On 21.10.2008 17:45 Uhr, Martijn Pieters wrote:
On Tue, Oct 21, 2008 at 17:22, Andreas Jung<lists@zopyx.com> wrote:
Look at the ExtendedPathIndex implementation of Plone (can be used outside Plone).
And how do you think ExtendedPathIndex help with sorting here?
In this case, some custom sorting would be required in a python method or view.
Code-solving-everything does not fall from the sky. EPI likely the best starting point for solving the problem. Andreas
On Tue, Oct 21, 2008 at 17:50, Andreas Jung <lists@zopyx.com> wrote:
Code-solving-everything does not fall from the sky. EPI likely the best starting point for solving the problem.
But what the EPI offers over the regular path index has no bearing on Nico's problem. -- Martijn Pieters
On 21.10.2008 17:56 Uhr, Martijn Pieters wrote:
On Tue, Oct 21, 2008 at 17:50, Andreas Jung<lists@zopyx.com> wrote:
Code-solving-everything does not fall from the sky. EPI likely the best starting point for solving the problem.
But what the EPI offers over the regular path index has no bearing on Nico's problem.
You have to split the complete processing over several EPI queries where a single query returns all elements with level=1 for a particular subfolder. You can sort_on='position' within each query. And paste the results in some way together. Nobody said that EPI would solve the problem out-of-the-box :-) Andreas -- ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany Web: www.zopyx.com - Email: info@zopyx.com - Phone +49 - 7071 - 793376 Registergericht: Amtsgericht Stuttgart, Handelsregister A 381535 Geschäftsführer/Gesellschafter: ZOPYX Limited, Birmingham, UK ------------------------------------------------------------------------ E-Publishing, Python, Zope & Plone development, Consulting
On Tue, Oct 21, 2008 at 18:10, Andreas Jung <lists@zopyx.com> wrote:
You have to split the complete processing over several EPI queries where a single query returns all elements with level=1 for a particular subfolder. You can sort_on='position' within each query. And paste the results in some way together. Nobody said that EPI would solve the problem out-of-the-box :-)
Right, so with sufficient levels you end up with a *lot* of queries. Why not just query for the whole lot and use one method that returns a (path, position) tuple for a given item, and pass that to the sort function as the key keyword? Should be a lot better performing. -- Martijn Pieters
On 21.10.2008 18:25 Uhr, Martijn Pieters wrote:
On Tue, Oct 21, 2008 at 18:10, Andreas Jung<lists@zopyx.com> wrote:
You have to split the complete processing over several EPI queries where a single query returns all elements with level=1 for a particular subfolder. You can sort_on='position' within each query. And paste the results in some way together. Nobody said that EPI would solve the problem out-of-the-box :-)
Right, so with sufficient levels you end up with a *lot* of queries.
Why not just query for the whole lot and use one method that returns a (path, position) tuple for a given item, and pass that to the sort function as the key keyword? Should be a lot better performing.
If this would be a programming contest then you would cache the results and don't care about the performance for the initial calculation. Andreas
In a context where you need to obtain the whole list the Martijn solutions sounds better in my ears because the Andreas one do more times the bottleneck In a context where you will complete the list as soon as you need (as Zope Smart Manager) the Andreas one sounds better Only my point of view ;) 2008/10/21 Andreas Jung <lists@zopyx.com>
On 21.10.2008 18:25 Uhr, Martijn Pieters wrote:
On Tue, Oct 21, 2008 at 18:10, Andreas Jung<lists@zopyx.com> wrote:
You have to split the complete processing over several EPI queries where a single query returns all elements with level=1 for a particular subfolder. You can sort_on='position' within each query. And paste the results in some way together. Nobody said that EPI would solve the problem out-of-the-box :-)
Right, so with sufficient levels you end up with a *lot* of queries.
Why not just query for the whole lot and use one method that returns a (path, position) tuple for a given item, and pass that to the sort function as the key keyword? Should be a lot better performing.
If this would be a programming contest then you would cache the results and don't care about the performance for the initial calculation.
Andreas
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Mis Cosas http://blogs.sistes.net/Garito Zope Smart Manager http://blogs.sistes.net/Garito/670
And how do you think ExtendedPathIndex help with sorting here?
In this case, some custom sorting would be required in a python method or view.
It's the combination of both the indexes "position" and the "ExtendedPathIndex" which provides a depth parameter that solved my problem. No expensive object calls which results in heavy CPU usage if your tree contains severy hundres or even thousands of items. @ Martijn I used this for a Silva CMS Site to create a Navigation Tree. After this project has been gone online (expected in the next 1 or 2 weeks) I'll write a how-to to share this to other Silva developers. My first attempt was to use the "_get_container_tree()" method provided by Silva and cached the result as a list of dictionaries. Unfortunately the initial call took several minutes (I have a huge tree) and the system was almost frozen during that time. Thanks for the ExtendedPathIndex tip, Andreas. The usage of the "depth" parameter is exactly what I needed to recursively go through the tree without any object-wakups. Regards, Nico
participants (4)
-
Andreas Jung -
Garito -
Martijn Pieters -
Nico Grubert