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.

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"}

e.g.

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

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