1
package org.apache.lucene.search.vectorhighlight;
3
import org.apache.lucene.search.Query;
6
* Licensed to the Apache Software Foundation (ASF) under one or more
7
* contributor license agreements. See the NOTICE file distributed with
8
* this work for additional information regarding copyright ownership.
9
* The ASF licenses this file to You under the Apache License, Version 2.0
10
* (the "License"); you may not use this file except in compliance with
11
* the License. You may obtain a copy of the License at
13
* http://www.apache.org/licenses/LICENSE-2.0
15
* Unless required by applicable law or agreed to in writing, software
16
* distributed under the License is distributed on an "AS IS" BASIS,
17
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
* See the License for the specific language governing permissions and
19
* limitations under the License.
22
public class SingleFragListBuilderTest extends AbstractTestCase {
24
public void testNullFieldFragList() throws Exception {
25
SingleFragListBuilder sflb = new SingleFragListBuilder();
26
FieldFragList ffl = sflb.createFieldFragList( fpl( "a", "b c d" ), 100 );
27
assertEquals( 0, ffl.getFragInfos().size() );
30
public void testShortFieldFragList() throws Exception {
31
SingleFragListBuilder sflb = new SingleFragListBuilder();
32
FieldFragList ffl = sflb.createFieldFragList( fpl( "a", "a b c d" ), 100 );
33
assertEquals( 1, ffl.getFragInfos().size() );
34
assertEquals( "subInfos=(a((0,1)))/1.0(0,2147483647)", ffl.getFragInfos().get( 0 ).toString() );
37
public void testLongFieldFragList() throws Exception {
38
SingleFragListBuilder sflb = new SingleFragListBuilder();
39
FieldFragList ffl = sflb.createFieldFragList( fpl( "a", "a b c d", "a b c d e f g h i", "j k l m n o p q r s t u v w x y z a b c", "d e f g" ), 100 );
40
assertEquals( 1, ffl.getFragInfos().size() );
41
assertEquals( "subInfos=(a((0,1))a((8,9))a((60,61)))/3.0(0,2147483647)", ffl.getFragInfos().get( 0 ).toString() );
44
private FieldPhraseList fpl( String queryValue, String... indexValues ) throws Exception {
45
make1dmfIndex( indexValues );
46
Query query = paW.parse( queryValue );
47
FieldQuery fq = new FieldQuery( query, true, true );
48
FieldTermStack stack = new FieldTermStack( reader, 0, F, fq );
49
return new FieldPhraseList( stack, fq );