1 package org.apache.lucene.search.highlight;
5 * Licensed to the Apache Software Foundation (ASF) under one or more
6 * contributor license agreements. See the NOTICE file distributed with
7 * this work for additional information regarding copyright ownership.
8 * The ASF licenses this file to You under the Apache License, Version 2.0
9 * (the "License"); you may not use this file except in compliance with
10 * the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
26 * Lightweight class to hold term, weight, and positions used for scoring this
29 public class WeightedSpanTerm extends WeightedTerm{
30 boolean positionSensitive;
31 private List<PositionSpan> positionSpans = new ArrayList<PositionSpan>();
37 public WeightedSpanTerm(float weight, String term) {
39 this.positionSpans = new ArrayList<PositionSpan>();
45 * @param positionSensitive
47 public WeightedSpanTerm(float weight, String term, boolean positionSensitive) {
49 this.positionSensitive = positionSensitive;
53 * Checks to see if this term is valid at <code>position</code>.
56 * to check against valid term positions
57 * @return true iff this term is a hit at this position
59 public boolean checkPosition(int position) {
60 // There would probably be a slight speed improvement if PositionSpans
61 // where kept in some sort of priority queue - that way this method
63 // bail early without checking each PositionSpan.
64 Iterator<PositionSpan> positionSpanIt = positionSpans.iterator();
66 while (positionSpanIt.hasNext()) {
67 PositionSpan posSpan = positionSpanIt.next();
69 if (((position >= posSpan.start) && (position <= posSpan.end))) {
77 public void addPositionSpans(List<PositionSpan> positionSpans) {
78 this.positionSpans.addAll(positionSpans);
81 public boolean isPositionSensitive() {
82 return positionSensitive;
85 public void setPositionSensitive(boolean positionSensitive) {
86 this.positionSensitive = positionSensitive;
89 public List<PositionSpan> getPositionSpans() {
95 // Utility class to store a Span
100 public PositionSpan(int start, int end) {