01: package org.apache.lucene.search.highlight;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: /**
21: * Low-level class used to record information about a section of a document
22: * with a score.
23: * @author MAHarwood
24: *
25: *
26: */
27: public class TextFragment {
28: StringBuffer markedUpText;
29: int fragNum;
30: int textStartPos;
31: int textEndPos;
32: float score;
33:
34: public TextFragment(StringBuffer markedUpText, int textStartPos,
35: int fragNum) {
36: this .markedUpText = markedUpText;
37: this .textStartPos = textStartPos;
38: this .fragNum = fragNum;
39: }
40:
41: void setScore(float score) {
42: this .score = score;
43: }
44:
45: public float getScore() {
46: return score;
47: }
48:
49: /**
50: * @param frag2 Fragment to be merged into this one
51: */
52: public void merge(TextFragment frag2) {
53: textEndPos = frag2.textEndPos;
54: score = Math.max(score, frag2.score);
55: }
56:
57: /**
58: * @param fragment
59: * @return true if this fragment follows the one passed
60: */
61: public boolean follows(TextFragment fragment) {
62: return textStartPos == fragment.textEndPos;
63: }
64:
65: /**
66: * @return the fragment sequence number
67: */
68: public int getFragNum() {
69: return fragNum;
70: }
71:
72: /* Returns the marked-up text for this text fragment
73: */
74: public String toString() {
75: return markedUpText.substring(textStartPos, textEndPos);
76: }
77:
78: }
|