/** Add the specified to the term posting to the memory postings. * @param term The String form of the term * @param doc the document id of the doc * @param frequency the frequency of the specified term in the document * @param blocks the blockids at which this term occurs */ public void add(String term, int doc, int frequency, int[] blocks) throws IOException{ BlockPosting post; if((post =(BlockPosting) postings.get(term)) != null) { valueBytes += post.insert(doc, frequency, blocks); int tf = post.getTF(); // Update the max size if(maxSize < tf) maxSize = tf; } else{ post = new BlockPosting(); valueBytes += post.writeFirstDoc(doc, frequency, blocks); postings.put(term,post); keyBytes += (long)(12 + 2*term.length()); } numPointers++; } }
/** * Inserts a new document in the posting list. Document insertions must be done * in order. * @param doc the document identifier. * @param freq the frequency of the term in the document. * @param blockids the blockids for all the term * @return the updated term frequency. * @throws IOException if and I/O error occurs. */ public int insert(final int doc, final int freq, final int[] blockids) throws IOException{ final int c = insert(doc, freq); final int blockCount = blockids.length; docIds.writeUnary(blockCount+1); if (blockCount > 0) { docIds.writeGamma(blockids[0]+1); for (int i=1; i<blockCount; i++) { docIds.writeGamma(blockids[i] - blockids[i-1]); } } return c; }
((BlockPosting)directPostings[writerOffset]).insert(termId, ip.getFrequency(), blocks);