|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.index.query; |
| 21 | + |
| 22 | +import org.apache.lucene.index.IndexReader; |
| 23 | +import org.apache.lucene.search.BooleanClause; |
| 24 | +import org.apache.lucene.search.Query; |
| 25 | +import org.apache.lucene.search.QueryVisitor; |
| 26 | + |
| 27 | +import java.io.IOException; |
| 28 | +import java.util.Objects; |
| 29 | + |
| 30 | +/** |
| 31 | + * A simple wrapper class that indicates that the wrapped query has made use of NOW |
| 32 | + * when parsing its datemath. Useful for preprocessors such as the percolator that |
| 33 | + * need to know when not to extract dates from the query. |
| 34 | + */ |
| 35 | +public class DateRangeIncludingNowQuery extends Query { |
| 36 | + |
| 37 | + private final Query in; |
| 38 | + |
| 39 | + public DateRangeIncludingNowQuery(Query in) { |
| 40 | + this.in = in; |
| 41 | + } |
| 42 | + |
| 43 | + public Query getQuery() { |
| 44 | + return in; |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public Query rewrite(IndexReader reader) throws IOException { |
| 49 | + return in; |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public String toString(String field) { |
| 54 | + return "DateRangeIncludingNowQuery(" + in + ")"; |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void visit(QueryVisitor visitor) { |
| 59 | + in.visit(visitor.getSubVisitor(BooleanClause.Occur.MUST, this)); |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public boolean equals(Object o) { |
| 64 | + if (this == o) return true; |
| 65 | + if (o == null || getClass() != o.getClass()) return false; |
| 66 | + DateRangeIncludingNowQuery that = (DateRangeIncludingNowQuery) o; |
| 67 | + return Objects.equals(in, that.in); |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public int hashCode() { |
| 72 | + return Objects.hash(in); |
| 73 | + } |
| 74 | +} |
0 commit comments