BitemporalCondition extends SingleMapperCondition<BitemporalMapper> { @Override public Query doQuery(BitemporalMapper mapper, Analyzer analyzer) { Long vtFromTime = parseTime(mapper, DEFAULT_FROM, vtFrom); Long vtToTime = parseTime(mapper, DEFAULT_TO, vtTo); Long ttFromTime = parseTime(mapper, DEFAULT_FROM, ttFrom); Long ttToTime = parseTime(mapper, DEFAULT_TO, ttTo); Long minTime = BitemporalDateTime.MIN.toTimestamp(); Long maxTime = BitemporalDateTime.MAX.toTimestamp(); BooleanQuery.Builder builder = new BooleanQuery.Builder(); if (!((vtFromTime.equals(0L)) && (vtToTime.equals(Long.MAX_VALUE)))) { BooleanQuery.Builder validBuilder = new BooleanQuery.Builder(); validBuilder.add(newLongRange(field + BitemporalMapper.VT_FROM_FIELD_SUFFIX, vtFromTime, vtToTime, true, true), SHOULD); validBuilder.add(newLongRange(field + BitemporalMapper.VT_TO_FIELD_SUFFIX, vtFromTime, vtToTime, true, true), SHOULD); BooleanQuery.Builder containsValidBuilder = new BooleanQuery.Builder(); containsValidBuilder.add(newLongRange(field + BitemporalMapper.VT_FROM_FIELD_SUFFIX, minTime, vtFromTime, true, true), MUST); containsValidBuilder.add(newLongRange(field + BitemporalMapper.VT_TO_FIELD_SUFFIX, vtToTime, maxTime, true, true), MUST); validBuilder.add(containsValidBuilder.build(), SHOULD); builder.add(validBuilder.build(), MUST); } if (!((ttFromTime.equals(0L)) && (ttToTime.equals(Long.MAX_VALUE)))) { BooleanQuery.Builder transactionBuilder = new BooleanQuery.Builder(); transactionBuilder.add(newLongRange(field + BitemporalMapper.TT_FROM_FIELD_SUFFIX, ttFromTime, ttToTime, true, true), SHOULD); transactionBuilder.add(newLongRange(field + BitemporalMapper.TT_TO_FIELD_SUFFIX, ttFromTime, ttToTime, true, true), SHOULD); BooleanQuery.Builder containsTransactionBuilder = new BooleanQuery.Builder(); containsTransactionBuilder.add(newLongRange(field + BitemporalMapper.TT_FROM_FIELD_SUFFIX, minTime, ttFromTime, true, true), MUST); containsTransactionBuilder.add(newLongRange(field + BitemporalMapper.TT_TO_FIELD_SUFFIX, ttToTime, maxTime, true, true), MUST); transactionBuilder.add(containsTransactionBuilder.build(), SHOULD); builder.add(transactionBuilder.build(), MUST); } return builder.build(); } BitemporalCondition(Float boost, String field, Object vtFrom, Object vtTo, Object ttFrom, Object ttTo); @Override Query doQuery(BitemporalMapper mapper, Analyzer analyzer); @Override MoreObjects.ToStringHelper toStringHelper();  }
@Test public void testQuery() { MapperBuilder<?, ?> mapperBuilder = bitemporalMapper("vtFrom", "vtTo", "ttFrom", "ttTo").pattern("yyyy"); Schema schema = schema().mapper("name", mapperBuilder).build(); BitemporalCondition condition = new BitemporalCondition(0.5f, "name", 2001, 2002, 2003, 2004); Query query = condition.doQuery(schema); assertNotNull("Query is not built", query); assertTrue("Query type is wrong", query instanceof BooleanQuery); }