/** * Writes the contents of the postings in memory to disk. * @param writer The RunWriter to write the postings to. * @param postings the Map<String,Posting> containing the posting lists in memory. * @throws IOException if an I/O error occurs. */ private void writeToWriter(RunWriter writer, Map<String, Posting> _postings) throws IOException{ if (_postings.size() != 0){ writer.beginWrite(maxSize, _postings.size()); for( Entry<String,Posting> entry : _postings.entrySet()) { writer.writeTerm(entry.getKey(), entry.getValue()); } } writer.finishWrite(); } }
/** Triggers the writing of the postings in memory to the specified * RunWriter. If the RunWriter requires that terms are written in order, * then this will happen. * @param runWriter * @throws IOException */ public void finish(RunWriter runWriter) throws IOException { logger.debug("Writing run "+runWriter.toString()); //only sort the postings if required by the RunWriter writeToWriter(runWriter, runWriter.writeSorted() ? new TreeMap<String, Posting>(postings) : postings); logger.debug(" done"); }
/** * Triggers the writing of the postings in memory to disk. * Uses the default RunWriter, writing to the specified files. * @param file name of the file to write the postings. * @throws IOException if an I/O error occurs. */ public void finish(String[] file) throws IOException{ finish(new RunWriter(file[0], file[1])); }