Search Service

Info: The Bloomreach Content Search Service is designed for use with the Advanced Search feature in the CMS. For delivery tier implementations, use the Fluent Search API for the delivery tier.

Overview

The Search Service in Bloomreach Content provides a Java domain-specific language (DSL) for building search queries. This API is intended to simplify query construction and support multiple underlying implementations without exposing JCR-specific code.

The following example demonstrates how to use the Search Service in a project with the namespace myproject.

Example: Building a Query with the Fluent API

import org.onehippo.cms7.services.search.service.SearchServiceFactory; import org.onehippo.cms7.services.search.service.SearchService import static org.onehippo.cms7.services.search.query.QueryUtils.both; import static org.onehippo.cms7.services.search.query.QueryUtils.date; import static org.onehippo.cms7.services.search.query.QueryUtils.either; import static org.onehippo.cms7.services.search.query.QueryUtils.integer; import static org.onehippo.cms7.services.search.query.QueryUtils.not; import static org.onehippo.cms7.services.search.query.QueryUtils.text; public class SearchExample { public void doSearch() throws SearchServiceException, RepositoryException { SearchServiceFactory searchServiceFactory = HippoServiceRegistry.getService(SearchServiceFactory.class, SearchServiceFactory.class.getName()); if (searchServiceFactory == null) { throw new SearchServiceException("Cannot find search service factory by name " + SearchServiceFactory.class.getName()); } SearchService searchService = searchServiceFactory.createSearchService(UserSession.get().getJcrSession()); Query query = searchService.createQuery() .from("/content/documents") .ofType("hippo:document") .where(text("myproject:title").contains("hippo")) .and(date("hippostdpubwf:publicationDate").from(new Date()).andTo(new Date())) .and(integer("myproject:counter").from(6).andTo(8)) .and(not(text("hippostdpubwf:lastModifiedBy").isEqualTo("editor"))) .limitTo(10) .offsetBy(30) .orderBy("hippostdpubwf:publicationDate").descending(); QueryResult result = searchService.search(query); HitIterator hits = result.getHits(); while (hits.hasNext()) { Hit hit = hits.next(); String id = hit.getSearchDocument().getContentId().toIdentifier(); Node documentNode = UserSession.get().getJcrSession().getNodeByIdentifier(id); // do stuff } } }

The fluent API provides method chaining to construct queries in a readable and maintainable way. Static helper methods such as text, date, and not are available to define constraints clearly.

This API does not expose JCR-specific code. It is designed to support multiple backend implementations.

Note: By default, date range searches use a resolution of DAY. You can specify a different resolution in the isEqualTo, from, and to methods. Using a larger resolution can improve query performance.

Configuring the Search Service

Starting with brXM 11.2, the Search Service is configurable through the repository. The configuration node is located at:

/hippo:configuration/hippo:modules/search-service/hippo:moduleconfig

The following table describes the available configuration properties:

Property nameTypeDefaultDescription
wildcard.postfix.enabledBooleantrueWhen enabled, text searches are extended with a wildcard. For example, searching for 'foobar' expands to jcr:contains("foobar") OR jcr:contains("foobar*").
wildcard.postfix.minlengthLong3Specifies the minimum length a search term must have to be extended with a wildcard postfix. This prevents excessive state expansion.
Share Feedback
Page: /build/spring-services/search-service
Section: Build
Category *