Providing a Solr search

This page describes how to use the solrfn templating functions to create a search page based on results from Apache Solr. The functions are provided by the Solr Templating submodule of the Magnolia Solr module.

The Solr module integrates Apache Solr, a standalone enterprise-grade search server with a REST-like API, for indexing and crawling of Magnolia content, especially if you need to manage assets in high volumes (100,000+ assets).

Creating a search results page

Templating functions allow you to create FreeMarker templates in a light development fashion, that is directly from the templates, without any Java development.

By default, the Solr Templating submodule does not provide any templates. This is because every website is different and may have different requirements for searches. Likewise, in spite of the fact that Apache Solr is very flexible search engine, a Solr document schema may look very different for each client.

It is not easy to provide a generic template which would satisfy all the needs. However, it is considered a best practise to create a template which would suit the page and fields in your schema, without any additional generic logic.

Using solrfn in templates

The solrfn templating functions provide methods for most of the common parameters used in Solr. For a full set of the methods, please see the solr page.


  • Create a query and trigger a search:

    [#assign results = solrfn.query("searchTerm").search()?eval]
  • Set query parameters and trigger a search:

    [#assign results = solrfn.query(queryTerm)
        .clientName("my-client-name") [#-- client used for the search --]
        .rows(50) [#-- maximum number of results returned to 50 --]
        .field("url", "title", "abstract", "uuid") [#-- restrict fields included in response --]
        .filterQuery("destinations:europe")) [#-- only documents which have destination Europe --]

The results are returned in JSON, for example:

      "caption":["Lapland for Families"],
      "title":["Tour detail"],
      "caption":["Antarctic Active Adventure"],
      "title":["Tour detail"],

To parse the results, use the dot (.) notation, for example results.response.numFound as in:

[#assign results = solrfn.query("searchTerm").search()?eval]

Number of results ${results.response.numFound}

[#list as doc]
    <a href="${doc.url!}">${doc.url!}</a>

Example search template

For demonstration purposes, we have created a light module called solr (download link:^). Feel free to use and modify it.

The module decorates the basic page template from the mtk2. If you are using mtk, rename the mtk2 directory (in /solr/decorations/mtk2) to mtk.

Content of the light module:

  • Search component FreeMarker template.

  • Pagination and faceting macros.

  • Search component dialog.


  • Selection of a search client.

  • Pagination, with a maximum number of results.

  • Choosing the title field used to represent a page in a search result.

  • Limiting a search to certain fields with a boost factor.

  • Search filtering, to restrict the superset of documents that can be returned.

  • Restricting the information included in a query response to a specified list of fields.

  • Highlighting.

  • Faceting.

Solr example templat dialog.


DX Core



This widget lets you know where you are on the docs site.

You are currently perusing through the DX Core docs.

Main doc sections

DX Core Headless PaaS Legacy Cloud Incubator modules
6.3 beta

Magnolia 6.3 beta

Magnolia 6.3 is in beta. We are updating docs based on development and feedback. Consider the 6.3 docs currently in a state of progress and not final.

We are working on some 6.3-beta known issues during this phase.