/** * Adds an occurrence of a term in a document to the posting in memory. * @param term String representing the term. * @param doc int containing the document identifier. * @param frequency int containing the frequency of the term in the document. * @param fieldFrequencies int[] contains the frequencies of the term in each field * @throws IOException if an I/O error occurs. */ public void add(String term, int doc, int frequency, int[] fieldFrequencies) throws IOException{ FieldPosting post; if((post = (FieldPosting) postings.get(term)) != null) { valueBytes += post.insert(doc, frequency, fieldFrequencies); int tf = post.getTF(); // Update the max size if(maxSize < tf) maxSize = tf; } else{ post = new FieldPosting(); valueBytes += post.writeFirstDoc(doc, frequency, fieldFrequencies); postings.put(term,post); keyBytes += (long)(12 + 2*term.length()); } numPointers++; } }
((FieldPosting)directPostings[writerOffset]).insert(termId, ip.getFrequency(), fieldFs); ((FieldPosting)directPostings[writerOffset]).writeFirstDoc(termId, ip.getFrequency(), fieldFs);
/** get an array of posting object of the specified size. These will be used to hold * the postings for a range of documents */ protected Posting[] getPostings(final int count) { Posting[] rtr = new Posting[count]; if (saveTagInformation) { for(int i=0;i<count;i++) rtr[i] = new FieldPosting(); } else { for(int i=0;i<count;i++) rtr[i] = new Posting(); } return rtr; }
/** * Writes the first document in the posting list. * @param doc the document identifier. * @param frequency the frequency of the term in the document. * @param fieldFrequencies tf in each field for the term in the document. * @throws IOException if an I/O error ocurrs. */ public int writeFirstDoc(final int doc, final int frequency, final int[] fieldFrequencies) throws IOException{ writeFirstDoc(doc, frequency); for(int field_f : fieldFrequencies) { //System.err.println("f" + "=" + field_f); docIds.writeUnary(field_f+1); } return docIds.getSize(); }
/** * 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 fieldFrequencies the frequency of the term in the document. * @return the number of bytes consumed in the buffer * @throws IOException if and I/O error occurs. */ public int insert(final int doc, final int freq, final int[] fieldFrequencies) throws IOException{ final int bytes = docIds.getSize(); insert(doc, freq); for(int field_f : fieldFrequencies) { //System.err.println("f" + "=" + field_f); docIds.writeUnary(field_f+1); } return docIds.getSize() - bytes; } }