Skip to main content

Excludes a subtree from search.

Project description

Introduction

openc.excludesearch is designed to make it possible for an administrator to easily mark content as being hidden to searches.

NB: Requires dm’s AdvancedQuery from http://www.dieter.handshake.de/pyprojects/zope/#AdvancedQuery

First off, install myself:

>>> self.addProduct("openc.excludesearch")

We set up an object that will show in searches for “foo”:

>>> self.folder.invokeFactory('Document', 'foo', 'Foo Page')
'foo'
>>> self.folder['foo']
<ATDocument at .../foo>
>>> self.folder['foo'].setText("I am a foo object from foosville.")

We name it foo for convenience:

>>> foo = self.folder['foo']

We can see its text fine:

>>> foo.getText()
'<p>I am a foo object from foosville.</p>'
>>> foo.reindexObject()

If we search for it, we find it:

>>> app.plone.restrictedTraverse("queryCatalog")({"SearchableText":"foo"})
[<Products.ZCatalog.Catalog.mybrains object at ...>]

Once we activate the hiding functionality we don’t:

>>> foo.getField('hidesearch').get(foo)
False
>>> foo.getField('hidesearch').set(foo, value=True)
>>> foo.reindexObject()
>>> foo.getField('hidesearch').get(foo)
True
>>> app.plone.restrictedTraverse("queryCatalog")({"SearchableText":"foo"})
[]

This is because it has a new marker interface:

>>> from openc.excludesearch.interfaces import IExcludeFromSearch
>>> IExcludeFromSearch(foo)
<ATDocument at .../foo>

If we remove this marker, we find it again:

>>> foo.getField('hidesearch').get(foo)
True
>>> foo.getField('hidesearch').set(foo, value=False)
>>> foo.reindexObject()
>>> foo.getField('hidesearch').get(foo)
False
>>> app.plone.restrictedTraverse("queryCatalog")({"SearchableText":"foo"})
[<Products.ZCatalog.Catalog.mybrains object at ...>]

As we no longer provide that interface:

>>> IExcludeFromSearch(foo)
Traceback (most recent call last):
...
TypeError: ('Could not adapt', <ATDocument at .../foo>, <InterfaceClass openc.excludesearch.interfaces.IExcludeFromSearch>)

Todo

  1. Subclass/monkeypatch collections so they know to ignore things with the IExcludeFromSearch marker interface

Changelog

0.1 - Unreleased

  • Doctest [MatthewWilkes]

  • Added an adapter for archetypes.schemaextended to add a boolean field to the settings schema of any AT content type that adds/removes the marker interface when used. [MatthewWilkes]

  • Customised the queryCatalog script in a skin layer to drop all results providing IExludeFromSearch using AdvancedQuery [MatthewWilkes]

  • Added a marker interface called IExcludeFromSearch [MatthewWilkes]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openc.excludesearch-0.1.1.tar.gz (11.8 kB view details)

Uploaded Source

File details

Details for the file openc.excludesearch-0.1.1.tar.gz.

File metadata

File hashes

Hashes for openc.excludesearch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 866e0216266d335f1ede7b0137d6ec38d7e8434a96ad46870de4d880569c7f54
MD5 6c8cfe5d704cc329c3241eecad6e9e4d
BLAKE2b-256 4bc055ef4fc44e8ef1f1510fc125b28e0c77547851e0bc1e274e698179ef5fe2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page