add --shared
[pylucene.git] / lucene-java-3.4.0 / lucene / contrib / highlighter / src / java / org / apache / lucene / search / highlight / TextFragment.java
1 package org.apache.lucene.search.highlight;
2 /**
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements.  See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License.  You may obtain a copy of the License at
9  *
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 /**
21  * Low-level class used to record information about a section of a document 
22  * with a score.
23  *
24  * 
25  */
26 public class TextFragment
27 {
28         CharSequence markedUpText;
29         int fragNum;
30         int textStartPos;
31         int textEndPos;
32         float score;
33
34         public TextFragment(CharSequence markedUpText,int textStartPos, int fragNum)
35         {
36                 this.markedUpText=markedUpText;
37                 this.textStartPos = textStartPos;
38                 this.fragNum = fragNum;
39         }
40   /** 
41    * @deprecated Use {@link #TextFragment(CharSequence, int, int)} instead.
42    * This constructor will be removed in Lucene 4.0
43    */
44         @Deprecated
45         public TextFragment(StringBuffer markedUpText,int textStartPos, int fragNum)
46         {
47                 this.markedUpText=markedUpText;
48                 this.textStartPos = textStartPos;
49                 this.fragNum = fragNum;
50         }
51         void setScore(float score)
52         {
53                 this.score=score;
54         }
55         public float getScore()
56         {
57                 return score;
58         }
59         /**
60          * @param frag2 Fragment to be merged into this one
61          */
62   public void merge(TextFragment frag2)
63   {
64     textEndPos = frag2.textEndPos;
65     score=Math.max(score,frag2.score);
66   }
67   /**
68          * @param fragment 
69          * @return true if this fragment follows the one passed
70          */
71         public boolean follows(TextFragment fragment)
72         {
73                 return textStartPos == fragment.textEndPos;
74         }
75
76         /**
77          * @return the fragment sequence number
78          */
79         public int getFragNum()
80         {
81                 return fragNum;
82         }
83
84         /* Returns the marked-up text for this text fragment 
85          */
86         @Override
87         public String toString() {
88                 return markedUpText.subSequence(textStartPos, textEndPos).toString();
89         }
90
91 }