[Zope3-Users] querying the catalog

Duncan McGreggor duncan.mcgreggor at gmail.com
Fri Sep 30 20:34:24 EDT 2005


On Sep 30, 2005, at 6:14 PM, Alen Stanisic wrote:

> Can your catalog live in root '/' site rather than 'accumac' site.

Honestly, this would be a partial defeat of the usefulness of having 
the ability to make folders into full-blown sites. We need to be able 
to use the resources that are allocated for each "sub-site"... you 
know?

> Utilities are looked up in local sites than if not found they will be
> looked up in parent site and so on until root site is hit. I don't 
> think
> utility look up will go on to search across in sites not in the same
> branch.

The accumac site is where the catalog is, but it is also where the 
content it... it's the context of the whole app. For instance, the 
homepage content object lives here:

   /accumac/index.html

Instances of the equipment content object are here:

   /accumac/equipment

And the catalog for the site is here (and it's the only catalog 
instance in the local site):

   /accumac/++etc++site/default/accumac_catalog

The IntId instance lives parallel to the local catalog, too. Does this 
explain the layout better? If not, then I have misunderstood your 
comment...

d

>
> Alen
>
> On Fri, 2005-09-30 at 16:33 -0600, Duncan McGreggor wrote:
>> I have a multiple sites on a zope3 instance (folders at the top level
>> that have their own site managers). In one of them, there is page
>> content object with a custom view for portraying search results from
>> its (local) catalog. However, I have had a great deal of difficulty
>> getting the catalog I want. Here is the pertinent code for three
>> attempts, the last of which "worked".
>>
>> Attempt #1
>>
>> class HomePageView(BrowserView):
>>      def inventoryInStock(self):
>>          catalog = zapi.getUtility(ICatalog,
>>              name='accumac_catalog',
>>              context=self.context)
>>          return catalog.searchResults(equipment_in_stock=[True])
>>
>> Attempt #2
>>
>> class HomePageView(BrowserView):
>>      def inventoryInStock(self):
>>          sm = zapi.traverse(self.context, '++etc++site')
>>          catalog = sm['default']['accumac_catalog']
>>          return catalog.searchResults(equipment_in_stock=[True])
>>
>> Attempt #3
>>
>> class HomePageView(BrowserView):
>>      def inventoryInStock(self):
>>          sm = zapi.traverse(self.context, '/accumac/++etc++site')
>>          catalog = sm['default']['accumac_catalog']
>>          return catalog.searchResults(equipment_in_stock=[True])
>>
>>
>> The first attempt got the catalog at the root of the zope 3 instance 
>> if
>> I passed no name; if I passed the name of the local catalog, I got the
>> following error:
>>
>> ComponentLookupError: (<InterfaceClass
>> zope.app.catalog.interfaces.ICatalog>, 'accumac_catalog')
>>
>> A clue as to why this happened may be in attempt #2. The error for
>> attempt #2 was:
>>
>> TraversalError: (<accumacsite.homepage.HomePage object at 0x2e688f0>,
>> 'site')
>>
>> And this might be a clue; it made me think that if the HomePage 
>> content
>> object was traversable, in both attempt #1 and #2, the correct catalog
>> would have been found.
>>
>> In attempt #3, I had zope traverse to the absolute location of the
>> local site manager, and from there got the correct catalog, with the
>> results being returned properly. However, this last attempt seems
>> rather hackish, as it uses a path and hard-coded names. I'd really 
>> like
>> to do this the right way.
>>
>> Does anyone have advice on this?
>>
>> Thanks!
>>
>> Duncan
>>
>> _______________________________________________
>> Zope3-users mailing list
>> Zope3-users at zope.org
>> http://mail.zope.org/mailman/listinfo/zope3-users
>



More information about the Zope3-users mailing list