Define additional metadata mappings using a plugin
The plugin indexing interface provides a method metadataMappings()
which enables additional metadata mappings to be registered within a data source.
The primary use case for this is to set up any metadata mappings that are required to support a plugin, such as mapping known metadata fields for a new social media gatherer.
Prerequisite
In order to add a metadata mapping, your plugin must be configured to provide indexing functionality.
Add a metadata mapping
To create metadata mappings, implement the metadataMappings()
method within this java class.
void metadataMappings(IndexConfigProviderContext context, MetadataMappingConsumer consumer)
Within this method, you need to call the map()
method on the consumer for each mapping you wish to set up.
The void map(String metadataClass, MetadataType type, MetadataSourceType sourceType, String locator)
method takes four parameters:
metadataClass
-
The name of the metadata class which may be used at query time. Must be less than 65 characters and must be ASCII alphanumeric.
type
-
The type of the metadata class, e.g.
NUMERICAL
for numeric values. Acceptable values are defined in theMetadataType
enum. sourceType
-
This indicates the type of the source metadata field. e.g.
HTML_OR_HTTP_HEADERS
if the metadata is coming from<meta name="author" content="John Doe">
. Acceptable values are defined in theMetadataSourceType
enum. locator
-
The location to get the metadata from e.g. when getting metadata from HTML:
<meta name="author" content="John Doe">
the locator would be "author".
Example: Provide additional metadata mappings
This example, extracted from the social tags plugin shows how to define metadata mappings within a plugin.
package com.funnelback.plugin.socialtags;
import com.funnelback.plugin.index.consumers.MetadataMappingConsumer;
import com.funnelback.plugin.index.model.metadatamapping.MetadataSourceType;
import com.funnelback.plugin.index.model.metadatamapping.MetadataType;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.funnelback.plugin.index.IndexConfigProviderContext;
import com.funnelback.plugin.index.IndexingConfigProvider;
public class SocialTagsIndexingConfigProvider implements IndexingConfigProvider {
private static final Logger log = LogManager.getLogger(SocialTagsIndexingConfigProvider.class);
@Override
public void metadataMappings(IndexConfigProviderContext context, MetadataMappingConsumer consumer) {
log.debug("Add metadata mapping for social tags metadata");
consumer.map(PluginUtils.HASH_TAG_METADATA_NAME, MetadataType.TEXT_INDEXED_AS_DOCUMENT_CONTENT, MetadataSourceType.HTML_OR_HTTP_HEADERS,
PluginUtils.HASH_TAG_METADATA); (1)
consumer.map(PluginUtils.USER_TAG_METADATA_NAME, MetadataType.TEXT_INDEXED_AS_DOCUMENT_CONTENT, MetadataSourceType.HTML_OR_HTTP_HEADERS,
PluginUtils.USER_TAG_METADATA);
}
}
1 | Defines a metadata mapping which maps the Plugin-Social-Tags-Hash-Tags metadata field (added via the plugin filter) to a metadata class hashTags in Funnelback. The fields passed to the consumer.map() method:
|