/** Inserts all the terms from a document posting * into the lexicon map * @param doc The postinglist for that document */ public void insert(DocumentPostingList doc) { doc.forEachTerm(new TObjectIntProcedure<String>() { public boolean execute(final String t, final int tf) { tfs.adjustOrPutValue(t, tf, tf); nts.adjustOrPutValue(t, 1 , 1); if (tf > maxtfs.get(t)) maxtfs.put(t, tf); return true; } }); }
public void write(final DataOutput out) throws IOException { WritableUtils.writeVInt(out, getNumberOfPointers()); try { this.forEachTerm(new TObjectIntProcedure<String>() { public boolean execute(String term, int freq) { try{ Text.writeString(out, term); WritableUtils.writeVInt(out, freq); } catch (IOException e) { throw new Error(e); } return true; } }); } catch (Error e) { throw (IOException)e.getCause(); } }