Add external metadata using a plugin

The plugin indexing interface provides a method externalMetadata() which enables external metadata mappings to be added to a data source.

Prerequisite

In order to add external metadata, your plugin must be configured to provide indexing functionality.

Add external metadata

To add external metadata, implement the externalMetadata() method within this java class.

void externalMetadata(IndexConfigProviderContext context, ExternalMetadataConsumer consumer)

Within this method, you need to call the addMetadataToPrefix() method on the consumer to add the metadata.

The void addMetadataToPrefix(String URL, com.google.common.collect.ListMultimap<String,String> metadata method takes two parameters:

URL

URL prefix. Must include a full hostname, if no protocol specified then http:// is assumed. e.g. https://www.example.org/movies

metadata

A multimap of one or more metadata keys and values.

External metadata can be added from configuration (external_metadata.cfg) or via one or more plugins. Each source of external metadata is independent of the other sources and the resultant metadata applied to a document will combine all metadata that has been added, including potentially duplicate values added by different external metadata sources.

Example: Add external metadata

This example demonstrates two different ways of adding external metadata to documents.

ExampleIndexingConfigProvider.java
package com.funnelback.plugin.example;

import com.funnelback.plugin.index.consumers.ExternalMetadataConsumer;
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 ExampleIndexingConfigProvider implements IndexingConfigProvider {

    private static final Logger log = LogManager.getLogger(ExampleIndexingConfigProvider.class);

    @Override
    public void externalMetadata(IndexConfigProviderContext context, ExternalMetadataConsumer consumer) {
        log.debug("Add some external metadata");

        // Apply metadata to documents with URLs starting with https://foo.com/documents/ (1)
        consumer.addMetadataToPrefix("https://foo.com/documents/", ImmutableListMultimap.of(
             "type", "doc",
             "notes", "informative",
             "notes", "boring"));

        // Apply metadata to documents with URLs starting with https://foo.com/videos/ (2)
        ListMultimap<String, String> metadata = ArrayListMultimap.create();
        metadata.put("type", "video");
        metadata.put("notes", "sometimes informative");

        consumer.addMetadataToPrefix("https://foo.com/videos/", metadata);
    }
}
1 Adds three metadata values, type=doc, notes=informative and notes=boring to URLs beginning with https://foo.com/documents/ by passing the metadata values directly to the addMetadataToPrefix() method.
2 Adds two metadata values, type=video and notes=sometimes informative to URLs beginning with https://foo.com/videos/ by first adding the metadata values to a multimap which is then passed to the addMetadataToPrefix() method.