Blog Hero Image

Jahia Search in the Enterprise

Nov 09, 2011
Oshyn Labs
Oshyn Labs

Jahia has an embedded search engine that can be used by a Tag Library. This library offers components to build forms, field elements, components to display search results, and components to implement the pagination. I want to share a way of how to use the Jahia Search Tag Library to do full text searches.

Configuring Search Results Page Template

I am assuming that you have some experience with template development. If not, you can find a quick review of template development here. When you create a template set, you need to configure the file templates.xml to declare the templates that are going to be part of the template, but also you can use this file to configure which page is going to handle search results. You need to add the following configuration to the file templates.xml.


SearchResults.jsp is the page that is going to display the search results executed by the Jahia Search Taglib.

Search Form

To build search forms, first you need to include the Jahia Search Taglib in the .jsp file that is going to contain the form

<%@ taglib uri="" prefix="s" %>

Then you need to use the tags and to build the form. Following is an example form:

<s:form name="fulltextsearch">
<td class="title" style="width: 150px;">Search</td>
<td style="width: 350px;"><s:term class="text1"/></td>
<td><input type="submit" value="search" class="button"/></td>

Search Results Page

The search results page is the page configured in the file template.xml to display the results. This page is called every time that a submit is performed in the s:form. You need to use the libraries:

<%@ taglib uri="" prefix="s" %>
<%@ taglib uri="" prefix="pg" %>

And the tags <s:results>, <pg:pager>, <s:resultIterator>,  <pg:item> to display the results.

The tag <s:results> is in charge to execute the search  and expose the results to be displayed, and <s:resultIterator> is in charge to iterate over the results.  The tag <s:results>  has the important method getCount(), to obtain the number of results, and can be accessed by the EL (Expression Language) ${count}.

The tag <pg:pager> is in charge of implement the pagination of large data sets and <pg:item> represents each page returned by the search.

Following is an example of how to use the above elements in action:

<pg:pager maxPageItems="10" url="${}" export="currentPageNumber=pageNumber">
<td><a href="${}">${fn:escapeXml(hit.title)}</a></td>

Notice that the element <pg:pager> is used to define the number of results displayed per page. The <s:results> tag returns a java.util.List<> List, so for that reason you can use the EL ${}, ${hit.title} and ${hit.summary}.

Also you can include more pagination elements to handle the navigation. You can use the tags <pg:prev> and <pg:next> inside the tag <pg:index> like the following example:

<pg:index export="itemCount">
<pg:prev ifnull="true">
<c:if test="${not empty pageUrl}">
<a href="${pageUrl}">previous</a>
<c:if test="${empty pageUrl}">
</pg:prev>        |
<pg:next ifnull="true">
<c:if test="${not empty pageUrl}">
<a> <a href="${pageUrl}">next</a></c:if>
<c:if test="${empty pageUrl}">

The following screenshot shows a search result page with pagination. Each page has the size of one, and notice that at the bottom of the page are the next and previous arrows to navigate through pages.

Latest insights