pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / highlighter / src / test / org / apache / lucene / search / vectorhighlight / ScoreOrderFragmentsBuilderTest.java
1 package org.apache.lucene.search.vectorhighlight;
2
3 /**
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  */
19
20 import org.apache.lucene.search.Query;
21
22 public class ScoreOrderFragmentsBuilderTest extends AbstractTestCase {
23   
24   public void test3Frags() throws Exception {
25     FieldFragList ffl = ffl( "a c", "a b b b b b b b b b b b a b a b b b b b c a a b b" );
26     ScoreOrderFragmentsBuilder sofb = new ScoreOrderFragmentsBuilder();
27     String[] f = sofb.createFragments( reader, 0, F, ffl, 3 );
28     assertEquals( 3, f.length );
29     // check score order
30     assertEquals( "<b>c</b> <b>a</b> <b>a</b> b b ", f[0] );
31     assertEquals( "b b <b>a</b> b <b>a</b> b b b b b c", f[1] );
32     assertEquals( "<b>a</b> b b b b b b b b b b", f[2] );
33   }
34
35   private FieldFragList ffl( String queryValue, String indexValue ) throws Exception {
36     make1d1fIndex( indexValue );
37     Query query = paW.parse( queryValue );
38     FieldQuery fq = new FieldQuery( query, true, true );
39     FieldTermStack stack = new FieldTermStack( reader, 0, F, fq );
40     FieldPhraseList fpl = new FieldPhraseList( stack, fq );
41     return new SimpleFragListBuilder().createFieldFragList( fpl, 20 );
42   }
43 }