1 package org.apache.lucene.search.vectorhighlight;
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 import java.util.ArrayList;
21 import java.util.List;
23 import org.apache.lucene.search.vectorhighlight.FieldPhraseList.WeightedPhraseInfo;
24 import org.apache.lucene.search.vectorhighlight.FieldPhraseList.WeightedPhraseInfo.Toffs;
27 * FieldFragList has a list of "frag info" that is used by FragmentsBuilder class
28 * to create fragments (snippets).
30 public class FieldFragList {
32 private List<WeightedFragInfo> fragInfos = new ArrayList<WeightedFragInfo>();
37 * @param fragCharSize the length (number of chars) of a fragment
39 public FieldFragList( int fragCharSize ){
43 * convert the list of WeightedPhraseInfo to WeightedFragInfo, then add it to the fragInfos
45 * @param startOffset start offset of the fragment
46 * @param endOffset end offset of the fragment
47 * @param phraseInfoList list of WeightedPhraseInfo objects
49 public void add( int startOffset, int endOffset, List<WeightedPhraseInfo> phraseInfoList ){
50 fragInfos.add( new WeightedFragInfo( startOffset, endOffset, phraseInfoList ) );
54 * return the list of WeightedFragInfos.
58 public List<WeightedFragInfo> getFragInfos() {
62 public static class WeightedFragInfo {
64 List<SubInfo> subInfos;
69 public WeightedFragInfo( int startOffset, int endOffset, List<WeightedPhraseInfo> phraseInfoList ){
70 this.startOffset = startOffset;
71 this.endOffset = endOffset;
72 subInfos = new ArrayList<SubInfo>();
73 for( WeightedPhraseInfo phraseInfo : phraseInfoList ){
74 SubInfo subInfo = new SubInfo( phraseInfo.text, phraseInfo.termsOffsets, phraseInfo.seqnum );
75 subInfos.add( subInfo );
76 totalBoost += phraseInfo.boost;
80 public List<SubInfo> getSubInfos(){
84 public float getTotalBoost(){
88 public int getStartOffset(){
92 public int getEndOffset(){
97 public String toString(){
98 StringBuilder sb = new StringBuilder();
99 sb.append( "subInfos=(" );
100 for( SubInfo si : subInfos )
101 sb.append( si.toString() );
102 sb.append( ")/" ).append( totalBoost ).append( '(' ).append( startOffset ).append( ',' ).append( endOffset ).append( ')' );
103 return sb.toString();
106 public static class SubInfo {
107 final String text; // unnecessary member, just exists for debugging purpose
108 final List<Toffs> termsOffsets; // usually termsOffsets.size() == 1,
109 // but if position-gap > 1 and slop > 0 then size() could be greater than 1
112 SubInfo( String text, List<Toffs> termsOffsets, int seqnum ){
114 this.termsOffsets = termsOffsets;
115 this.seqnum = seqnum;
118 public List<Toffs> getTermsOffsets(){
122 public int getSeqnum(){
127 public String toString(){
128 StringBuilder sb = new StringBuilder();
129 sb.append( text ).append( '(' );
130 for( Toffs to : termsOffsets )
131 sb.append( to.toString() );
133 return sb.toString();