SOLR-6085: Suggester crashes when prefixToken is longer than surface form

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1638711 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jan Høydahl 2014-11-12 08:25:28 +00:00
parent cc1b4bea5e
commit a323091dac
3 changed files with 33 additions and 3 deletions

View File

@ -695,12 +695,14 @@ public class AnalyzingInfixSuggester extends Lookup implements Closeable {
protected void addPrefixMatch(StringBuilder sb, String surface, String analyzed, String prefixToken) {
// TODO: apps can try to invert their analysis logic
// here, e.g. downcase the two before checking prefix:
if (prefixToken.length() >= surface.length()) {
addWholeMatch(sb, surface, analyzed);
return;
}
sb.append("<b>");
sb.append(surface.substring(0, prefixToken.length()));
sb.append("</b>");
if (prefixToken.length() < surface.length()) {
sb.append(surface.substring(prefixToken.length()));
}
sb.append(surface.substring(prefixToken.length()));
}
@Override

View File

@ -41,9 +41,11 @@ import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.suggest.Input;
import org.apache.lucene.search.suggest.InputArrayIterator;
import org.apache.lucene.search.suggest.Lookup.LookupResult;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.junit.Test;
public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
@ -1076,4 +1078,28 @@ public class AnalyzingInfixSuggesterTest extends LuceneTestCase {
suggester.close();
}
}
@Test
public void testAddPrefixMatch() throws IOException {
Analyzer a = new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false);
Directory dir = newDirectory();
AnalyzingInfixSuggester suggester = new AnalyzingInfixSuggester(dir, a);
assertEquals("<b>Sol</b>r", pfmToString(suggester, "Solr", "Sol"));
assertEquals("<b>Solr</b>", pfmToString(suggester, "Solr", "Solr"));
// Test SOLR-6085 - the analyzed tokens match due to ss->ß normalization
assertEquals("<b>daß</b>", pfmToString(suggester, "daß", "dass"));
dir.close();
suggester.close();
}
private String pfmToString(AnalyzingInfixSuggester suggester, String surface, String prefix) throws IOException {
StringBuilder sb = new StringBuilder();
suggester.addPrefixMatch(sb, surface, "", prefix);
return sb.toString();
}
}

View File

@ -400,6 +400,8 @@ Bug Fixes
* SOLR-6704: TrieDateField type drops schema properties in branch 4.10 (Tomás Fernández Löbbe)
* SOLR-6085: Suggester crashes when prefixToken is longer than surface form (janhoy)
================== 4.10.2 ==================
Bug Fixes