Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/collective/collective.dexteritytextindexer
Dynamic SearchableText index for dexterity content types
https://github.com/collective/collective.dexteritytextindexer
Last synced: about 1 month ago
JSON representation
Dynamic SearchableText index for dexterity content types
- Host: GitHub
- URL: https://github.com/collective/collective.dexteritytextindexer
- Owner: collective
- Created: 2010-11-23T14:22:20.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2022-12-27T15:35:41.000Z (almost 2 years ago)
- Last Synced: 2024-11-02T17:36:08.222Z (about 1 month ago)
- Language: Python
- Homepage: http://pypi.python.org/pypi/collective.dexteritytextindexer
- Size: 173 KB
- Stars: 9
- Watchers: 111
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
Awesome Lists containing this project
- awesome-plone - collective.dexteritytextindexer - Dynamic SearchableText index for dexterity content types. For Plone 6 this was merged into Plone core. (Content and utilities for content)
README
Introduction
============`collective.dexteritytextindexer` provides a dynamic SearchableText indexer for
dexterity content types. It makes it possible to index fields of multiple
behaviors as SearchableText.Usage
=====For enabling the indexer just add the behavior to the list of behaviors of your
content types.In your *profiles/default/types/YOURTYPE.xml* add the behavior::
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 alsoProvidesclass 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 searchablesearchable(ICategorization, 'categorization')
The `title` and `description` on `plone.app.dexterity`'s `IBasic` behavior
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_searchableno_longer_searchable(IBasic, 'title')
Alternatively, if you specified your model as a plone.supermodel XML model,
you can mark the field searchable that way::
Special field
Your SearchableText indexer includes now your custom field on your behavior, as
soon you enable it in your content type, where `IDexterityTextIndexer` behavior
is enabled too.Registering a custom field converter
====================================By 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.IDexterityTextIndexFieldConverter`
:Discriminators: 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::
There is already an adapter for converting NamedFiles properly. It's registered
only if `plone.namedfile` is installed.Extending indexed data
======================Sometimes 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 implementerimplementer(dexteritytextindexer.IDynamicTextIndexExtender)
class MySearchableTextExtender(object):
adapts(IMyBehavior)def __init__(self, context):
self.context = contextdef __call__(self):
"""Extend the searchable text with a custom string"""
return 'some more searchable words'ZCML::
This is a **named** adapter! 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 Baumann `_
- `Philippe Gross `_
- `Lukas Graf `_
- `Izhar Firdaus `_
- `Sune Broendum Woeller `_
- `Nejc Zupan `_