Written by The Jahia Team
   Estimated reading time:

Augmented Search exposes a new OSGI service to execute search queries.

To use this service in your Jahia modules, you need to have a dependency on Augmented Search in your pom.xml file.


Then, to use Augmented Search you will first need to get the service.

ServiceReference searchReference = bundleContext.getServiceReference(AugmentedSearchService.class);
if (searchReference != null) {
   AugmentedSearchService searchService = bundleContext.getService(searchReference);

You can then use the searchService to execute searches. For example, the snippet below searches for terms in the query variable across all content nodes (as per the filter on jnt:content defined in GqlFilterNodeType).

GqlSearchResults response = searchService.search(query, 
  AugmentedSearchService.SearchIn.CONTENT, 20, 0, null,    
  new GqlFilter(null, null, null, null,      
  new GqlFilterNodeType("jnt:content", false), null, null),                                               
  getCurrentResource().getLocale().getLanguage(), getCurrentResource().getWorkspace(),                                                

You can also perform simple searches or fetch facets along with your search. The response object contains the result from all the facets and from the main search query. To access those results, grab the SearchResponse object by calling getMainQueryResponse.

The following snippet returns a summary of the search results.

String message = String.format("Search took %s and found %d results when searching for %s",

This can also be used in a taglib for example.

<as:search q="ceo"/>
   <c:forEach items="${asResults.hits}" var="hit">

Which results in the following rendering.


You can find the full codebase for the taglib example in this repository: https://github.com/Jahia/augmented-search-taglib