문제

I have lots of Dexterity content types, some of them are just containers and are left with just the Title and Description (from plone.app.dexterity.behaviors.metadata.IBasic behavior).

I can find them by searching the text inside their title or description.

But for some complex content types I'm using collective.dexteritytextindexer to index some more fields and it works fine, I can find the text on the fields I marked to be indexed.

However the Title and Description are no longer available for searching. I tried something like:

class IMyContent(form.Schema):
    """My content type description
    """

    dexteritytextindexer.searchable('title')
    dexteritytextindexer.searchable('description')

    dexteritytextindexer.searchable('long_desc')
    form.widget(long_desc = WysiwygFieldWidget)
    long_desc = schema.Text (
            title = _(u"Rich description"),
            description = _(u"Complete description"),
            required = False,
        )
    ...

But I can't see the content of title and description on the SearchableText column in the portal_catalog, and thus the results don't show them.

Any idea what I'm missing?

Cheers,

도움이 되었습니까?

해결책 3

As a reference this is the code I ended up writing:

@indexer(IMyDexterityType)
def searchableIndexer(context):
    transforms = getToolByName(context, 'portal_transforms')
    long_desc = context.long_desc // long_desc is a rich text field
    if long_desc is not None:
        long_desc = transforms.convert('html_to_text', long_desc).getData()
    contacts = context.contacts // contacts is also a rich text field
    if contacts is not None:
        contacts = transforms.convert('html_to_text', contacts).getData()

    return "%s %s %s %s" % (context.title, context.description, long_desc, contacts,)
grok.global_adapter(searchableIndexer, name="SearchableText")

다른 팁

Got pretty much the same issue. Following the documentation on http://pypi.python.org/pypi/collective.dexteritytextindexer I used

from collective import dexteritytextindexer
from plone.autoform.interfaces import IFormFieldProvider
from plone.directives import form
from zope import schema
from zope.interface import alsoProvides

class IMyBehavior(form.Schema):

    dexteritytextindexer.searchable('specialfield')
    specialfield = schema.TextField(title=u'Special field')

alsoProvides(IMyBehavior, IFormFieldProvider)

to get my own fields indexed. However, the code

from plone.app.dexterity.interfaces import IBasic
from collective.dexteritytextindexer.utils import searchable

searchable(IBasic, 'title')
searchable(IBasic, 'description')

Didn't work. The import of IBasic fails. Seems this can easily be solved by importing

from plone.app.dexterity.behaviors.metadata import IBasic

The problem is probably that the field is coming from the IBasic or IDublineCore behaviour and not from your schema. I don't know enough about collective.dexteritytextindexer to know how to work around this, though.

Another option may be to just use plone.indexer and create your own SearchableText indexer that returns "%s %s %s" % (context.title, context.description, context.long_desc,). See the Dexterity docs for details.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top