Optimize Delivery Tier API Queries with Date Range Constraints for Performance

Overview

This page describes how to improve the performance of date range queries in the Delivery Tier API by specifying a date resolution.

When to Use

Apply these techniques when building queries with date constraints in Bloomreach Content's Delivery Tier API. Using an explicit date resolution prevents slow queries and reduces load on the repository.

Background

The Hippo Repository supports different date resolutions for queries with date range constraints. When you build queries using the Delivery Tier API, you can specify a date resolution to optimize query performance.

Implementation

You can specify a date resolution in both the Fluent Search API and the Legacy Search API.

Fluent Search API

To define a date resolution in the Fluent Search API, pass an org.hippoecm.repository.util.DateTools.Resolution object to the following methods in org.hippoecm.hst.content.beans.query.builder.FieldConstraintBuilder:

  • equalTo(Calendar, Resolution)
  • notEqualTo(Calendar, Resolution)
  • greaterOrEqualThan(Calendar, Resolution)
  • greaterThan(Calendar, Resolution)
  • lessOrEqualThan(Calendar, Resolution)
  • lessThan(Calendar, Resolution)
  • between(Calendar, Calendar, Resolution)
  • notBetween(Calendar, Calendar, Resolution)

Example

HstQuery hstQuery = HstQueryBuilder.create(scope) .ofTypes(BaseDocument.class) .where(constraint("myproject:date") .between(oneMonthAgo, today, DateTools.Resolution.DAY)) .build();

This example creates a query for documents with a myproject:date property between oneMonthAgo and today, using day-level resolution.

Legacy Search API

In the Legacy Search API, specify the date resolution by passing an org.hippoecm.repository.util.DateTools.Resolution object to these methods in org.hippoecm.hst.content.beans.query.filter.Filter:

  • addBetween(String, Calendar, Calendar, Resolution)
  • addNotBetween(String, Calendar, Calendar, Resolution)
  • addEqualTo(String, Calendar, Resolution)
  • addNotEqualTo(String, Calendar, Resolution)
  • addGreaterOrEqualThan(String, Calendar, Resolution)
  • addGreaterThan(String, Calendar, Resolution)
  • addLessOrEqualThan(String, Calendar, Resolution)
  • addLessThan(String, Calendar, Resolution)

Example

HstQuery hstQuery = context.getQueryManager().createQuery(scope, BaseDocument.class, true); Filter filter = hstQuery.createFilter(); filter.addBetween("myproject:date", oneMonthAgo, today, DateTools.Resolution.DAY); hstQuery.setFilter(filter);

This example creates a filter for documents with a myproject:date property between oneMonthAgo and today, using day-level resolution.

Date Resolution Options

The following date resolutions are available in org.hippoecm.repository.util.DateTools.Resolution:

  • DateTools.Resolution.YEAR
  • DateTools.Resolution.MONTH
  • DateTools.Resolution.DAY
  • DateTools.Resolution.HOUR

Performance improves as you use a coarser resolution (for example, YEAR is faster than DAY).

Default Date Resolution

By default, the system uses DateTools.Resolution.DAY for fast date range queries. For example, if you use Filter#addBetween(String, Object, Object) with Calendar objects as the start and end values, the query applies day-level resolution.

You can change the default date resolution by setting the default.query.date.range.resolution property in the hst-config.properties file.

Supported values:

  1. '' (empty string; uses Jackrabbit's default millisecond resolution)
  2. year
  3. month
  4. day
  5. hour

Important:
Do not set the default resolution to an empty string. Using millisecond resolution can cause poor query performance and may lead to out-of-memory errors.

Verification

After updating your queries or configuration, verify that date range queries execute quickly and return the expected results. Monitor repository performance and memory usage to ensure the chosen resolution meets your requirements.

Share Feedback
Page: /build/search/jcr-search/out-of-the-box-fast-date-range-query-support-from-hst
Section: Build
Category *