Skip to main content

Search support for Silva.

Project description

SilvaFind is a powerful search feature to allow easy creation of search forms and result pages, both for users of the public site and for authors in the SMI. Simple schemas can be defined to indicate which fields should be searchable.

Authors can add a Silva Find object anywhere and define which fields to make searchable by end users of the public site, and/or which fields to limit to a preset value. Authors also can determine which fields should be displayed in the search results. All metadata set/fields are supported.

If you can’t add the Silva Find object in the SMI you should make sure it’s checked in the addables section of the publication. If Silva Find is not checked, check it and uncheck the inheritance checkbox (otherwise inheritance will overrule it and uncheck it again).

By default all possible custom search criterion fields and result fields are available in the SMI. Besides that, the elements of all metadata sets are also available as result fields. If these fields are indexed in the catalog, they can also be used as search criterion fields. All available fields can be enabled/disabled in the SMI.

Besides this behavior, SilvaFind also allows you to manually override the list of search criteria. This behavior is also intended for backwards compatibility, but can be used to add your own custom fields from within other products.

For example the default global schema that SilvaFind installs (globalschema.py) looks as follows:

from Products.Silva.i18n import translate as _

from Products.SilvaFind.schema import SearchSchema
from Products.SilvaFind.schema import ResultsSchema

from Products.SilvaFind.schema import ResultField
from Products.SilvaFind.schema import FullTextCriterionField
from Products.SilvaFind.schema import MetadataCriterionField
from Products.SilvaFind.schema import MetatypeCriterionField
from Products.SilvaFind.schema import DateRangeMetadataCriterionField

globalSearchSchema = SearchSchema([
    MetatypeCriterionField(),
    FullTextCriterionField(),
    MetadataCriterionField('silva-content', 'maintitle'),
    MetadataCriterionField('silva-content', 'shorttitle'),
    DateRangeMetadataCriterionField('silva-extra', 'publicationtime'),
    ])

globalResultsSchema = ResultsSchema([
    ResultField('get_title', _('Title')),
    ])

The result schema defines what fields get shown in the list of results, by default as columns in a results table. There are currently 3 types of result fields (plain vanilla, metatype and metadata), and it is not hard to make your own. See schema.py for how that is done.

The following SearchField types exist for now, and of course it is possible to roll your own:

MetatypeCriterionField

allows the content that is to be searched, to be restricted to certain (one or more) content types.

FulltextCriterionField

allows the fulltext of the content item to be searched.

MetadataCriterionField

allows a specific metadata field of a specific metadata set to be searched.

DateRangeMetadataCriterionField

allows a specific datetime based metadata field of a specific metadata set to be searched, using a date range.

PathCriterionField

allows the content that is to be searched, to be restricted to be below a certain path. The path of the found children will always start with the supplied path, which is a string starting from the site root.

Making your own is as simple as creating a different SearchSchema and ResultsSchema in your extension, and registering it in the install.py of your extension. You can replace the global default search schema as follows, assuming myOwnSearchSchema is a valid SearchSchema object:

def register_search_schema(root):
    root.service_find.search_schema = myOwnSearchSchema
    root.service_find.manage_delObjects(['default'])
    SilvaFind.manage_addSilvaFind(
        root.service_find, 'default', 'Default search')
    default = root.service_find.default
    for field in root.service_find.getSearchSchema().getFields():
        fieldName = field.getName()
        default.shownFields[fieldName] = True
    default._p_changed = True

If your extension defines its own metadata-set, making the fields in that set searchable by putting them in your schema is easy:

myOwnSearchSchema = SearchSchema([

    ...

    MetadataCriterionField('my-metadataset', 'my-field1'),
    MetadataCriterionField('my-metadataset', 'my-field2'),

    ...

    ])

For a good example of how to customize and use SilvaFind from your own extension, see the Silva DLCMS, which you can find here:

svn co https://infrae.com/svn/dlcms/SilvaDLCMS/trunk/ SilvaDLCMS

and look at searchschema.py.

Changes

1.3.2 (2010-02-07)

  • Update the reference widget.

  • Edit form implement the correct interface.

1.3.1 (2010-12-20)

  • Fix bugs on reference path criteria (selection of invalid value, export).

1.3 (2010-10-18)

  • Finish XML import/export to properly work even for path criterion.

  • Remove useless code duplication.

  • Use silva.captcha instead of custom batch implementation.

  • Refactor criterion and results widgets.

  • Add test for criterion and results widgets, and for XML import/export.

  • Refactor functional tests.

1.3b1 (2010/07/16)

  • Add an XML import/export handler.

  • service_find is now an utility.

  • Use zeam.form instead of z3c.form as an add form.

  • Use a reference to map the starting folder for the search.

  • Update code for Zope 2.12 and Python 2.6.

1.2 (2010-03-31)

  • Fix search bug.

  • Fix installation and configure addables.

1.2b2 (2010-02-08)

  • Fix bug for catalog query using non-selected fields.

1.2b1 (2010-02-01)

  • Add validation on the edit screen so that the user enter at least one search criteria.

  • Fix for Dutch translations.

  • Fix SilvaFind under Silva 2.2: fix invalid search arguments set on Find objects when you edit find settings.

  • Fix translation issues which breaks search in other languages than english.

  • Do not search by default, you need to click on the Search button.

  • Refactor add-form, public view, product installation.

  • Use zope.component instead of zope.app.zapi.

1.1.7 (2008-11-04)

  • Fix metatype selector.

1.1.6 (2008-10-29)

  • Fix tests.

  • Redo the render_helper page template for inputs.

1.1.5 (2008-10-02)

  • Reformating the documentation to valid ReST.

1.1.4

Features added:

  • SilvaFind does not add a default search instance inside the service_find directory anymore. This was only being used by the dlcms, which will add it anyway, if it’s not there.

1.1.3 (2008/03/03)

Changes:

  • SilvaFind is now using Silva 2.0 zcml extension registration. From this version forward this product will not work in Silva 1.6 or lower.

  • Changed product to work with Silva 2.1 zcml extension registration.

Bugs Fixed:

  • metatypecriterion used all types when no selection was made in SMI, it should have used all available types instead since this could be overwritten with an adapter.

1.1.2

Changes:

  • i18n readied for Silva 2.0+.

  • Changed product to work with Silva 2.1 zcml extension registration.

1.1.1.2

Changes:

  • metatypecriterion allows for list values.

  • Some code refactoring in MetatypeCriterionView, so it’s easier to override.

  • Changed the line and border colors in the public view from green to gray and removed a green background so it’s less likely that the SilvaFind colors will conflict with a user’s site design.

  • Empty searches show nothing instead of everything.

Bugs Fixed:

  • Removed hardcoded Silva Document checks in favor of IVersion interfaces.

  • KeyError for meta_type when doing empty searches.

  • SilvaFind search was searching on all “search content” fields, and ignoring the checkboxes.

1.1.1

Bugs Fixed:

  • Getting path criterion value from request failed because paths in the catalog can’t have unicode characters.

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

Products.SilvaFind-1.3.2.tar.gz (206.5 kB view hashes)

Uploaded Source

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