@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();
    }
@ 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 ( ) ; }
{@inheritDoc}