mirror of https://github.com/apache/lucene.git
close the linefiledocs always
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1326473 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
776e1b4a98
commit
fffdb569d0
|
@ -34,6 +34,7 @@ import java.util.HashMap;
|
||||||
import org.apache.lucene.analysis.tokenattributes.*;
|
import org.apache.lucene.analysis.tokenattributes.*;
|
||||||
import org.apache.lucene.util.Attribute;
|
import org.apache.lucene.util.Attribute;
|
||||||
import org.apache.lucene.util.AttributeImpl;
|
import org.apache.lucene.util.AttributeImpl;
|
||||||
|
import org.apache.lucene.util.IOUtils;
|
||||||
import org.apache.lucene.util.LuceneTestCase;
|
import org.apache.lucene.util.LuceneTestCase;
|
||||||
import org.apache.lucene.util.LineFileDocs;
|
import org.apache.lucene.util.LineFileDocs;
|
||||||
import org.apache.lucene.util._TestUtil;
|
import org.apache.lucene.util._TestUtil;
|
||||||
|
@ -454,42 +455,46 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
|
||||||
private static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple, boolean offsetsAreCorrect) throws IOException {
|
private static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple, boolean offsetsAreCorrect) throws IOException {
|
||||||
|
|
||||||
final LineFileDocs docs = new LineFileDocs(random);
|
final LineFileDocs docs = new LineFileDocs(random);
|
||||||
|
|
||||||
for (int i = 0; i < iterations; i++) {
|
try {
|
||||||
String text;
|
for (int i = 0; i < iterations; i++) {
|
||||||
|
String text;
|
||||||
if (random.nextInt(10) == 7) {
|
|
||||||
// real data from linedocs
|
if (random.nextInt(10) == 7) {
|
||||||
text = docs.nextDoc().get("body");
|
// real data from linedocs
|
||||||
if (text.length() > maxWordLength) {
|
text = docs.nextDoc().get("body");
|
||||||
|
if (text.length() > maxWordLength) {
|
||||||
// Take a random slice from the text...:
|
|
||||||
int startPos = random.nextInt(text.length() - maxWordLength);
|
// Take a random slice from the text...:
|
||||||
if (startPos > 0 && Character.isLowSurrogate(text.charAt(startPos))) {
|
int startPos = random.nextInt(text.length() - maxWordLength);
|
||||||
// Take care not to split up a surrogate pair:
|
if (startPos > 0 && Character.isLowSurrogate(text.charAt(startPos))) {
|
||||||
startPos--;
|
// Take care not to split up a surrogate pair:
|
||||||
assert Character.isHighSurrogate(text.charAt(startPos));
|
startPos--;
|
||||||
|
assert Character.isHighSurrogate(text.charAt(startPos));
|
||||||
|
}
|
||||||
|
int endPos = startPos + maxWordLength - 1;
|
||||||
|
if (Character.isHighSurrogate(text.charAt(endPos))) {
|
||||||
|
// Take care not to split up a surrogate pair:
|
||||||
|
endPos--;
|
||||||
|
}
|
||||||
|
text = text.substring(startPos, 1+endPos);
|
||||||
}
|
}
|
||||||
int endPos = startPos + maxWordLength - 1;
|
} else {
|
||||||
if (Character.isHighSurrogate(text.charAt(endPos))) {
|
// synthetic
|
||||||
// Take care not to split up a surrogate pair:
|
text = randomAnalysisString(random, maxWordLength, simple);
|
||||||
endPos--;
|
}
|
||||||
}
|
|
||||||
text = text.substring(startPos, 1+endPos);
|
try {
|
||||||
|
checkAnalysisConsistency(random, a, useCharFilter, text, offsetsAreCorrect);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
// TODO: really we should pass a random seed to
|
||||||
|
// checkAnalysisConsistency then print it here too:
|
||||||
|
System.err.println("TEST FAIL: useCharFilter=" + useCharFilter + " text='" + escape(text) + "'");
|
||||||
|
Rethrow.rethrow(t);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
// synthetic
|
|
||||||
text = randomAnalysisString(random, maxWordLength, simple);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
checkAnalysisConsistency(random, a, useCharFilter, text, offsetsAreCorrect);
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// TODO: really we should pass a random seed to
|
|
||||||
// checkAnalysisConsistency then print it here too:
|
|
||||||
System.err.println("TEST FAIL: useCharFilter=" + useCharFilter + " text='" + escape(text) + "'");
|
|
||||||
Rethrow.rethrow(t);
|
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
IOUtils.closeWhileHandlingException(docs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue