Package: collective.dexteritytextindexer
Introductioncollective.dexteritytextindexerprovides a dynamic SearchableText indexer for
dexterity content types. It makes it possible to index fields of multiple
behaviors as SearchableText.UsageFor enabling the indexer just add the behavior to the list of behaviors of your
content types.In yourprofiles/default/types/YOURTYPE.xmladd the behavior:<?xml version="1.0"?>
<object name="example.conference.presenter" meta_type="Dexterity FTI"
   xmlns:i18n="http://xml.zope.org/namespaces/i18n"
   i18n:domain="example.conference">

 <!-- enabled behaviors -->
 <property name="behaviors">
     <element value="collective.dexteritytextindexer.behavior.IDexterityTextIndexer" />
 </property>

</object>Now you need to mark the fields you want to have in your SearchableText. This
is done with directives:from collective import dexteritytextindexer
from plone.autoform.interfaces import IFormFieldProvider
from plone.supermodel.model import Schema
from zope import schema
from zope.interface import alsoProvides

class IMyBehavior(Schema):

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

alsoProvides(IMyBehavior, IFormFieldProvider)If you want to mark fields of an existing 3rd party behavior, it can be
done using this utility function:from plone.app.dexterity.behaviors.metadata import ICategorization
from collective.dexteritytextindexer.utils import searchable

searchable(ICategorization, 'categorization')Thetitleanddescriptiononplone.app.dexterity’sIBasicbehavior
are marked as searchable by default.
For marking them as no longer searchable, there is a utility function:from plone.app.dexterity.behaviors.metadata import IBasic
from collective.dexteritytextindexer.utils import no_longer_searchable

no_longer_searchable(IBasic, 'title')Alternatively, if you specified your model as a plone.supermodel XML model,
you can mark the field searchable that way:<model xmlns="http://namespaces.plone.org/supermodel/schema"
       xmlns:indexer="http://namespaces.plone.org/supermodel/indexer">
  <schema based-on="plone.supermodel.model.Schema">

      <field name="specialfield" type="zope.schema.TextLine"
             indexer:searchable="true">
        <title>Special field</title>
      </field>

  </schema>
</model>Your SearchableText indexer includes now your custom field on your behavior, as
soon you enable it in your content type, whereIDexterityTextIndexerbehavior
is enabled too.Registering a custom field converterBy default, a field is converted to a searchable text by rendering the widget
in display mode and transforming the result to text/plain. However, if you need
to convert your custom field in a different way, you only have to provide a
more specific converter multi-adapter.Convert multi-adapter specification:Interface:collective.dexteritytextindexer.IDexterityTextIndexFieldConverterDiscriminators:context, field, widgetExample:from collective.dexteritytextindexer.converters import DefaultDexterityTextIndexFieldConverter
from collective.dexteritytextindexer.interfaces import IDexterityTextIndexFieldConverter
from my.package.interfaces import IMyFancyField
from plone.dexterity.interfaces import IDexterityContent
from z3c.form.interfaces import IWidget
from zope.component import adapts
from zope.interface import implementer

@implementer(IDexterityTextIndexFieldConverter)
class CustomFieldConverter(DefaultDexterityTextIndexFieldConverter):
    adapts(IDexterityContent, IMyFancyField, IWidget)

    def convert(self):
         # implement your custom converter
         # which returns a string at the end
         return ''ZCML:<configure xmlns="http://namespaces.zope.org/zope">

    <adapter factory=".converters.CustomFieldConverter" />

</configure>There is already an adapter for converting NamedFiles properly. It’s registered
only ifplone.namedfileis installed.Extending indexed dataSometimes you need to extend the SearchableText with additional data which is
not stored in a field. It’s possible to register a named adapter which provides
additional data:from collective import dexteritytextindexer
from zope.component import adapts
from zope.interface import implementer

implementer(dexteritytextindexer.IDynamicTextIndexExtender)
class MySearchableTextExtender(object):
    adapts(IMyBehavior)

    def __init__(self, context):
        self.context = context

    def __call__(self):
        """Extend the searchable text with a custom string"""
        return 'some more searchable words'ZCML:<configure xmlns="http://namespaces.zope.org/zope">

    <adapter factory=".indexer.MySearchableTextExtender"
             name="IMyBehavior"
             />

</configure>This is anamedadapter! This makes it possible to register multiple
extenders for the same object on different behavior interfaces. The name of
the adapter does not matter, but it’s recommended to use the name of the
behavior (this may reduce conflicts).If your behavior has a defined factory (which is not attribute storage), then
you need to define a marker interface and register the adapter on this marker
interface (dexterity objects do not provide behavior interfaces of behaviors,
which are not using attribute storage).Contributors(In order of appearance)Jonas BaumannPhilippe GrossLukas GrafIzhar FirdausSune Broendum WoellerNejc ZupanChangelog2.4.1 (2022-03-31)Fixed duplicated values in SearchableText.
[gbastien]Fix a bug in the RichText field indexer on Python 3.
[alecpm]2.4.0 (2020-01-24)Add behavior shortname “collective.dexteritytextindexer”
[agitator]2.3.0 (2019-09-27)A few updates to make build pass on travis again, i.e.
add index/allow-hosts to buildout configs,
set version.cfg reference to ‘latest’ for 5.0.x,
bump setuptools and zc.buildout versions
[staeff]Update the Add-On to also run in Plone 5.2 with Python 3.
Fixeshttps://github.com/collective/collective.dexteritytextindexer/issues/31[staeff]2.2.1 (2017-07-26)Fix a bug in the RichText field indexer when the value of RichText field is None.
The bug was introduced in 2.2.0.
[mbaechtold]2.2.0 (2017-06-23)Added TupleFieldConverter, to enable indexing of portal catalog KeywordIndex indices.
[jone, mtrebron, maurits]Improved code quality.  [maurits]Add the ability to index a RichText field. Fixes #23.
[smcmahon]2.1.1 (2016-11-03)Remove traces of plone.directives.form (which implicitly added grok as a dependency).
[gforcada]Silent a plone.behavior warning.
[gforcada]Specify compatibility in setup.py for versions which are tested and remove
unittest2 dependency
[tomgross]2.1.0 (2016-04-14)Add schemaeditor support
[datakurre]2.0.2 (2016-04-07)Handle indexing from scripts.
Fixeshttps://github.com/collective/collective.dexteritytextindexer/issues/12[gforcada]2.0.1 (2014-01-02)Fix encoding error when transforming HTML to text.
[jone]2.0 (2013-03-16)Drop Plone 4.1 support.
[jone]Mark title and description of p.a.dexterity’s IBasic
as searchable by default.
[jone]Add a no_longer_searchable utility function.
[jone]Plone 4.3 support.
[jone]Eliminate grok / martian dependencies in favor of the new plone.supermodel directives. #5
[jone]1.5.1 (2013-02-20)Do not try to convert text/plain in files, just index it as it is.
[zupo]1.5 (2012-08-16)Fix missing field bug. #3Log an error when indexing an object and one of its schemas defines a missing
field as searchable.Make sure that indexing other existing fields of the same schema works.searchable utils function: raise AttributeError when field is missing.[jone]Added support for marking fields searchable in plone.supermodel XML models.
This is done by implementing a IFieldMetadataHandler that is capable of
serializing/de-serializing the corresponding taggedValue to/from XML.
[lgraf]Addutils.searchablemethod for marking fields of third party schemas as searchable.
[kagesenshi]1.4.1 (2011-11-17)ignore the request in the get_field_widget method, to avoid problems with request variables wich have the same name than the field.
[phgross]Added test-buildout for plone-4.1.x
[lgraf]1.4 (2011-08-24)Added IntFieldConverter, wich return the plain value instead of the render method (600000 –> 600,000)
[phgross]1.3Fixed querying of tagged values: use helper function mergedTaggedValueList - which also looks
up tagged values on superclasses.
[jbaumann]Fixed html to text transform call: added source mimetype.
[jbaumann]1.2Fixed data transforms in NamedFileConverter
[lgraf]1.1Made reindexer more robust, since sometimes the field values may be wrong.
[jbaumann]Do not traverse to “view” in indexer, this could cause security issues especially in tests.
Using now a fake-view for enabling z2 mode.
[jbaumann]1.0Fixed assertion bug when using aIDynamicTextIndexExtenderadapter.
[jbaumann]1.0b3MovedIDynamicTextIndexExtendertointerfacesmodule.
[jbaumann]Theplone.namedfileis now optional. The new namedfile converting
adapter is only registered if its present
[jbaumann]Re-implemented converting of field data with an newly introduced adapter.
The default converter just converts the widget in display mode and
transforms it to text/plain.
[jbaumann]Fixed tests for compaitbility with plone.app.testing 4.0a3: Use TEST_USER_ID instead of TEST_USER_NAME
[jbaumann]fixed Bug UnicodeError:  while indexing lists  or dicts with special chars (Non-Ascii characters)
[phgross]1.0b2Fixed MANIFEST.in
[jbaumann]1.0b1Initial release