|
Lucene example source code file (FSTLookupTest.java)
The Lucene FSTLookupTest.java source codepackage org.apache.lucene.search.suggest.fst; /** * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Random; import org.apache.lucene.search.suggest.Lookup.LookupResult; import org.apache.lucene.search.suggest.fst.FSTLookup; import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.search.suggest.LookupBenchmarkTest; import org.apache.lucene.search.suggest.TermFreq; import org.apache.lucene.search.suggest.TermFreqArrayIterator; /** * Unit tests for {@link FSTLookup}. */ public class FSTLookupTest extends LuceneTestCase { public static TermFreq tf(String t, float v) { return new TermFreq(t, v); } private FSTLookup lookup; public void setUp() throws Exception { super.setUp(); final TermFreq[] keys = new TermFreq[] { tf("one", 0.5f), tf("oneness", 1), tf("onerous", 1), tf("onesimus", 1), tf("two", 1), tf("twofold", 1), tf("twonk", 1), tf("thrive", 1), tf("through", 1), tf("threat", 1), tf("three", 1), tf("foundation", 1), tf("fourier", 1), tf("four", 1), tf("fourty", 1), tf("xo", 1), }; lookup = new FSTLookup(); lookup.build(new TermFreqArrayIterator(keys)); } public void testExactMatchHighPriority() throws Exception { assertMatchEquals(lookup.lookup("two", true, 1), "two/1.0"); } public void testExactMatchLowPriority() throws Exception { assertMatchEquals(lookup.lookup("one", true, 2), "one/0.0", "oneness/1.0"); } public void testMiss() throws Exception { assertMatchEquals(lookup.lookup("xyz", true, 1)); } public void testAlphabeticWithWeights() throws Exception { assertEquals(0, lookup.lookup("xyz", false, 1).size()); } public void testFullMatchList() throws Exception { assertMatchEquals(lookup.lookup("one", true, Integer.MAX_VALUE), "oneness/1.0", "onerous/1.0", "onesimus/1.0", "one/0.0"); } public void testMultilingualInput() throws Exception { List<TermFreq> input = LookupBenchmarkTest.readTop50KWiki(); lookup = new FSTLookup(); lookup.build(new TermFreqArrayIterator(input)); for (TermFreq tf : input) { assertTrue("Not found: " + tf.term, lookup.get(tf.term) != null); assertEquals(tf.term, lookup.lookup(tf.term, true, 1).get(0).key); } } public void testEmptyInput() throws Exception { lookup = new FSTLookup(); lookup.build(new TermFreqArrayIterator(new TermFreq[0])); assertMatchEquals(lookup.lookup("", true, 10)); } public void testRandom() throws Exception { List<TermFreq> freqs = new ArrayList Other Lucene examples (source code examples)Here is a short list of links related to this Lucene FSTLookupTest.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.