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?

有帮助吗?

解决方案 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

其他提示

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)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top