KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lucene > search > highlight > TextFragment


1 package org.apache.lucene.search.highlight;
2 /**
3  * Copyright 2002-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18
19 /**
20  * Copyright 2002-2004 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
21  */

22 public class TextFragment
23 {
24     StringBuffer JavaDoc markedUpText;
25     int fragNum;
26     int textStartPos;
27     int textEndPos;
28     float score;
29
30     public TextFragment(StringBuffer JavaDoc markedUpText,int textStartPos, int fragNum)
31     {
32         this.markedUpText=markedUpText;
33         this.textStartPos = textStartPos;
34         this.fragNum = fragNum;
35     }
36     /**
37      * @param score The score to set.
38      * @uml.property name="score"
39      */

40     void setScore(float score)
41     {
42         this.score=score;
43     }
44     /**
45      * @return Returns the score.
46      * @uml.property name="score"
47      */

48     public float getScore()
49     {
50         return score;
51     }
52     /**
53      * @param frag2 Fragment to be merged into this one
54      */

55   public void merge(TextFragment frag2)
56   {
57     textEndPos = frag2.textEndPos;
58     score=Math.max(score,frag2.score);
59   }
60   /**
61      * @param fragment
62      * @return true if this fragment follows the one passed
63      */

64     public boolean follows(TextFragment fragment)
65     {
66         return textStartPos == fragment.textEndPos;
67     }
68
69     /**
70      * @return the fragment sequence number
71      * @uml.property name="fragNum"
72      */

73     public int getFragNum()
74     {
75         return fragNum;
76     }
77
78     /* Returns the marked-up text for this text fragment
79      */

80     public String JavaDoc toString() {
81         return markedUpText.substring(textStartPos, textEndPos);
82     }
83
84 }
85
Popular Tags