Hippo Search Service
The Hippo Search Service
The Hippo Search Service allows one to build queries using a Java DSL. A brief preview assuming the namespace of your project is myproject.
Search fluent API example:
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 will guide you through the different parts of the query. A number of static helper methods (text, date, not, ...) is available to keep the constraints readable.
Note that there's no JCR code involved; this is intentional as the API is intended to support multiple implementations.
The DEFAULT resolution of date range searches is DAY. You can specify in #isEqualTo, #from and #to a different resolution. The bigger the resolution, the faster the query.
Configure the Search Service
As of Bloomreach Experience Manager 11.2, the Search Service is a configurable module, with the following configuration location in the repository:
/hippo:configuration/hippo:modules/search-service/hippo:moduleconfig
The table below lists the available configuration properties:
Property name | Type | Default | Description |
wildcard.postfix.enabled | Boolean | true | If true, text searches will be extended with a wildcard. For example, a search for 'foobar' will be expanded to pseudo code jcr:contains("foobar") OR jcr:contains("foobar*"). |
wildcard.postfix.minlength | Long | 3 | The minimum length a search term must have to be extended with a wildcard postfix. This is to prevent state explosion |