/** * A predicate to decide if the given {@link WeightedPhraseInfo} should be * accepted as a highlighted phrase or if it should be discarded. * <p> * The default implementation discards phrases that are composed of more than one term * and where the matchLength exceeds the fragment character size. * * @param info the phrase info to accept * @param matchLength the match length of the current phrase * @param fragCharSize the configured fragment character size * @return <code>true</code> if this phrase info should be accepted as a highligh phrase */ protected boolean acceptPhrase(WeightedPhraseInfo info, int matchLength, int fragCharSize) { return info.getTermsOffsets().size() <= 1 || matchLength <= fragCharSize; }
@Override public void add( int startOffset, int endOffset, List<WeightedPhraseInfo> phraseInfoList ) { float totalBoost = 0; List<SubInfo> subInfos = new ArrayList<>(); for( WeightedPhraseInfo phraseInfo : phraseInfoList ){ subInfos.add( new SubInfo( phraseInfo.getText(), phraseInfo.getTermsOffsets(), phraseInfo.getSeqnum(), phraseInfo.getBoost() ) ); totalBoost += phraseInfo.getBoost(); } getFragInfos().add( new WeightedFragInfo( startOffset, endOffset, subInfos, totalBoost ) ); }
length++; tempSubInfos.add( new SubInfo( phraseInfo.getText(), phraseInfo.getTermsOffsets(), phraseInfo.getSeqnum(), phraseTotalBoost ) );