Skip to content

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.)

Note: 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 within the following sub-elements within each search result:

  • metaData: contains the value of the metadata class as a string, with multiple values concatenated with the metadata field delimiter (usually a | character).
  • 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.

${s.result.metaData["CLASSNAME"]!"default value"}

of

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

e.g. print out the author value

<ul>
<li>Author: ${s.result.metaData["author"]!"Unknown"}</li>
</ul>

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

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

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.metaData["author"]??>
	The author is ${s.result.metaData["author"]}
</#if>

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

<#if s.result.metaData["documentClassification"!] == "Top secret">
	Nothing to see here
</#if>

Using metadata in Groovy hook scripts

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

e.g.

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

top

Funnelback logo
v15.24.0