@Test public void testSingleDisjoint() 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}), }; IterablePosting joined = new ANDIterablePosting(ips, new Pointer[]{new SimpleBitIndexPointer(0, (byte) 0, 1),new SimpleBitIndexPointer(0,(byte) 0, 1)}); assertEquals(IterablePosting.EOL, joined.next()); joined.close(); }
@Test public void testSingleOverlap() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{1}, new int[]{1}, new int[]{3}), new ArrayOfBasicIterablePosting(new int[]{1}, new int[]{2}, new int[]{4}), }; IterablePosting joined = new ANDIterablePosting(ips, new Pointer[]{new SimpleBitIndexPointer(0, (byte) 0, 1),new SimpleBitIndexPointer(0,(byte) 0, 1)}); assertEquals(1, joined.next()); assertEquals(IterablePosting.EOL, joined.next()); joined.close(); }
@Test public void testTwoOverlap() throws Exception { IterablePosting[] ips = new IterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{3}), new ArrayOfBasicIterablePosting(new int[]{1,2}, new int[]{2,1}, new int[]{4}), }; IterablePosting joined = new ANDIterablePosting(ips, new Pointer[]{new SimpleBitIndexPointer(0, (byte) 0, 2),new SimpleBitIndexPointer(0,(byte) 0, 2)}); assertEquals(1, joined.next()); assertEquals(IterablePosting.EOL, joined.next()); joined.close(); }
@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)); }
ip = new ArrayOfBasicIterablePosting(ids, tf, null);
@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 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 testTwoOverlapSkip() throws Exception { ArrayOfBasicIterablePosting[] ips = new ArrayOfBasicIterablePosting[]{ new ArrayOfBasicIterablePosting(new int[]{0,1}, new int[]{1,1}, new int[]{3}), new ArrayOfBasicIterablePosting(new int[]{1,2}, new int[]{2,1}, new int[]{4}), }; IterablePosting joined; joined = new ANDIterablePosting(ips, new Pointer[]{new SimpleBitIndexPointer(0, (byte) 0, 2),new SimpleBitIndexPointer(0,(byte) 0, 2)}); assertEquals(1, joined.next(1)); assertEquals(IterablePosting.EOL, joined.next()); joined.close(); ips[0].reset(); ips[1].reset(); joined = new ANDIterablePosting(ips, new Pointer[]{new SimpleBitIndexPointer(0, (byte) 0, 2),new SimpleBitIndexPointer(0,(byte) 0, 2)}); assertEquals(1, joined.next(0)); assertEquals(IterablePosting.EOL, joined.next()); joined.close(); } }
@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()); }
@SuppressWarnings("unchecked") @Test public void testSimple() throws IOException { Index index = Index.createNewIndex(ApplicationSetup.TERRIER_INDEX_PATH, ApplicationSetup.TERRIER_INDEX_PREFIX); CompressionConfiguration cc = getConfig("inverted", new String[0], 0,0); AbstractPostingOutputStream pos = cc.getPostingOutputStream(((IndexOnDisk)index).getPath() + "/" + ((IndexOnDisk)index).getPrefix() + ".inverted" + cc.getStructureFileExtension()); Pointer p = pos.writePostings(new ArrayOfBasicIterablePosting(new int[]{0, 1}, new int[]{1,2})); pos.close(); cc.writeIndexProperties(index, "lexicon-entry-inputstream"); index.flush(); assertTrue(index.hasIndexStructure("inverted")); PostingIndex<Pointer> inv = (PostingIndex<Pointer>) index.getIndexStructure("inverted"); IterablePosting ip = inv.getPostings(p); assertNotNull(ip); assertEquals(0, ip.next()); assertEquals(1, ip.getFrequency()); assertEquals(1, ip.next()); assertEquals(2, ip.getFrequency()); index.close(); IndexUtil.deleteIndex(ApplicationSetup.TERRIER_INDEX_PATH, ApplicationSetup.TERRIER_INDEX_PREFIX); } }