1 package org.apache.lucene.search.highlight; 2 17 18 import org.apache.lucene.analysis.Token; 19 20 24 public class SimpleFragmenter implements Fragmenter 25 { 26 private static final int DEFAULT_FRAGMENT_SIZE =100; 27 private int currentNumFrags; 28 private int fragmentSize; 29 30 31 public SimpleFragmenter() 32 { 33 this(DEFAULT_FRAGMENT_SIZE); 34 } 35 36 37 41 public SimpleFragmenter(int fragmentSize) 42 { 43 this.fragmentSize=fragmentSize; 44 } 45 46 49 public void start(String originalText) 50 { 51 currentNumFrags=1; 52 } 53 54 57 public boolean isNewFragment(Token token) 58 { 59 boolean isNewFrag= token.endOffset()>=(fragmentSize*currentNumFrags); 60 if(isNewFrag) 61 { 62 currentNumFrags++; 63 } 64 return isNewFrag; 65 } 66 67 71 public int getFragmentSize() 72 { 73 return fragmentSize; 74 } 75 76 80 public void setFragmentSize(int size) 81 { 82 fragmentSize = size; 83 } 84 85 } 86 | Popular Tags |