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

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150706 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Daniel Naber 2004-12-12 20:26:27 +00:00
parent a7495a6df8
commit 857624d038
2 changed files with 16 additions and 2 deletions

View File

@ -17,6 +17,7 @@ package org.apache.lucene.index;
*/ */
import java.io.IOException; import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader; import java.io.Reader;
import java.io.StringReader; import java.io.StringReader;
import java.util.Hashtable; import java.util.Hashtable;
@ -38,6 +39,7 @@ final class DocumentWriter {
private Similarity similarity; private Similarity similarity;
private FieldInfos fieldInfos; private FieldInfos fieldInfos;
private int maxFieldLength; private int maxFieldLength;
private PrintStream infoStream;
/** /**
* *
@ -159,8 +161,11 @@ final class DocumentWriter {
addPosition(fieldName, t.termText(), position++, null); addPosition(fieldName, t.termText(), position++, null);
lastToken = t; lastToken = t;
if (++length > maxFieldLength) if (++length > maxFieldLength) {
if (infoStream != null)
infoStream.println("maxFieldLength " +maxFieldLength+ " reached, ignoring following tokens");
break; break;
}
} }
if(lastToken != null) 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 final class Posting { // info about a Term in a doc

View File

@ -321,7 +321,8 @@ public class IndexWriter {
return mergeFactor; 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) { public void setInfoStream(PrintStream infoStream) {
this.infoStream = infoStream; this.infoStream = infoStream;
@ -404,6 +405,7 @@ public class IndexWriter {
public void addDocument(Document doc, Analyzer analyzer) throws IOException { public void addDocument(Document doc, Analyzer analyzer) throws IOException {
DocumentWriter dw = DocumentWriter dw =
new DocumentWriter(ramDirectory, analyzer, similarity, maxFieldLength); new DocumentWriter(ramDirectory, analyzer, similarity, maxFieldLength);
dw.setInfoStream(infoStream);
String segmentName = newSegmentName(); String segmentName = newSegmentName();
dw.addDocument(segmentName, doc); dw.addDocument(segmentName, doc);
synchronized (this) { synchronized (this) {