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 with
21: * a score.
22: *
23: * @author MAHarwood
24: */
25: public class TextFragment {
26: StringBuffer markedUpText;
27:
28: int fragNum;
29:
30: int textStartPos;
31:
32: int textEndPos;
33:
34: float score;
35:
36: public TextFragment(StringBuffer markedUpText, int textStartPos,
37: int fragNum) {
38: this .markedUpText = markedUpText;
39: this .textStartPos = textStartPos;
40: this .fragNum = fragNum;
41: }
42:
43: void setScore(float score) {
44: this .score = score;
45: }
46:
47: public float getScore() {
48: return score;
49: }
50:
51: /**
52: * @param frag2
53: * Fragment to be merged into this one
54: */
55: public void merge(TextFragment frag2) {
56: textEndPos = frag2.textEndPos;
57: score = Math.max(score, frag2.score);
58: }
59:
60: /**
61: * @param fragment
62: * @return true if this fragment follows the one passed
63: */
64: public boolean follows(TextFragment fragment) {
65: return textStartPos == fragment.textEndPos;
66: }
67:
68: /**
69: * @return the fragment sequence number
70: */
71: public int getFragNum() {
72: return fragNum;
73: }
74:
75: /*
76: * Returns the marked-up text for this text fragment
77: */
78: public String toString() {
79: // make certain we dont truncate entities.
80: return markedUpText.substring(textStartPos, Math.min(
81: textEndPos + 1, markedUpText.length()));
82: }
83:
84: }
|