01: package org.apache.lucene.search.highlight;
02:
03: /**
04: * Copyright 2002-2004 The Apache Software Foundation
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
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.
17: */
18:
19: /**
20: * Low-level class used to record information about a section of a document
21: * with a score.
22: * @author MAHarwood
23: *
24: *
25: */
26: public class TextFragment {
27: StringBuffer markedUpText;
28: int fragNum;
29: int textStartPos;
30: int textEndPos;
31: float score;
32:
33: public TextFragment(StringBuffer markedUpText, int textStartPos,
34: int fragNum) {
35: this .markedUpText = markedUpText;
36: this .textStartPos = textStartPos;
37: this .fragNum = fragNum;
38: }
39:
40: void setScore(float score) {
41: this .score = score;
42: }
43:
44: public float getScore() {
45: return score;
46: }
47:
48: /**
49: * @param frag2 Fragment to be merged into this one
50: */
51: public void merge(TextFragment frag2) {
52: textEndPos = frag2.textEndPos;
53: score = Math.max(score, frag2.score);
54: }
55:
56: /**
57: * @param fragment
58: * @return true if this fragment follows the one passed
59: */
60: public boolean follows(TextFragment fragment) {
61: return textStartPos == fragment.textEndPos;
62: }
63:
64: /**
65: * @return the fragment sequence number
66: */
67: public int getFragNum() {
68: return fragNum;
69: }
70:
71: /* Returns the marked-up text for this text fragment
72: */
73: public String toString() {
74: return markedUpText.substring(textStartPos, textEndPos);
75: }
76:
77: }
|