@Override public int getFrequency() { return posting.getFrequency(); }
/** {@inheritDoc} */ public int getFrequency() { return children[currentChild].getFrequency(); }
String getContentsNoBlocksFreq(IterablePosting ip, Lexicon<String> lex) throws Exception { StringBuilder rtr = new StringBuilder(); int termid; while( (termid = ip.next()) != IterablePosting.END_OF_LIST){ String term = lex.getLexiconEntry(termid).getKey(); rtr.append(term); rtr.append(':'); rtr.append(ip.getFrequency()); rtr.append(' '); } return rtr.toString(); }
String getContentsNoBlocksFreq(IterablePosting ip, Lexicon<String> lex) throws Exception { StringBuilder rtr = new StringBuilder(); int termid; while( (termid = ip.next()) != IterablePosting.END_OF_LIST){ String term = lex.getLexiconEntry(termid).getKey(); rtr.append(term); rtr.append(':'); rtr.append(ip.getFrequency()); rtr.append(' '); } return rtr.toString(); }
String getContentsNoBlocks(IterablePosting ip, Lexicon<String> lex, boolean expandFreq) throws Exception { StringBuilder rtr = new StringBuilder(); int termid; while( (termid = ip.next()) != IterablePosting.END_OF_LIST){ String term = lex.getLexiconEntry(termid).getKey(); for(int i=0;i< (expandFreq ? ip.getFrequency() : 1); i++) { rtr.append(term); rtr.append(' '); } } return rtr.toString(); }
String getContentsNoBlocks(IterablePosting ip, Lexicon<String> lex, boolean expandFreq) throws Exception { StringBuilder rtr = new StringBuilder(); int termid; while( (termid = ip.next()) != IterablePosting.END_OF_LIST){ String term = lex.getLexiconEntry(termid).getKey(); for(int i=0;i< (expandFreq ? ip.getFrequency() : 1); i++) { rtr.append(term); rtr.append(' '); } } return rtr.toString(); }
/** Get an array of all the ids and frequencies in a given IterablePosting stream, * where the length of the stream is unknown */ public static int[][] getAllPostings(final IterablePosting ip, final int numPointers) throws IOException { final int[][] rtr = new int[2][numPointers]; for(int i=0;ip.next() != IterablePosting.EOL;i++) { rtr[0][i] = ip.getId(); rtr[1][i] = ip.getFrequency(); } return rtr; }
/** Get an array of all the ids and frequencies in a given IterablePosting stream, * where the length of the stream is unknown */ public static int[][] getAllPostings(final IterablePosting ip, final int numPointers) throws IOException { final int[][] rtr = new int[2][numPointers]; for(int i=0;ip.next() != IterablePosting.EOL;i++) { rtr[0][i] = ip.getId(); rtr[1][i] = ip.getFrequency(); } return rtr; }
/** * Adds the feedback document from the index given a docid */ public void insertDocument(int docid, int rank, double score) throws IOException { totalDocumentLength += documentIndex.getDocumentLength(docid); final IterablePosting ip = directIndex.getPostings((BitIndexPointer)documentIndex.getDocumentEntry(docid)); if (ip == null) { logger.warn("document id "+docid+" not found"); return; } while(ip.next() != IterablePosting.EOL) { this.insertTerm(ip.getId(), ip.getFrequency()); } feedbackDocumentCount++; }
/** Get an array of all the ids in a given IterablePosting stream, * where the length of the stream is known */ public static int[][] getAllPostings(final IterablePosting ip) throws IOException { if (ip == null) return null; final TIntArrayList ids = new TIntArrayList(); final TIntArrayList tfs = new TIntArrayList(); while(ip.next() != IterablePosting.EOL) { ids.add(ip.getId()); tfs.add(ip.getFrequency()); } return new int[][]{ids.toNativeArray(), tfs.toNativeArray()}; }
/** Get an array of all the ids in a given IterablePosting stream, * where the length of the stream is known */ public static int[][] getAllPostings(final IterablePosting ip) throws IOException { if (ip == null) return null; final TIntArrayList ids = new TIntArrayList(); final TIntArrayList tfs = new TIntArrayList(); while(ip.next() != IterablePosting.EOL) { ids.add(ip.getId()); tfs.add(ip.getFrequency()); } return new int[][]{ids.toNativeArray(), tfs.toNativeArray()}; }
@Test public void testPrefix() throws Exception { Index index = IndexTestUtils.makeIndex(new String[]{"doc1"}, new String[]{"aa ab cc"}); Pair<EntryStatistics, IterablePosting> pair = new PrefixTermOp("a").getPostingIterator(index); EntryStatistics es = pair.getLeft(); assertEquals(2, es.getFrequency()); IterablePosting ip = pair.getRight(); assertEquals(0, ip.next()); assertEquals(2, ip.getFrequency()); assertEquals(IterablePosting.EOL, ip.next()); }
@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 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()); }
public static void comparePostings(List<Posting> inputPostings, IterablePosting outputPostings) throws Exception { for(Posting p : inputPostings) { assertEquals(p.getId(), outputPostings.next()); assertEquals(p.getId(), outputPostings.getId()); assertEquals(p.getFrequency(), outputPostings.getFrequency()); } assertTrue(outputPostings.next() == IterablePosting.EOL); assertTrue(outputPostings.getId() == IterablePosting.EOL); //TR-519 }
@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)); }
@SuppressWarnings("unchecked") @Test public void testOnePhraseOneDocument() throws Exception { ApplicationSetup.setProperty("termpipelines", ""); Index index = IndexTestUtils.makeIndexBlocks( new String[]{"doc1"}, new String[]{"dramatis personae"}); IterablePosting ip = PhraseIterablePosting.createPhrasePostingList( new String[]{"dramatis", "personae"}, index.getLexicon(), (PostingIndex<Pointer>) index.getInvertedIndex(), true); assertNotNull(ip); assertEquals(0, ip.next()); assertEquals(1, ip.getFrequency()); assertEquals(IterablePosting.EOL, ip.next()); }
public static void compareBlockPostings(List<Posting> inputPostings, IterablePosting outputPostings) throws Exception { for(Posting p : inputPostings) { assertEquals(p.getId(), outputPostings.next()); assertEquals(p.getId(), outputPostings.getId()); assertEquals(p.getFrequency(), outputPostings.getFrequency()); assertArrayEquals(((BlockPosting) p).getPositions(), ((BlockPosting) p).getPositions()); } assertTrue(outputPostings.next() == IterablePosting.EOL); assertTrue(outputPostings.getId() == IterablePosting.EOL); //TR-519 }
public static void compareFieldPostings(List<Posting> inputPostings, IterablePosting outputPostings) throws Exception { for(Posting p : inputPostings) { assertEquals(p.getId(), outputPostings.next()); assertEquals(p.getId(), outputPostings.getId()); assertEquals(p.getFrequency(), outputPostings.getFrequency()); assertArrayEquals(((FieldPosting) p).getFieldFrequencies(), ((FieldPosting) p).getFieldFrequencies()); } assertTrue(outputPostings.next() == IterablePosting.EOL); assertTrue(outputPostings.getId() == IterablePosting.EOL); //TR-519 }
public static void compareBlockFieldPostings(List<Posting> inputPostings, IterablePosting outputPostings) throws Exception { for(Posting p : inputPostings) { assertEquals(p.getId(), outputPostings.next()); assertEquals(p.getId(), outputPostings.getId()); assertEquals(p.getFrequency(), outputPostings.getFrequency()); assertArrayEquals(((FieldPosting) p).getFieldFrequencies(), ((FieldPosting) p).getFieldFrequencies()); assertArrayEquals(((BlockPosting) p).getPositions(), ((BlockPosting) p).getPositions()); } assertTrue(outputPostings.next() == IterablePosting.EOL); assertTrue(outputPostings.getId() == IterablePosting.EOL); //TR-519 }