Displaying metadata in search results

Metadata can be used to enhance search results by providing richer information for the result summaries, or to provide fields that conditional template code can be based off.

By default Funnelback will return metadata from the a, c, p and s classes in the search results or data model. There are a number of display settings that affect how metadata is returned to the user.

Configuring metadata display options

Metadata is returned as part of each search result, unless summaries are disabled (by setting -SM=off as a query processor option.)

The list of metadata fields returned with the search results is determined by the summary fields (SF) query processor option. The fields to return are defined as a comma separated list of class names surrounded by square brackets (e.g. -SF=[title,author,keyword,description] instructs Funnelback to return the title, author, subject and description fields with the result set). The list supports a regex expression that will match multiple metadata fields. (e.g. -SF=[fun.] will return all fields beginning with fun and -SF=[.] will return all defined fields.)

using the wildcard matches for fields is convenient but can result in a performance hit if there is a lot of metadata fields (as this bloats the size of the result packet that must be returned by Funnelback.)

Once these two settings have bee configured metadata will be returned in the data model (for both JSON and XML endpoints) along with the other fields for each result.

Returned metadata is placed in the following sub-element within each search result:

  • listMetadata: contains the value of the metadata class as a list of strings, with multiple values as separate values in the list.

Advanced display options

  • Metadata buffer size (MBL)

Using metadata in Freemarker

The Freemarker templates can make use of any metadata that is available in the data model.

To print out the content of a metadata class use the following inside an <@s.Results> template block.

<#if s.result.listMetadata["CLASSNAME"]??>
    <#list s.result.listMetadata["CLASSNAME"] as item>${item!}</#list>
	default value

e.g. print out the first author value

<li>Author: ${s.result.listMetadata["author"]?first!"Unknown"}</li>

To print out all the subject metadata values from the listMetadata element:

<#if s.result.listMetadata["author"]?first??>
    <#list s.result.listMetadata["author"] as a><p><@s.boldicize>${a!}</@s.boldicize></p></#list>

Use metadata in a conditional test

Metadata can be used as the basis of a conditional test.

If the author metadata is defined then print out the author’s name

<#if s.result.listMetadata["author"]?first??>
	The author is ${s.result.listMetadata["author"]?first!}

If the document classification is top secret then print out a message

<#if s.result.listMetadata["documentClassification"]?first! == "Top secret">
	Nothing to see here

Using metadata in Groovy hook scripts

Metadata can similarly be accessed from Groovy hook scripts once it is returned with the data model.


// Remove site's names from result titles
if (transaction.response.resultPacket != null) {
    transaction.response.resultPacket.results.each() {
      // In Groovy, "it" represents the item being iterated
      def newTitle = (it.listMetadata["title"].stream().findFirst().orElse("") =~ / - Site Name$/).replaceAll("")
      it.listMetadata.replaceValues("title", [newTitle])