[Grok-dev] How do I look up a grok.Indexes utility so I can call methods on an index?

Sebastian Ware sebastian at urbantalk.se
Wed Aug 25 09:16:48 EDT 2010


I have a value index from zc.catalog and I want to use the implemented sort method. However, I don't understand how to look up the actual index. The index is defined as:

class SitePublishCatalog(grok.Indexes):
    grok.site(Testvalueindex)
    grok.context(IPublished)
    grok.name('content_index')

    published = Value()

I want to be able to do call index.sort(res) on my results that come from hurry.query, in the way explained in the zc.catalog doctest.

"""
Sorting
-------

Value indexes supports sorting, just like zope.index.field.FieldIndex.

    >>> index.clear()

    >>> index.index_doc(1, 9)
    >>> index.index_doc(2, 8)
    >>> index.index_doc(3, 7)
    >>> index.index_doc(4, 6)
    >>> index.index_doc(5, 5)
    >>> index.index_doc(6, 4)
    >>> index.index_doc(7, 3)
    >>> index.index_doc(8, 2)
    >>> index.index_doc(9, 1)

    >>> list(index.sort([4, 2, 9, 7, 3, 1, 5]))
    [9, 7, 5, 4, 3, 2, 1]
"""

Mvh Sebastian





More information about the Grok-dev mailing list