/** {@inheritDoc} */ public int getDocumentLength() { return children[currentChild].getDocumentLength(); }
@Override public int getDocumentLength() { return ips[0].getDocumentLength(); }
@Override public int getDocumentLength() { return posting.getDocumentLength(); }
@Override public int getDocumentLength() { return ips[0].getDocumentLength(); }
@Test public void doTest() throws Exception { ArrayOfFieldIterablePosting fips = getFips(); IterablePosting ip1 = new FieldOnlyIterablePosting(fips, 0); assertEquals(1, ip1.next()); assertEquals(1, ip1.getFrequency()); assertEquals(2, ip1.getDocumentLength()); assertEquals(2, ip1.next()); assertEquals(8, ip1.getFrequency()); assertEquals(3, ip1.getDocumentLength()); assertEquals(IterablePosting.EOL, ip1.next()); assertEquals(IterablePosting.EOL, ip1.getId()); ip1.close(); }
@Test public void testTwoWithOverlap() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{5,6}), new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{2,2}, new int[]{5,6}), }; IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next()); assertEquals(0, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(5, joined.getDocumentLength()); assertEquals(1, joined.next()); assertEquals(1, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(6, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testTwoWithOverlapSkip() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{5,6}), new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{2,2}, new int[]{5,6}), }; IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next(0)); assertEquals(0, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(5, joined.getDocumentLength()); assertEquals(1, joined.next(1)); assertEquals(1, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(6, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testManySomeOverlap() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{4,5}), new ArrayOfBasicIterablePosting(new int[]{1,2}, new int[]{2,2}, new int[]{5,6}), }; IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next()); assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(1, joined.next()); assertEquals(1, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(5, joined.getDocumentLength()); assertEquals(2, joined.next()); assertEquals(2, joined.getId()); assertEquals(2, joined.getFrequency()); assertEquals(6, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testManySomeOverlapSkip() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{4,5}), new ArrayOfBasicIterablePosting(new int[]{1,2}, new int[]{2,2}, new int[]{5,6}), }; IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next(0)); assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(1, joined.next(1)); assertEquals(1, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(5, joined.getDocumentLength()); assertEquals(2, joined.next(2)); assertEquals(2, joined.getId()); assertEquals(2, joined.getFrequency()); assertEquals(6, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testSingleNoOverlapSkip() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0}, new int[]{1}, new int[]{3}), new ArrayOfBasicIterablePosting(new int[]{1}, new int[]{2}, new int[]{4}), }; //for(IterablePosting ip : ips) // ip.next(); IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next(0)); assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(3, joined.getDocumentLength()); assertEquals(1, joined.next(1)); assertEquals(1, joined.getId()); assertEquals(2, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testManySomeOverlapSkipOver() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{4,5}), new ArrayOfBasicIterablePosting(new int[]{1,2}, new int[]{2,2}, new int[]{5,6}), }; IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next(0)); assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(2, joined.next(2)); assertEquals(2, joined.getId()); assertEquals(2, joined.getFrequency()); assertEquals(6, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testSingleNoOverlap() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0}, new int[]{1}, new int[]{3}), new ArrayOfBasicIterablePosting(new int[]{1}, new int[]{2}, new int[]{4}), }; //for(IterablePosting ip : ips) // ip.next(); IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next()); assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(3, joined.getDocumentLength()); assertEquals(1, joined.next()); assertEquals(1, joined.getId()); assertEquals(2, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next()); }
@Test public void testManySomeOverlapSkipPast() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{4,5}), new ArrayOfBasicIterablePosting(new int[]{1,2}, new int[]{2,2}, new int[]{5,6}), }; IterablePosting joined = joinPostings(ips); assertEquals(0, joined.next(0)); assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(IterablePosting.EOL, joined.next(3)); }
while(ip.next() != IterablePosting.EOL) if (D_DEBUG) System.err.println("termid" +ip.getId() + " f=" + ip.getFrequency()+" dlength="+ip.getDocumentLength()+" docid="+docid); termIds.add(ip.getId()); tokens += ip.getFrequency(); doclen += ip.getFrequency(); pointers++; docpointers++; assertEquals("Document length for docid = "+docid+" on termid "+ip.getId()+" is wrong",documentLengths[docid], ip.getDocumentLength()); if (numberOfTerms > 0) assertTrue("Got too big a termid ("+ip.getId()+") from direct index input stream, numTerms=" + numberOfTerms, ip.getId() < maxTermId); assertEquals(DOCUMENT_LENGTHS[docid2], ip.getDocumentLength()); if (numberOfTerms > 0) assertTrue("Got too big a termid ("+ip.getId()+") from direct index input stream, numTerms=" + numberOfTerms, ip.getId() < maxTermId);
assertEquals(documentLengths[ip.getId()], ip.getDocumentLength()); count++; observedDocLengths[ip.getId()]+= ip.getFrequency();
@SuppressWarnings("unchecked") public static void checkContents(Index index, String term, int freq, int[] docids, int[] freqs, int[] docLens) throws Exception { Lexicon<String> lexicon = index.getLexicon(); assertNotNull(lexicon); LexiconEntry le = lexicon.getLexiconEntry(term); assertNotNull(le); assertEquals(freq, le.getFrequency()); assertEquals(docids.length, le.getDocumentFrequency()); PostingIndex<Pointer> inverted = (PostingIndex<Pointer>) index.getInvertedIndex(); assertNotNull(inverted); IterablePosting ip = inverted.getPostings(le); assertNotNull(ip); for(int i=0;i<docids.length;i++) { assertEquals(docids[i], ip.next()); assertEquals(docids[i], ip.getId()); assertEquals(freqs[i], ip.getFrequency()); assertEquals(docLens[i],ip.getDocumentLength()); } assertEquals(IterablePosting.EOL, ip.next()); }
assertEquals(0, joined.getId()); assertEquals(1, joined.getFrequency()); assertEquals(4, joined.getDocumentLength()); assertEquals(0, fp.getFieldFrequencies()[0]); assertEquals(1, fp.getFieldFrequencies()[1]); assertEquals(1, joined.getId()); assertEquals(3, joined.getFrequency()); assertEquals(5, joined.getDocumentLength()); assertEquals(3, fp.getFieldFrequencies()[0]); assertEquals(0, fp.getFieldFrequencies()[1]); assertEquals(2, joined.getId()); assertEquals(2, joined.getFrequency()); assertEquals(6, joined.getDocumentLength()); assertEquals(1, fp.getFieldFrequencies()[0]); assertEquals(1, fp.getFieldFrequencies()[1]);
assertEquals(invIds[t][d], ip.getId()); assertEquals(invTfs[t][d], ip.getFrequency()); assertEquals(doclens[invIds[t][d]], ip.getDocumentLength()); if (fieldsExpected) { assertEquals(2, invFfs[t][d].length); assertEquals(invIds[t][d], ip.getId()); assertEquals(invTfs[t][d], ip.getFrequency()); assertEquals(doclens[invIds[t][d]], ip.getDocumentLength()); if (fieldsExpected) { assertEquals(2, invFfs[t][d].length); assertTrue("term " + term +" not expected in document " + d, dirTfs[d].containsKey(term)); assertEquals(dirTfs[d].get(term), ip.getFrequency()); assertEquals(doclens[d], ip.getDocumentLength()); assertTrue(dirTfs[d].containsKey(term)); assertEquals(dirTfs[d].get(term), ip.getFrequency()); assertEquals("document length was wrong for docid " + d, doclens[d], ip.getDocumentLength());
assertEquals(post1.getId(), post2.getId()); assertEquals(post1.getFrequency(), post2.getFrequency()); assertEquals(post1.getDocumentLength(), post2.getDocumentLength());