Search Plugins

Search plugins allows for modification of the search functionality in Cantemo.

IElasticSearchDocumentProcessor

class portal.generic.plugin_interfaces.IElasticSearchDocumentProcessor

Allows a plugin to pre-process a search document which is sent to elastic.

This allows a 3rd-party plugin to modify a search document for example restrict which items or collections are returned by a search.

Requires:
  • process(plugin, search_document, *args, **kwargs)

Args:
  • search_document - A json document which is about to be sent to elastic.

The following is an example plugin which only logs the supplied search_document:

from portal.pluginbase.core import implements, Plugin
from portal.generic.plugin_interfaces import IElasticSearchDocumentProcessor

import logging
log = logging.getLogger(__name__)


class ElasticSearchDocumentPluginExample(Plugin):
    implements(IElasticSearchDocumentProcessor)

    def process(plugin, search_document):
        log.debug("SearchDocumentPluginExample: %s" % search_document)
        return search_document

ElasticSearchDocumentPluginExample()

IElasticSearchCollectionPostprocessing

class portal.generic.plugin_interfaces.IElasticSearchCollectionPostprocessing

Searching for collections returns JSON context into the page which can be used for rendering items and providing additional data onto collections.

This Interface allows modification of the JSON that will be used, with access to the collection results for the page.

It is called for each collection.

Requires:
  • __call__(collection_json, request):

Args:
  • collection_json - Dict with all available collection data

  • request - the page request

Returns:
  • JSON based structure for sending in to the page.

A typical response might look like this:

media_type_support_list =
    {'id': 'VX-1',
     'name': 'Example Collection',
     'resource_url': 'http://portal/collection/1/',
     'app':'my new string'},

IElasticIndexItemProcessor

class portal.generic.plugin_interfaces.IElasticIndexItemProcessor

Allows a plugin to pre-process an item elastic document before it is sent to elastic.

This allows a 3rd-party plugin to modify an index document for example add or remove certain fields or do other processing.

This plugin should return a dict which it wants Portal to index in elastic. In normal cases you would just add any additional fields you want to the index_document argument, but in certain cases you may want to override the entire document.

Requires:
  • process(plugin, item, index_document, *args, **kwargs)

Args:
  • item - The item to be indexed

  • index_document - A json document which is about to be sent to elastic.

The following is an example plugin which adds an additional field:

from portal.pluginbase.core import implements, Plugin
from portal.generic.plugin_interfaces import IElasticIndexItemProcessor

class ElasticIndexItemDocumentPluginExample(Plugin):
    implements(IElasticIndexItemProcessor)

    def process(plugin, item, index_document, *args, **kwargs):
        index_document['myownfield'] = get_myownfield_value(item)
        return index_document

ElasticIndexItemDocumentPluginExample()

IElasticIndexSubClipProcessor

class portal.generic.plugin_interfaces.IElasticIndexSubClipProcessor

Allows a plugin to pre-process subclip elastic document before it is sent to elastic.

This allows a 3rd-party plugin to modify an index document for example add or remove certain fields or do other processing.

This plugin should return a dict which it wants Portal to index in elastic. In normal cases you would just add any additional fields you want to the index_document argument, but in certain cases you may want to override the entire document.

Requires:
  • process(plugin, item, subclip_id, search_interval, index_document, *args, **kwargs)

Args:
  • item - The item of the subclip to be indexed

  • subclip- The subclip to be indexed

  • search_interval - The interval of this document. Portal indexes three documents for each subclip.

    This corresponds to the “Search only” selector in the Advanced Search interface where a user can chose to only search in item/subclip/both. This argument can have the following values: * subclip - Only contains the subclip metadata * all - Contains the union of item and subclip * item - Only the item metadata

  • index_document - A json document which is about to be sent to elastic.

The following is an example plugin which adds an additional field:

from portal.pluginbase.core import implements, Plugin
from portal.generic.plugin_interfaces import IElasticIndexSubClipProcessor

class ElasticIndexSubClipDocumentPluginExample(Plugin):
    implements(IElasticIndexSubClipProcessor)

    def process(plugin, item, subclip_id, index_document, *args, **kwargs):
        index_document['myownfield'] = get_myownfield_value(item)
        return index_document

ElasticIndexSubClipDocumentPluginExample()

IElasticIndexCollectionProcessor

class portal.generic.plugin_interfaces.IElasticIndexCollectionProcessor

Allows a plugin to pre-process an collection elastic document before it is sent to elastic.

This allows a 3rd-party plugin to modify an index document for example add or remove certain fields or do other processing.

This plugin should return a dict which it wants Portal to index in elastic. In normal cases you would just add any additional fields you want to the index_document argument, but in certain cases you may want to override the entire document.

Requires:
  • process(plugin, collection, index_document, *args, **kwargs)

Args:
  • collection - The collection being indexed

  • index_document - A json document which is about to be sent to elastic.

The following is an example plugin which adds an additional field:

from portal.pluginbase.core import implements, Plugin
from portal.generic.plugin_interfaces import IElasticIndexCollectionProcessor

class ElasticIndexCollectionDocumentPluginExample(Plugin):
    implements(IElasticIndexCollectionProcessor)

    def process(plugin, collection, index_document, *args, **kwargs):
        index_document['myownfield'] = get_myownfield_value(collection.getId())
        return index_document

ElasticIndexCollectionDocumentPluginExample()

Deprecated interfaces

ICollectionSearchJSONContent

class portal.generic.plugin_interfaces.ICollectionSearchJSONContent

This interface is deprecated. Please use ‘IElasticSearchCollectionPostprocessing’ instead

Searching for collections returns JSON context into the page which can be used for rendering items and providing additional data onto collections.

This Interface allows modification of the JSON that will be used, with access to the collection results for the page.

It is called for each collection.

Requires:
  • __call__(json_incoming, collection, request):

Args:
  • json - The data used as JSON already provided.

  • collection - Collection objects from the search

  • request - the page request

Returns:
  • JSON based structure for sending in to the page.

A typical response might look like this:

media_type_support_list =
    {'id': 'VX-1',
     'name': 'Example Collection',
     'resource_url': 'http://portal/collection/1/',
     'app': 'my new string'}

IVidispineSearchDocumentProcessor

class portal.generic.plugin_interfaces.IVidispineSearchDocumentProcessor

This interface is deprecated. Please use IElasticSearchDocumentProcessor instead.

Allows a plugin to pre-process a search document which is sent to vidispine.

This allows a 3rd-party plugin to modify a search document for example restrict which items or collections are returned by a search.

Requires: * process(search_document, search_domain, *args, **kwargs)

Args: * search_document - A VSXMLSchema.SearchDocument document which is about to be sent to vidispine. * search_domain - A string signaling if this is a search for “item” or “collection”

The following is an example plugin which only logs the supplied search_document:

from portal.pluginbase.core import implements, Plugin
from portal.generic.plugin_interfaces import IVidispineSearchDocumentProcessor

import logging
log = logging.getLogger(__name__)

class SearchDocumentPluginExample(Plugin):
    implements(IVidispineSearchDocumentProcessor)

    def process(plugin, search_document, search_domain):
        log.debug("SearchDocumentPluginExample: %s" % search_document.toxml())
        return search_document

SearchDocumentPluginExample()