Written by The Jahia Team
 
Developers
   Estimated reading time:

When using the default Jahia Search forms like Simple Search Form the results are displayed in relevance order.

Is it possible to change this configuration to display the results in a distinct order like modification date?

Also is it possible to choose between ascending and descending order?

Answer

Yes, the Search results can be displayed in modification date order. Taking the Simple Search Form as an example:

<s:form method="post" class="simplesearchform" action="${searchUrl}">
		<jcr:nodeProperty name="jcr:title" node="${currentNode}" var="title"/>
		<c:if test="${not empty title.string}">
		<label for="searchTerm">${fn:escapeXml(title.string)}:&nbsp;</label>
		</c:if>
		<fmt:message key='search.startSearching' var="startSearching"/>
       	<s:term match="all_words" id="searchTerm" value="${startSearching}" searchIn="siteContent,tags,files" onfocus="if(this.value=='${startSearching}')this.value='';" onblur="if(this.value=='')this.value='${startSearching}';" class="text-input"/>
       	<s:site value="${renderContext.site.name}" includeReferencesFrom="systemsite" display="false"/>
       	<s:language value="${renderContext.mainResource.locale}" display="false" />
    	<input class="searchsubmit" type="submit" title="<fmt:message key='search.submit'/>" value=""/>
</s:form>

One can add the tag s:orderBy in the form and select the proper attributes so the search results will be listed ordered by jcr:lastModified field in a descending order:

<s:orderBy operand="property" display="false" propertyName="jcr:lastModified" order="descending"/>

If the attribute display is removed then a selector between "Date" and "Relevance" will show up in your UI so the user can choose how to sort the results.

Related links