[ZCM] [ZC] 1955/ 4 Comment "zcatalog does not index on item-access"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Wed Nov 23 11:39:18 EST 2005


Issue #1955 Update (Comment) "zcatalog does not index on item-access"
 Status Accepted, Zope/feature+solution medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/1955

==============================================================
= Comment - Entry #4 by tseaver on Nov 23, 2005 11:39 am

Dieter Maurer's ManageableIndex uses a TALES expression to extract
the indexed value;  it likely does exactly what the OP wants:

  http://www.dieter.handshake.de/pyprojects/zope/#ManagableIndex
________________________________________
= Edit - Entry #3 by efge on Nov 23, 2005 8:36 am

 Changes: submitter email, edited transcript, classification (bug+solution => feature+solution)
________________________________________
= Comment - Entry #2 by efge on Nov 23, 2005 8:35 am

That's not a bug, it's a feature request. Current catalog indexes are designed to access attributes. There's no reason to change this in base classes, it would surely break things.

You can write your own index if you want to change this.

-1 on this patch.

________________________________________
= Request - Entry #1 by tino on Nov 22, 2005 5:54 pm

 Status: Pending => Accepted

 Supporters added: tino

ZCatalog currently does not index on item access,
meaning it only evaluates obj.attr 
instead of also obj['attr'] like many other places
where zope accesses subobjects.

This way you cannot easily construct virtual objects
using dictionaries (as seen in "catalog almost anything" howto)

And several other problems, where you dont have true
attributes but objects support item access (particulary
to avoid uber namespace clutter)

Following code is responsible:

---------------------------------------------------
lib/python/Products/PluginIndexes/common/UnIndex.py

line 269 ff:
------------ snip ---------------------------------
    def _get_object_datum(self,obj, attr):
        # self.id is the name of the index, which is also the name of the
        # attribute we're interested in.  If the attribute is callable,
        # we'll do so.
        try:
            datum = getattr(obj, attr)
            if safe_callable(datum):
                datum = datum()
        except AttributeError:
            datum = _marker
        return datum

------- replace with ------------------

    def _get_object_datum(self,obj, attr):
        # self.id is the name of the index, which is also the name of the
        # attribute we're interested in.  If the attribute is callable,
        # we'll do so.
        try:
            datum = getattr(obj, attr)
            if safe_callable(datum):
                datum = datum()
        except AttributeError:
            try:
                datum = obj[attr]
            except (TypeError,KeyError):
                datum = _marker
        return datum

---------------------------------------------------
lib/python/Products/PluginIndexes/KeywordIndex/KeywordIndex.py

line 97ff:
----------- snip ----------------------------------
    def _get_object_keywords(self, obj, attr):
        newKeywords = getattr(obj, attr, ())
        if safe_callable(newKeywords):
            newKeywords = newKeywords()

---------- replace --------------------------------
    def _get_object_keywords(self, obj, attr):
        newKeywords=self._get_object_datum(obj, attr)

---------------------------------------------------
(the latter also avoids code duplicates)

Should I proceed? (usual unittests and yada, yada)
==============================================================



More information about the Zope-Collector-Monitor mailing list