1 package org.apache.lucene.search.spans;
3 * Licensed to the Apache Software Foundation (ASF) under one or more
4 * contributor license agreements. See the NOTICE file distributed with
5 * this work for additional information regarding copyright ownership.
6 * The ASF licenses this file to You under the Apache License, Version 2.0
7 * (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 import org.apache.lucene.util.ToStringUtils;
22 import java.io.IOException;
26 * Checks to see if the {@link #getMatch()} lies between a start and end position
28 * @see org.apache.lucene.search.spans.SpanFirstQuery for a derivation that is optimized for the case where start position is 0
30 public class SpanPositionRangeQuery extends SpanPositionCheckQuery {
31 protected int start = 0;
34 public SpanPositionRangeQuery(SpanQuery match, int start, int end) {
42 protected AcceptStatus acceptPosition(Spans spans) throws IOException {
43 assert spans.start() != spans.end();
44 if (spans.start() >= end)
45 return AcceptStatus.NO_AND_ADVANCE;
46 else if (spans.start() >= start && spans.end() <= end)
47 return AcceptStatus.YES;
49 return AcceptStatus.NO;
54 * @return The minimum position permitted in a match
56 public int getStart() {
61 * @return the maximum end position permitted in a match.
68 public String toString(String field) {
69 StringBuilder buffer = new StringBuilder();
70 buffer.append("spanPosRange(");
71 buffer.append(match.toString(field));
72 buffer.append(", ").append(start).append(", ");
75 buffer.append(ToStringUtils.boost(getBoost()));
76 return buffer.toString();
80 public Object clone() {
81 SpanPositionRangeQuery result = new SpanPositionRangeQuery((SpanQuery) match.clone(), start, end);
82 result.setBoost(getBoost());
87 public boolean equals(Object o) {
88 if (this == o) return true;
89 if (!(o instanceof SpanPositionRangeQuery)) return false;
91 SpanPositionRangeQuery other = (SpanPositionRangeQuery)o;
92 return this.end == other.end && this.start == other.start
93 && this.match.equals(other.match)
94 && this.getBoost() == other.getBoost();
98 public int hashCode() {
99 int h = match.hashCode();
100 h ^= (h << 8) | (h >>> 25); // reversible
101 h ^= Float.floatToRawIntBits(getBoost()) ^ end ^ start;