Save This Page
Home » lucene-3.0.1-src » org.apache » lucene » search » highlight » [javadoc | source]
    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   	public TextFragment(StringBuffer markedUpText,int textStartPos, int fragNum)
   45   	{
   46   		this.markedUpText=markedUpText;
   47   		this.textStartPos = textStartPos;
   48   		this.fragNum = fragNum;
   49   	}
   50   	void setScore(float score)
   51   	{
   52   		this.score=score;
   53   	}
   54   	public float getScore()
   55   	{
   56   		return score;
   57   	}
   58   	/**
   59   	 * @param frag2 Fragment to be merged into this one
   60   	 */
   61     public void merge(TextFragment frag2)
   62     {
   63       textEndPos = frag2.textEndPos;
   64       score=Math.max(score,frag2.score);
   65     }
   66     /**
   67   	 * @param fragment 
   68   	 * @return true if this fragment follows the one passed
   69   	 */
   70   	public boolean follows(TextFragment fragment)
   71   	{
   72   		return textStartPos == fragment.textEndPos;
   73   	}
   74   
   75   	/**
   76   	 * @return the fragment sequence number
   77   	 */
   78   	public int getFragNum()
   79   	{
   80   		return fragNum;
   81   	}
   82   
   83   	/* Returns the marked-up text for this text fragment 
   84   	 */
   85   	@Override
   86   	public String toString() {
   87   		return markedUpText.subSequence(textStartPos, textEndPos).toString();
   88   	}
   89   
   90   }

Save This Page
Home » lucene-3.0.1-src » org.apache » lucene » search » highlight » [javadoc | source]