Question

My custom dexterity type looks like this:

class IMyType(form.Schema):
    title = schema.TextLine(
        title=_(u"Title"),
    )
    address = schema.TextLine(
        title=_(u"Address"),
        required=False,
    )

class MyType(dexterity.Container):
    grok.implements(IMyType)

I want the Live Search result looks like this, listing its title and first 3 char of the address value if existing:

Item One
  Address[:3]

Item Two
  Address[:3]

By default, each item matched will show its title and description. Thus, one solution is making the description field computed from the address field. But I don't know how. Any hint or better suggestion?

Was it helpful?

Solution 2

You could override the Description index for your specific type using plone.indexer. This way the catalog has the right information and you don't have to customize the search result.

from plone.indexer import indexer

@indexer(IMyType)
def custom_description(obj, **kw):
    return obj.Description[:3]

Register

<adapter name="description" factory=".indexers.custom_description" />

Check plone.indexer documentation on pypi https://pypi.python.org/pypi/plone.indexer

OTHER TIPS

Quoting http://somedoma.in:8080/somePloneSiteId/portal_catalog/manage_catalogSchema:

"It is important to understand that when the Catalog is searched, it returns a list of result objects, not the cataloged objects themselves, so if you want to use the value of an object's attribute in the result of a search, that attribute must be in this list"

So, after adding your fieldname to the metadata-index, you can customize livesearch_reply, to achieve what you want, insert after line 52 (Products.CMFPlone-4.3) where "display_description" is set, this:

if result.portal_type == 'yourtype':
    display_description = safe_unicode(result.address)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top