[triangle-zpug] RE: triangle-zpug Digest, Vol 32, Issue 2

Paul Smith paul at blinkylights.org
Fri Dec 2 17:24:27 CET 2005


On Dec 1, 2005, at 3:38 PM, Dimauro, Frank wrote:

> can anyone help me alter this so that I search only a specific  
> directory on
> my Plone site?




Hey Frank,
     The easiest thing to do might be to just go straight to the  
portal_catalog with your own query rather than using the queryCatalog  
script. You could make your own script object with something like  
this in it:


#title=searchHR
#parameters=searchstring=None,searchpath="/site"

results = context.portal_catalog.searchResults(
    path = searchpath,
    SearchableText = searchstring,
    )

return results


     Andy McKay's book has a good section on querying the catalog,  
and if you don't have it, you can get it in PDF format at plone.org.  
A caveat on doing queries this way: for the sake of efficiency, the  
things in the 'results' list aren't the objects themselves, but  
"brains"... they just contain index and metadata. You can get the  
objects with brain.getObject(), or if you're sure your query is never  
going to return a big list, you can do this:

results = context.portal_catalog.searchResults(
    path = searchpath,
    SearchableText = searchstring,
    full_objects = True,
    )



HTH,
--Paul



More information about the triangle-zpug mailing list