Per result extra searches

Managed by | Updated .


Per result extra searches are expensive to run as an extra search is run for each result that is returned in the result set. Use of per result extra searches can have a large negative impact on search performance and should be only be used in limited situations, where the number of results per page is small.


The Modern UI includes a feature that enables the running of an extra search for each result. This can be used to run a search to bring in additional content from a second index related to an item. For example in a University staff search a per results extra search might be used to return the publications authored by each staff member, which are then nested within the search result for that user.

This should not be confused with the per-query extra searches that are used more commonly (using the ExtraResults macro). For more information on per-query extra searches see the extra searches documentation.

Per-result extra search

ExtraSearch macro

The ExtraSearch macro is used to configure and run an extra search, initiated by the Freemarker template.

When defining an extra search the following fields are available:

  • collection: this needs to be set to the collection id of the collection against which the extra search will be run (mandatory).
  • query: this should be set to the query language string that defines the extra search (mandatory).
  • params: optional map of additional CGI parameters to pass to the extra search.


This example will run an extra search against another collection for each search result using the title of the current result item as the query.

Run an extra search to return everything from othercollection, where the author metadata (metaA) is set to the author of the current result. Ensure that title (t) and description (c) metadata are returned with the extra search results.

<@fb.ExtraSearch collection="other_collection" question=question query="!padrenull" params={"meta_A_sand":"${s.result.metaData['A']}","SF":"[t,c]"}>
    <#-- Freemarker code to process the extra search result set -->

Note: You can't view the data model of the extra search easily (for example by inspecting the json or XML output). If you wish to inspect the data model for an extra search then it is possible to print the extra search question and response variables in debugging output.

The following fuller example shows the code required to print out search results from the extra search within each result of the main search:

    <#if s.result.class.simpleName != "TierBar">
        <#if s.result.title?exists>
            <@fb.ExtraSearch question=question collection="other_collection" query=s.result.title>
                Extra search has same data model as normal search - you can access items in it in the same way.  question and response when used within the fb.ExtraSearch macro refer to the respective data model elements from the extra search.
                <!--DEBUG: Extra search question ${question} -->
                <!--DEBUG: Extra search response ${response} -->
                <#if response.resultPacket?size &gt; 0>
                    <#-- IF THE EXTRA SEARCH RESPONSE EXISTS -->

                    Print the URL of the item from the original search:
                    Parent URL: ${s.result.liveUrl}

                    <#if response.resultPacket.rmcs?size &gt; 0>
                        Iterate over the rmcs counts of the extra search
                        <#assign keys = response.resultPacket.rmcs?keys>
                        <#list keys as thes>


Tip: If you want to modify the query above (which is passing in s.result.title) you can create a variable before you call ExtraSearch (eg. <#assign newquery = "A:\"+s.result.title+"\""> then call ExtraSearch with query=newquery

Further reading

Was this artcle helpful?

Type: Keywords:
Frontend > Modern UI Frontend > Freemarker Frontend > Extra searches