Skip to content

Apache Lucene open-source search software

print a message to infoStream if the number of maximum tokens per document (maxFieldLength) is reached

Daniel Naber857624d03862
diff --git a/src/java/org/apache/lucene/index/DocumentWriter.java b/src/java/org/apache/lucene/index/DocumentWriter.java
index 4952d227b69..efa36490399 100644
--- a/src/java/org/apache/lucene/index/DocumentWriter.java
+++ b/src/java/org/apache/lucene/index/DocumentWriter.java
@@ -17,6 +17,7 @@ package org.apache.lucene.index;
*/
import java.io.IOException;
+import java.io.PrintStream;
import java.io.Reader;
import java.io.StringReader;
import java.util.Hashtable;
@@ -38,6 +39,7 @@ final class DocumentWriter {
private Similarity similarity;
private FieldInfos fieldInfos;
private int maxFieldLength;
+ private PrintStream infoStream;
/**
*
@@ -159,8 +161,11 @@ final class DocumentWriter {
addPosition(fieldName, t.termText(), position++, null);
lastToken = t;
- if (++length > maxFieldLength)
+ if (++length > maxFieldLength) {
+ if (infoStream != null)
+ infoStream.println("maxFieldLength " +maxFieldLength+ " reached, ignoring following tokens");
break;
+ }
}
if(lastToken != null)
@@ -367,6 +372,13 @@ final class DocumentWriter {
}
}
}
+
+ /** If non-null, a message will be printed to this if maxFieldLength is reached.
+ */
+ void setInfoStream(PrintStream infoStream) {
+ this.infoStream = infoStream;
+ }
+
}
final class Posting { // info about a Term in a doc
diff --git a/src/java/org/apache/lucene/index/IndexWriter.java b/src/java/org/apache/lucene/index/IndexWriter.java
index 0acd3066e57..3c390b1a94c 100644
--- a/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/src/java/org/apache/lucene/index/IndexWriter.java
@@ -321,7 +321,8 @@ public class IndexWriter {
return mergeFactor;
}
- /** If non-null, information about merges will be printed to this.
+ /** If non-null, information about merges and a message when
+ * maxFieldLength is reached will be printed to this.
*/
public void setInfoStream(PrintStream infoStream) {
this.infoStream = infoStream;
@@ -404,6 +405,7 @@ public class IndexWriter {
public void addDocument(Document doc, Analyzer analyzer) throws IOException {
DocumentWriter dw =
new DocumentWriter(ramDirectory, analyzer, similarity, maxFieldLength);
+ dw.setInfoStream(infoStream);
String segmentName = newSegmentName();
dw.addDocument(segmentName, doc);
synchronized (this) {