public override IList <LookupResult> DoLookup(string key, IEnumerable <BytesRef> contexts, bool higherWeightsFirst, int num) { if (contexts != null) { throw new ArgumentException("this suggester doesn't support contexts"); } IList <FSTCompletion.Completion> completions; if (higherWeightsFirst) { completions = higherWeightsCompletion.DoLookup(key, num); } else { completions = normalCompletion.DoLookup(key, num); } List <LookupResult> results = new List <LookupResult>(completions.Count); CharsRef spare = new CharsRef(); foreach (FSTCompletion.Completion c in completions) { spare.Grow(c.Utf8.Length); UnicodeUtil.UTF8toUTF16(c.Utf8, spare); results.Add(new LookupResult(spare.ToString(), c.Bucket)); } return(results); }
public void TestThreeByte() { //string key = new string(new sbyte[] { // (sbyte) 0xF0, (sbyte) 0xA4, (sbyte) 0xAD, (sbyte) 0xA2}, 0, 4, Encoding.UTF8); string key = Encoding.UTF8.GetString(new byte[] { 0xF0, 0xA4, 0xAD, 0xA2 }); FSTCompletionBuilder builder = new FSTCompletionBuilder(); builder.Add(new BytesRef(key), 0); FSTCompletion lookup = builder.Build(); IEnumerable <FSTCompletion.Completion> result = lookup.DoLookup(StringToCharSequence(key).ToString(), 1); assertEquals(1, result.Count()); }
public void TestRequestedCount() { // 'one' is promoted after collecting two higher ranking results. AssertMatchEquals(completion.DoLookup(StringToCharSequence("one").ToString(), 2), "one/0.0", "oneness/1.0"); // 'four' is collected in a bucket and then again as an exact match. AssertMatchEquals(completion.DoLookup(StringToCharSequence("four").ToString(), 2), "four/0.0", "fourblah/1.0"); // Check reordering of exact matches. AssertMatchEquals(completion.DoLookup(StringToCharSequence("four").ToString(), 4), "four/0.0", "fourblah/1.0", "fourteen/1.0", "fourier/0.0"); // 'one' is at the top after collecting all alphabetical results. AssertMatchEquals(completionAlphabetical.DoLookup(StringToCharSequence("one").ToString(), 2), "one/0.0", "oneness/1.0"); // 'one' is not promoted after collecting two higher ranking results. FSTCompletion noPromotion = new FSTCompletion(completion.FST, true, false); AssertMatchEquals(noPromotion.DoLookup(StringToCharSequence("one").ToString(), 2), "oneness/1.0", "onerous/1.0"); // 'one' is at the top after collecting all alphabetical results. AssertMatchEquals(completionAlphabetical.DoLookup(StringToCharSequence("one").ToString(), 2), "one/0.0", "oneness/1.0"); }
public void TestExactMatchHighPriority() { AssertMatchEquals(completion.DoLookup(StringToCharSequence("two").ToString(), 1), "two/1.0"); }
public void TestEmptyInput() { completion = new FSTCompletionBuilder().Build(); AssertMatchEquals(completion.DoLookup(StringToCharSequence("").ToString(), 10)); }