Using the Content Search Query API

Using the Content Search Query API

Using the search API in your site webapp (or in your Java code in general) is done via obtaining a specific service from the HippoServiceRegistry, of class

ExternalSearchService searchService = HippoServiceRegistry.getService(ExternalSearchService.class);

Having the service, you can very easily build a query using the Fluent API, e.g.:

Future<QueryResponse> future = searchService
  .catalog(“your catalog")
  .query("your query")
  .filterQuery("attribute name", “value to filter on”)
  .filterQuery("another attribute name", “another value to filter on”)
  .retrieveField("another field")
  .facetField("facet field")
  .sortBy("title", SortType.ASC)

The filterQuery() method adds fq parameters, while the retrieveField() method appends values to the fl parameter. For a detailed description of the available options and format of these 2 parameters, and how to use the view_id parameter (via view() method) see this documentation page.

You can filter on any attribute that is indexed in SM. During feed generation, the addon includes some metadata as top level attributes, allowing you to configure those in SM and apply search filters using them. These attributes are:




The document type name of the indexed document (e.g. myproject:news)

Obtaining an object of type Future allows you to perform the query in your prepareBeforeRender, taking advantage of HST’s parallel component preprocessing.

The addon uses CRISP to perform searching against the SM index. CRISP provides for caching, and you can tweak (though it’s not recommended) the resolver used by the addon by navigating to /hippo:configuration/hippo:modules/crispregistry/hippo:moduleconfig/crisp:resourceresolvercontainer/brSMSearchClient.

Response object model

The Query API provides a couple of domain objects to represent the returned results from SM. Specifically, classes QueryResponse, SearchResult and Document are used to unmarshall and easily process the results. Currently you can obtain the result set size and paging information, available facets, and all the attributes that you specified as “retrieve field” when constructing your query. These classes are basic Java beans and thus very straightforward to use. Please see the Javadoc for additional details.

Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?