This took me a while to grok and perhaps by mentioning it here, it'll prevent other people from making the same mistake as I did and perhaps preventing myself from doing the same mistake again.

In the ZCatalog, when you set up indexes you can give them a name and an index attribute. If you omit the index attribute, it'll try to hook into the objects by the name of the index. For example, if you set the index to be title with no indexed attribute it'll fetch the title attribute of the objects it catalogs. But if you set the indexed attribute to be something like idx_getTitle you can do something like this in your class:


def idx_getTitle(self):
   """ return title as we want it to be available in the ZCatalog """
   return re.sub('<*.?>','', self.title)

The same can not be done with indexes of type DateIndex.

DateIndex in Zope doesn't have indexed attributes I don't know why it is so but perhaps there's a good explanation that I don't understand. If you use the ZMI it's clear that you can't add an indexed attribute but it doesn't stop you from adding one in pure python like you do with all other indexes:


from ZPublisher.HTTPRequest import record
zcatalog = self.MyCatalog
indexes = zcatalog._catalog.indexes

# this works
extra = record()
extra.indexed_attrs = 'getSearchableCountry'
zcatalog.addIndex('country', 'FieldIndex', extra)

# this does NOT work!
extra = record()
extra.indexed_attrs = 'getPublishDateHourless'
zcatalog.addIndex('publish_date', 'DateIndex', extra)

If you run this code, it'll even pick up the method getPublishDateHourless in the ZMI view of the catalog's indexes. But it's never run!

By the way, what I wanted to achieve was to index the publish date of certain objects but only index them without the hour/minute/second bit. Because I couldn't have such a "proxy method" I instead searched on the index publish_date with a range like this:


zcatalog = self.MyCatalog
v = DateTime('2007/12/13')
query = {'query':[v, v+1], 'range':'min:max'}
return zcatalog.searchResults(publish_date=query)

Comments

Your email will never ever be published.

Previous:
Piteå, as experienced by Sam Dunstan October 25, 2007 Sweden
Next:
Now I'm on Last.fm October 30, 2007 Music
Related by category:
'Cache-Control' or Expires September 16, 2005 Zope
To all Zope developers: Does this sound familiar? March 8, 2011 Zope
IssueTrackerProduct now officially abandoned March 30, 2012 Zope
Sending HTML emails in Zope October 26, 2006 Zope
Related by keyword:
Inspecting the index size in PostgreSQL April 21, 2025 PostgreSQL
The correct way to index data into Elasticsearch with (Python) elasticsearch-dsl May 14, 2021 Python, MDN, Elasticsearch
EditArea vs. CodePress January 3, 2008 Web development
Filename splitter November 15, 2005 Zope, Python