1 package org.apache.lucene.search.highlight;
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
21 * Low-level class used to record information about a section of a document
26 public class TextFragment
28 CharSequence markedUpText;
34 public TextFragment(CharSequence markedUpText,int textStartPos, int fragNum)
36 this.markedUpText=markedUpText;
37 this.textStartPos = textStartPos;
38 this.fragNum = fragNum;
41 * @deprecated Use {@link #TextFragment(CharSequence, int, int)} instead.
42 * This constructor will be removed in Lucene 4.0
45 public TextFragment(StringBuffer markedUpText,int textStartPos, int fragNum)
47 this.markedUpText=markedUpText;
48 this.textStartPos = textStartPos;
49 this.fragNum = fragNum;
51 void setScore(float score)
55 public float getScore()
60 * @param frag2 Fragment to be merged into this one
62 public void merge(TextFragment frag2)
64 textEndPos = frag2.textEndPos;
65 score=Math.max(score,frag2.score);
69 * @return true if this fragment follows the one passed
71 public boolean follows(TextFragment fragment)
73 return textStartPos == fragment.textEndPos;
77 * @return the fragment sequence number
79 public int getFragNum()
84 /* Returns the marked-up text for this text fragment
87 public String toString() {
88 return markedUpText.subSequence(textStartPos, textEndPos).toString();