Skip to content

Apache Lucene open-source search software

LUCENE-7914: Fix TestSuggestField#testRealisticKeys: trim big titles to make sure that they can pass the max recursion level in Operations#topsortState.

Jim Ferenczi2a8930cf838b
diff --git a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java
index a797ca5f1be..a6659e082d5 100644
--- a/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java
+++ b/lucene/suggest/src/test/org/apache/lucene/search/suggest/document/TestSuggestField.java
@@ -719,13 +719,15 @@ public class TestSuggestField extends LuceneTestCase {
for (int i = 0; i < num; i++) {
Document document = lineFileDocs.nextDoc();
String title = document.getField("title").stringValue();
+ int maxLen = Math.min(title.length(), 500);
+ String prefix = title.substring(0, maxLen);
int weight = random().nextInt(Integer.MAX_VALUE);
- Integer prevWeight = mappings.get(title);
+ Integer prevWeight = mappings.get(prefix);
if (prevWeight == null || prevWeight < weight) {
- mappings.put(title, weight);
+ mappings.put(prefix, weight);
}
Document doc = new Document();
- doc.add(new SuggestField("suggest_field", title, weight));
+ doc.add(new SuggestField("suggest_field", prefix, weight));
iw.addDocument(doc);
if (rarely()) {