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.Collections;
21 import java.util.Comparator;
22 import java.util.List;
24 import org.apache.lucene.search.vectorhighlight.FieldFragList.WeightedFragInfo;
27 * An implementation of FragmentsBuilder that outputs score-order fragments.
29 public class ScoreOrderFragmentsBuilder extends BaseFragmentsBuilder {
34 public ScoreOrderFragmentsBuilder(){
41 * @param preTags array of pre-tags for markup terms.
42 * @param postTags array of post-tags for markup terms.
44 public ScoreOrderFragmentsBuilder( String[] preTags, String[] postTags ){
45 super( preTags, postTags );
49 * Sort by score the list of WeightedFragInfo
52 public List<WeightedFragInfo> getWeightedFragInfoList( List<WeightedFragInfo> src ) {
53 Collections.sort( src, new ScoreComparator() );
57 public static class ScoreComparator implements Comparator<WeightedFragInfo> {
59 public int compare( WeightedFragInfo o1, WeightedFragInfo o2 ) {
60 if( o1.totalBoost > o2.totalBoost ) return -1;
61 else if( o1.totalBoost < o2.totalBoost ) return 1;
62 // if same score then check startOffset
64 if( o1.startOffset < o2.startOffset ) return -1;
65 else if( o1.startOffset > o2.startOffset ) return 1;