[Zope-dev] ZCatalog and indexing DTML methods

Stuart 'Zen' Bishop zen@cs.rmit.edu.au
Sat, 23 Oct 1999 10:35:03 +1000 (EST)


On Sun, 17 Oct 1999, Michel Pelletier wrote:

> > Would it be possible to modify Catalog to do this? I think the
> > necessary section to modify would be recordify in Catalog.py.
> > The first argument to a DTML Method call would just be the object
> > passed to recordify. I'm unsure how to fake up the REQUEST attribute
> > though. Is this the right way to proceed?
> 
> The problem here is that an assumption is being made, passing an object
> in as the first argument to a bound method.  The whole argument passing
> concept in general is ripe with complication, as everyone and their
> brother is going to want to call a method their way, although I do agree
> that calling DTML methods with a context is useful.
> 
> I'll have to think about this a bit to see if there is a general
> solution, in the mean time you can of course modify your code (you found
> the right spot).  Anyone else have any ideas?

How does the following sound for a solution?:

    Each index and column in the ZCatalog has three variables - 
    name, type and expression. Name and type are as they already are.
    If expression is empty, then behaviour works exactly like it does now.

    If expression is not empty, it is passed to the object for evaluation,
    along with a fake REQUEST object and whatever else is deemed necessary.
    This method would have to be added to Base or similar base class if
    there is currently no way of doing this.

    eg.
	expr = title		
	expr = myMethod(this(),REQUEST)
	expr = id + ': ' + title
	expr = absolute_url()


    Slight modification to this might be:

	Only evaluate the expression if the object does not have an attribute
	matching the index name

    or

	Only evaluate the expression if the object does not have a non
	callable attribute matching the index name

    or

	Only evaluate the expression if the object does not have an attribute
	matching the index name, or this attribute returned a false value
	or threw an exception.


The last option would allow me to provide a fallback if a given attribute
is not set (eg. an index [summary, TextIndex, "id + title"] or
[summary, TextIndex, "text[:256]"] or [summary, TextIndex, "buildSummary()"]

 ___
   //     Zen (alias Stuart Bishop)     Work: zen@cs.rmit.edu.au
  // E N  Senior Systems Alchemist      Play: zen@shangri-la.dropbear.id.au
 //__     Computer Science, RMIT 	 WWW: http://www.cs.rmit.edu.au/~zen