System.out.println("FST stores ord");
} else {
System.out.println("FST stores docFreq");
}
}
TermEnum termEnum = r.terms(new Term("body", ""));
if (VERBOSE) {
System.out.println("TEST: got termEnum=" + termEnum);
}
int ord = 0;
while(true) {
final Term term = termEnum.term();
if (term == null || !"body".equals(term.field())) {
break;
}
// No ord in 3.x:
/*
if (ord == 0) {
try {
termsEnum.ord();
} catch (UnsupportedOperationException uoe) {
if (VERBOSE) {
System.out.println("TEST: codec doesn't support ord; FST stores docFreq");
}
storeOrd = false;
}
}
*/
final int output;
if (storeOrd) {
output = ord;
} else {
output = termEnum.docFreq();
}
//System.out.println("ADD: " + term.text() + " ch[0]=" + (term.text().length() == 0 ? -1 : term.text().charAt(0)));
builder.add(toIntsRef(term.text()), outputs.get(output));
ord++;
if (ord % 100000 == 0 && LuceneTestCase.TEST_NIGHTLY) {
System.out.println(ord + " terms...");
}
termEnum.next();
}
final FST<Long> fst = builder.finish();
if (VERBOSE) {
System.out.println("FST: " + docCount + " docs; " + ord + " terms; " + fst.getNodeCount() + " nodes; " + fst.getArcCount() + " arcs;" + " " + fst.sizeInBytes() + " bytes");
}
if (ord > 0) {
// Now confirm BytesRefFSTEnum and TermEnum act the
// same:
final IntsRefFSTEnum<Long> fstEnum = new IntsRefFSTEnum<Long>(fst);
int num = atLeast(1000);
for(int iter=0;iter<num;iter++) {
final String randomTerm = getRandomString();
if (VERBOSE) {
System.out.println("TEST: seek " + randomTerm + " ch[0]=" + (randomTerm.length() == 0 ? -1 : randomTerm.charAt(0)));
}
termEnum = r.terms(new Term("body", randomTerm));
final IntsRefFSTEnum.InputOutput fstSeekResult = fstEnum.seekCeil(toIntsRef(randomTerm));
if (termEnum.term() == null || !"body".equals(termEnum.term().field())) {
assertNull("got " + (fstSeekResult == null ? "null" : toString(fstSeekResult.input) + " but expected null"), fstSeekResult);
} else {
assertSame(termEnum, fstEnum, storeOrd);
for(int nextIter=0;nextIter<10;nextIter++) {
if (VERBOSE) {
System.out.println("TEST: next");
//if (storeOrd) {
//System.out.println(" ord=" + termEnum.ord());
//}
}
termEnum.next();
if (termEnum.term() != null && "body".equals(termEnum.term().field())) {
if (VERBOSE) {
System.out.println(" term=" + termEnum.term());
}
assertNotNull(fstEnum.next());
assertSame(termEnum, fstEnum, storeOrd);
} else {
if (VERBOSE) {