[Zope] reversing a LazyMap from a Catalog

Casey Duncan casey@zope.com
Wed, 27 Mar 2002 15:21:42 -0700


Here's a possible solution:

create a one line py script (possibly in the catalog) that returns the 
title. Then create a field index on this python script, which will be 
acquired at index time. You could call the python script "sortTitle" or
"fieldTitle" for example to differenciate it.

Then sort on that index. You definitely want to use the Catalog sorting 
here and not reverse or some external sort.

hth,

-Casey

notices name wrote:
> Hi. I'm very new to all this, and I have a wierd problem with my catalog results. I have four catalogs, which I update in a batch from mysql. I find that if I query MySQL with an ORDER BY title DESC, then my catalog searches give me results in alphabetical order, which is great. Now, if my searches have no results, I'm supposed to give the user the whole contents of the catalog (thank god for batching!). I did that by setting the search terms to "" in the request, but it comes out in reverse alphabetical order. I tried to use the list reverse function, but the result seems to be a LazyMap, not a list and I can't figure out how to reverse it efficiently. I also tried request.set("sort_on","title"), but that doesn't work because it's a text index, not field.  Any ideas? Thanks a lot,
> Annie
> 
> This script piece gets the catalog results. It is called from the results page. 
> 
> if not(request.has_key('all')):             # check to see if user wanted the whole list
>         found = container.np.pc.pcCatalog()    
>         if len(found) > 0:
>             return found                        # if there was a result return it  
>         request.set("badsearch","true")   # if not, set flag for badsearch message 
>     request.set("city","")                     # clear search terms from request
>     request.set("state","")
>     request.set ("title","")
>     return container.np.pc.pcCatalog()   # this returns the whole catalog in reverse alphabetical order??
> 
> 
> This script piece loads the urls from mysql
> #empty the old urls      
> objectsToDelete = context.np.pc.objectIds('newspaper URL holder')
> context.np.pc.manage_delObjects(ids=objectsToDelete)
> 
> #add the new
> id = 0
> for record in container.pc.getPcUrls():
>     id=id+1 
>     idstring = str(id)    
>     context.np.pc.manage_addProduct['newspaperURL'].newspaperURL.createInObjectManager(idstring, context.REQUEST)
>     newURL = context.np.pc[idstring]
>     newURL.manage_editCataloger('pcCatalog')
>     newURL.propertysheets.newspaperURLProperties.manage_changeProperties(req,city=record.city,state=record.state,newspaperurl=record.web_url,deviceType='pc',naaid=record.naaid,title=record.newspaper_name)    
>     newURL.reindex_object()
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> 
>