1
package org.apache.solr.analysis;
4
* Copyright 2004 The Apache Software Foundation
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
10
* http://www.apache.org/licenses/LICENSE-2.0
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
19
import java.io.IOException;
20
import java.io.StringReader;
21
import java.util.HashMap;
24
import org.apache.lucene.analysis.MockTokenizer;
25
import org.apache.lucene.analysis.TokenStream;
27
public class LengthFilterTest extends BaseTokenTestCase {
29
public void test() throws IOException {
30
LengthFilterFactory factory = new LengthFilterFactory();
31
Map<String, String> args = new HashMap<String, String>();
32
args.put(LengthFilterFactory.MIN_KEY, String.valueOf(4));
33
args.put(LengthFilterFactory.MAX_KEY, String.valueOf(10));
34
// default: args.put("enablePositionIncrements", "false");
36
String test = "foo foobar super-duper-trooper";
37
TokenStream stream = factory.create(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false));
38
assertTokenStreamContents(stream, new String[] { "foobar" }, new int[] { 1 });
40
factory = new LengthFilterFactory();
41
args = new HashMap<String, String>();
42
args.put(LengthFilterFactory.MIN_KEY, String.valueOf(4));
43
args.put(LengthFilterFactory.MAX_KEY, String.valueOf(10));
44
args.put("enablePositionIncrements", "true");
46
stream = factory.create(new MockTokenizer(new StringReader(test), MockTokenizer.WHITESPACE, false));
47
assertTokenStreamContents(stream, new String[] { "foobar" }, new int[] { 2 });
b'\\ No newline at end of file'