Set gscopes using a plugin

The plugin indexing interface provides two methods supplyGscopesByRegex() and supplyGscopesByQuery() which enables additional gscopes to be registered within a data source.

The primary use case for this is to set up any gscopes that are required to support a plugin.

Prerequisite

In order to add a gscope, your plugin must be configured to provide indexing functionality.

Gscopes can be added from configuration (gscopes.cfg or query_gscopes.cfg) or via one or more plugins. Each source of gscopes is independent of the other sources and the resultant gscopes applied to a document will combine all gscopes that has been added by the different gscope sources.

Set gscopes on documents with URLs matching a pattern

This is equivalent to gscopes that are defined in gscopes.cfg.

To set a gscope based on a URL match, implement the supplyGscopesByRegex() method within this java class.

void supplyGscopesByRegex(IndexConfigProviderContext context, GscopeByRegexConsumer consumer)

Within this method, you need to call the applyGscopeWhenRegexMatches() method on the consumer for each mapping you wish to set up.

The void applyGscopeWhenRegexMatches(String gscopeName, String perlRegularExpression) method takes two parameters:

gscopeName

The name the gscope to set. This must be a valid gscope name. See: configuring gscopes.

perlRegularExpression

A Perl5 regular expression that will be matched against the URL.

Set gscopes on documents returned by a Funnelback query

This is equivalent to gscopes that are defined in query_gscopes.cfg.

To set a gscope based on a match to a Funnelback query, implement the supplyGscopesByQuery() method within this java class.

void supplyGscopesByQuery(IndexConfigProviderContext context, GscopeByQueryConsumer consumer)

Within this method, you need to call the applyGscopeWhenQueryMatches() method on the consumer for each mapping you wish to set up.

The void applyGscopeWhenQueryMatches(String gscopeName, String query) method takes two parameters:

gscopeName

The name the gscope to set. This must be a valid gscope name. See: configuring gscopes.

query

The Funnelback search query which will be run. The search query must be specified using the Funnelback query language and will be run against the search index of the data source.

Example: Set Gscopes

This example demonstrates how to set gscopes on a document using a plugin.

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

import com.funnelback.plugin.index.consumers.GscopeByRegexConsumer;
import com.funnelback.plugin.index.consumers.GscopeByQueryConsumer;
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 supplyGscopesByRegex(IndexConfigProviderContext context, GscopeByRegexConsumer consumer) {
        log.debug("Set gscopes for pages identified as a document");

        consumer.applyGscopeWhenRegexMatches("isDocument", "example\\.com/documents/"); (1)
    }

    public void supplyGscopesByQuery(IndexConfigProviderContext context, GscopeByQueryConsumer consumer) {
        log.debug("Set gscopes for pages identified as a document");

        consumer.applyGscopeWhenQueryMatches("isDocument", "word document"); (2)
        consumer.applyGscopeWhenQueryMatches("isDocument", "excel file"); (2)
    }
}
1 Sets the isDocument gscope on all items that match the URL example.com/documents/. Note: In regex . us a special character that matches any character. To match a period you must escape this with a backslash, which in java requires additional escaping.
2 Sets the isDocument gscopes for all URLs that are returned for a query of word document and URLs that are returned for a query of excel file run against the data source’s index.