Skip to content

Commit

Permalink
added dexterity search extender behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
reinhardt committed Nov 13, 2015
1 parent b0e41d9 commit aa8b9c7
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
3 changes: 3 additions & 0 deletions docs/CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Changelog
does not affect server state)
[reinhardt]

- Added behavior that provides showinsearch and searchwords for dexterity types.
[reinhardt]


4.1.0 (2015-02-19)
------------------
Expand Down
2 changes: 1 addition & 1 deletion docs/features/exclude.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Exclude from search and elevation
---------------------------------

By default this add-on introduces two new fields to the default content types or any custom type derived from ATContentTypes.
By default this add-on introduces two new fields to the default content types or any custom type derived from ATContentTypes. For dexterity content types, including plone.app.contenttypes, a behavior is provided which must be manually activated on the desired content types.

The `showinsearch` boolean field lets you hide specific content items from the search results, by setting the value to `false`.

Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
'plone.app.layout',
'plone.app.testing',
'plone.app.vocabularies',
'plone.behavior',
'plone.browserlayer',
'plone.indexer',
'setuptools',
Expand Down
40 changes: 40 additions & 0 deletions src/collective/solr/extender.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,21 @@
from archetypes.schemaextender.interfaces import ISchemaExtender
from archetypes.schemaextender.interfaces import IBrowserLayerAwareExtender
from collective.solr.browser.interfaces import IThemeSpecific
from plone.supermodel import directives
from plone.autoform.interfaces import IFormFieldProvider
from plone.app.dexterity.behaviors.metadata import MetadataBase
from plone.app.dexterity.behaviors.metadata import DCFieldProperty
from plone.indexer import indexer
from plone.supermodel import model
from Products.Archetypes.atapi import BooleanField
from Products.Archetypes.atapi import BooleanWidget
from Products.Archetypes.atapi import TextAreaWidget
from Products.Archetypes.atapi import TextField
from Products.Archetypes.interfaces import IBaseObject
from zope import schema
from zope.interface import implementer
from zope.interface import implements
from zope.interface import provider
from zope.interface import Interface

from collective.solr import SolrMessageFactory as _
Expand Down Expand Up @@ -97,3 +105,35 @@ def __init__(self, context):

def getFields(self):
return self._fields


@provider(IFormFieldProvider)
class IElevationFields(model.Schema):
directives.fieldset(
'settings',
label=_(u'Settings'),
fields=('showinsearch', 'searchwords'),
)

showinsearch = schema.Bool(
title=_('label_showinsearch', default=u"Show in search"),
description=u"",
default=True,
)

searchwords = schema.Text(
title=_('label_searchwords', default=u"Search words"),
description=_(
'help_searchwords',
default=u"Specify words for which this item will show up "
u"as the first search result. Multiple words can be "
u"specified on new lines."
),
required=False,
)


@implementer(IElevationFields)
class DexteritySearchExtender(MetadataBase):
showinsearch = DCFieldProperty(IElevationFields['showinsearch'])
searchwords = DCFieldProperty(IElevationFields['searchwords'])
14 changes: 13 additions & 1 deletion src/collective/solr/extender.zcml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<configure xmlns="http://namespaces.zope.org/zope" i18n_domain="solr">
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:plone="http://namespaces.plone.org/plone"
i18n_domain="solr">

<include package="plone.behavior" file="meta.zcml" />

<adapter factory=".extender.searchwords" name="searchwords" />
<adapter factory=".extender.showinsearch" name="showinsearch" />
Expand All @@ -9,4 +14,11 @@
provides="archetypes.schemaextender.interfaces.ISchemaExtender"
factory=".extender.SearchExtender" />

<plone:behavior
title="Search Extender"
description="Provides additional search metadata for elevation"
provides=".extender.IElevationFields"
factory=".extender.DexteritySearchExtender"
/>

</configure>

0 comments on commit aa8b9c7

Please sign in to comment.