Unify Enterprise Search results portlet


Jump to: navigation, search
Unify Enterprise Search results portlet
module: Publishing module
supplier: VYRE Ltd.

The Unify Enterprise Search results portlet is used to display the results of a Solr search query. The results are displayed and formatted using FreeMarker templates.



This portlet renders and displays results (or parts of results) of queries sent to the Solr search engine. Multiple instances of this portlet can be placed on the page to render different components of the result set, e.g. navigation and result list separately.


Key for accessing shared results

This key is used to store the search on a session, therefore it allows for multiply search forms and results on the same page and also allows a search results use a search submitted on a separate page. It is effectively used for inter-portlet communication. Ensure that this key is unique for each set of search/results portlets.

Sorting Attributes available to the user (Since 4.4)

Here a list of sorting fields that should be available to the user through the Sorting object (see below)

FreeMarker template for displaying results

The FreeMarker template rendered and populated with result objects from the search server. The following objects are available to the template at query time:

  • query: query object.
    • .getParameter(key): returns a given query parameter as a String[].
    • .getParameterStringValue(key): returns the string value of the parameter.
    • .parameters: returns all parameters as a Map of String[]
  • results: search result object reference.
    • .resultList: returns results as a List<SearchableItem>
    • .navigators: returns navigators as a Map of Navigator objects (Map<String,Navigator>())
    • .hits: number of items that match query
    • .start: the offset of the first item in the list (e.g. used when paging)
    • .spellingSuggestions: returns any spelling suggestions as a String.
    • .totalQueryTime: length of time taken to process query.
  • ${item.getSearchablePropertyValue("title","")} field to retrieve, second arg is default value if not found
  • pagination: pagination object reference.
    • .startIndex: position of first result on page.
    • .endIndex: position of last result on page.
Sorting (since 4.4)
  • sorting: sorting object reference.
    • .html: the html for the sorting options. Can take two parameters, Ascending value and descending value, to change the value used for the up and down display [default is "asec" and "desc"].
    • .sortableFields: list of sortable fields.
    • .currentSort: field that is currently being sorted on.
    • .currentDirection: direction for the current sort.
Localization (since 4.4)
  • bundle: localization bundle object reference.
    • ${bundle.getStringIfExists("key.goes.here")} can be used to display the key key.goes.here
Filter Utils (since 4.4)
  • filterUtils: filterUtils object reference. Holds common functions that help in the displaying and controlling of the filter for the search results.
    • .resetFilterUrl: outputs the url to reset the search.
    • .getRemoveFromFilterUrl(String filter): outputs the url to remove all the occurrences of the filter passed.
    • .getRemoveFromFilterUrl(String filter, String value): outputs the url to remove any occurrences of the filter/value pair passed.
    • .getSetOnFilterUrl(String filter, String value): outputs the url to set (replace) the filter on the search, with the given value.
    • .getAddOnFilterUrl(String filter, String value): outputs the url to add the filter on the search, with the given value (this does not replace existing values).
Utils (since 4.4)
  • utils: utils object reference. Holds common functions that help in the displaying and controlling of the search results.
    • .getFreeMarkerResourcePath( 'resourceId' ): outputs the contents of the FreeMarker resource with the given id.
FileManager(since 4.4)
  • fileManager:fileManager is the object reference for a file utility class. This holds common functions for obtaining links to thumbnails, derived files, and so on.
    • .getOriginalFile(Item item):loads a WebFileInfo object which can be used to link to the original file represented by this Item
    • .getThumbnail(Item item):loads a WebFileInfo object which can be used to link to the thumbnail for the file represented by the item
    • .getPreview(Item item):loads a WebFileInfo object which can be used to link to the preview for the file represented by the item
    • .getStoryBoard(Item item):loads a WebFileInfo object which can be used to link to the storyboard
    • .getDerivedFiles(Item item):loads a list of WebFileInfo objects which can be used to link to derived files for the item
    • .getDerivedFile(Item item, String serviceId):loads a WebFileInfo object which can be used to link to the derived file for the given item and given service id
    • .getUnifyItem(Item item):returns a reference to the Unify Item used to generate the Item from the remote index
    • .hasDerivedFile(Item item, String serviceId):determine (boolean value) if the item has a derived file generated by the specified service

Each fileManager method above that takes an Item as an argument also has an overloaded form that takes a String id.


Below you will find a list of FreeMarker result templates to achieve common tasks. These can be put in the same template or separate Search result instances. In some of these examples a certain amount of FreeMarker gymnastics is required achieve simple tasks. These will be collated and generically implemented as a part of the final release.

Result list
  <#if results?has_content>
    <!-- Result List -->
    <div class="resultList">
      <#list results.resultList as item>
        <div class="resultItem">
          <div class="title">
            ${item_index + 1}. ${item.allSearchableProperties.title}
          <div class="description">
          <div class="resultMetadata">
            Locale: <b>${item.getSearchableProperty("locale")}</b><br>
            Store: <b>${item.getSearchableProperty("store")}</b><br>
Result Statistics
  <#if results?has_content && query?has_content>
    <!-- Result Statistics -->
    <div class="resultStatistics">
      Results for '<u>${query.getParameterStringValue("query")}</u>' <b>${pagination.getStartIndex()+1} - ${pagination.getEndIndex()+1}</b> of <b>${results.hits}</b>. (<b>${results.totalQueryTime}</b> ms)
  <#if pagination?has_content>
    <!-- Pagination -->
    <div class="resultPagination">
  <#if pagination?has_content>
    <!-- Pagination -->
    <div class="resultPagination">
      ${pagination.getHtml("<img src='/other_files/ascending.gif"/>'","<img src='/other_files/decending.gif"/>'")}
  <#list results.navigators?values as nav> 
    <h4>Filter answers by ${nav.name?capitalize}: </h4>
    <ul class="criteria">
      <#list nav.navigatorEntries?values as entry>
        <#assign displayName = entry.name?capitalize >
        <li><a href="${filterUtils.getAddOnFilterUrl(nav.name, entry.name)}">${displayName}</a> <span>(<b>${entry.frequency}</b>)</span></li>
Filter Trace
  <h1>Selected Filters</h1>
  <#list filterUtils.selectedFacets?values as nav>
    <ul class="selected">
      <#list nav.navigatorEntries?values as entry>
        <li style="">
          <a href="${filterUtils.getRemoveFromFilterUrl( nav.name, entry.name )}">${entry.name?capitalize}</a>
Converting dates
 <@generatePrettyDate item=item valueKey="root_closing_night" />
 <!-- method to get the pretty date -->
 <#macro generatePrettyDate item valueKey >
   <#assign spanValue= item.getSearchablePropertyValue(valueKey,"") />
   <#if spanValue?trim != "" >
      <#assign date = spanValue?datetime("yyyy-MM-dd'T'HH:mm:ss")?string("dd MMM, yyyy") > 
File Manager
 <#if fileManager.hasDerivedFile(item, "311") >
  <div class="fileInfo">${fileManager.getOriginalFile(item).getName()}</div>
  <div class="fileInfo"><img src="${fileManager.getOriginalFile(item).getPath()}"/></div>
  <div class="fileInfo"><img src="${fileManager.getThumbnail(item).getPath()}"/></div>
  <div class="fileInfo"><img src="${fileManager.getPreview(item).getPath()}"/></div>
  <h4>file information</h4>
   <div class="fileInfo"><img src="${fileManager.getPreview(item).getPath()}"/></div>
   <h3>file service 342 </h3>	
   <#if fileManager.hasDerivedFile(item.uuid, "342") > true
 <h3>derived files</h3>
 <#assign derivedFiles = fileManager.getDerivedFiles(item) >
  <#list derivedFiles as file >
   <div class="fileInfo"><img src="${file.getPath()}"/></div>
Shared Search URL and Path

Since Unify 4.6 two additional String variables are available in Freemarker results templates. These are called shared_search_path and shared_search_url. These allow a user to click on a link, or paste a URL into a browser bar, and have the search who's results they are currently viewing run again. This is useful for saving persistent links to a set of search results, or sharing results between users or browsers.

The variable shared_search_path excludes the protocol and host name at the start of the URL, whilst shared_search_url produces the full URL, including protocol.

  <a href="${shared_search_url}">This is the full URL to the search</a>
  <a href="${shared_search_path}">This is the path to the search, excluding host name and protocol</a>

The parameters at the end of the shared_search_url specify exactly which parameters are passed to Solr as part of the search. The parameters include the following:

  • filter - filter queries
  • query - the main query to run
  • sortFields - fields to sort the results on
  • pageNo - the page number
  • resultSize - teh result size
  • fieldList - the field list for the returned results
  • operator - the operator to apply to the search terms
  • facetFields - the fields to facet on
  • facetFieldLimit - the facet field limit
  • facetFieldSortedOnCount - whether to sort facet fields on count
  • highlightingOn - turn highlighting on
  • highlightingFields - the list of fields to apply highlighting to
  • highlightingSnippetCount - the number of snippets
  • highlightingFragSize - the maximum size of each snippet
  • highlightingPre - the tag to use before each snippet
  • highlightingPost - the tag to use after each snippet
  • localeFilter - the locale filter
  • extra - any additional Solr parameters

The generated URL/Path can be rather long, and will look something like:

  <a href="/searchpage/?filter=%2Bcollection%3A1&query=russia&sortFields=uuid+desc&fieldList=uuid%2Ctitle%2Cdescription%2Ccollection&localeFilter=noLocaleFilter">Shared search path</a>

See Also

Personal tools