{return;}
final int wordsCount = words[TEXT_NODES].size() +
words[ATTRIBUTE_NODES].size() + words[BY_QNAME].size();
if (wordsCount == 0)
{return;}
final ProgressIndicator progress = new ProgressIndicator(wordsCount, 100);
final int collectionId = this.doc.getCollection().getId();
int count = 0;
for (byte currentSection = 0; currentSection <= QNAME_SECTION; currentSection++) {
//Not very necessary, but anyway...
switch (currentSection) {
case TEXT_SECTION :
case ATTRIBUTE_SECTION :
case QNAME_SECTION :
break;
default :
throw new IllegalArgumentException("Invalid section type in '" +
dbTokens.getFile().getName() + "' (inverted index)");
}
for (final Iterator i = words[currentSection].entrySet().iterator(); i.hasNext(); count++) {
final Map.Entry entry = (Map.Entry) i.next();
final Object token = entry.getKey();
final OccurrenceList occurences = (OccurrenceList) entry.getValue();
if (occurences == null)
{continue;} // may happen if the index is in an invalid state due to earlier errors
//Don't forget this one
occurences.sort();
os.clear();
os.writeInt(this.doc.getDocId());
os.writeByte(currentSection);
os.writeInt(occurences.getTermCount());
//Mark position
final int lenOffset = os.position();
//Dummy value : actual one will be written below
os.writeFixedInt(0);
NodeId previous = null;
for (int m = 0; m < occurences.getSize(); ) {
try {
previous = occurences.getNode(m).write(previous, os);
} catch (final IOException e) {
LOG.error("IOException while writing fulltext index: " + e.getMessage(), e);
//TODO : throw exception ? -pb
}
int freq = occurences.getOccurrences(m);
os.writeInt(freq);
for (int n = 0; n < freq; n++) {
os.writeInt(occurences.getOffset(m + n));
}
m += freq;
}
//Write (variable) length of node IDs + frequency + offsets
os.writeFixedInt(lenOffset, os.position() - lenOffset - LENGTH_NODE_IDS_FREQ_OFFSETS);
flushWord(currentSection, collectionId, token, os.data());
progress.setValue(count);
if (progress.changed()) {
setChanged();
notifyObservers(progress);
}
}
//TOUNDERSTAND : is this a flush ?
//If so, the ProgressIndicator should be reinitialized -pb
if (wordsCount > 100) {
progress.finish();
setChanged();
notifyObservers(progress);
}
words[currentSection].clear();
}