LuceneIterable implements Iterable<Vector> { @Override public Iterator<Vector> iterator() { return new LuceneIterator(indexReader, idField, field, terminfo, weight, normPower, maxPercentErrorDocs); } LuceneIterable(IndexReader reader, String idField, String field, TermInfo terminfo, Weight weight);  LuceneIterable(IndexReader indexReader, String idField, String field, TermInfo terminfo, Weight weight,
      double normPower);  LuceneIterable(IndexReader indexReader,
                        String idField,
                        String field,
                        TermInfo terminfo,
                        Weight weight,
                        double normPower,
                        double maxPercentErrorDocs); @Override Iterator<Vector> iterator(); static final double NO_NORMALIZING; }
@Test(expected = IllegalStateException.class) public void testIterableNoTermVectors() throws IOException { RAMDirectory directory = createTestIndex(TYPE_NO_TERM_VECTORS); IndexReader reader = DirectoryReader.open(directory); Weight weight = new TFIDF(); TermInfo termInfo = new CachedTermInfo(reader, "content", 1, 100); LuceneIterable iterable = new LuceneIterable(reader, "id", "content", termInfo,weight); Iterator<Vector> iterator = iterable.iterator(); Iterators.advance(iterator, 1); }
@Test public void testIterableSomeNoiseTermVectors() throws IOException { RAMDirectory directory = createTestIndex(TYPE_TERM_VECTORS, new RAMDirectory(), 0); createTestIndex(TYPE_NO_TERM_VECTORS, directory, 5); IndexReader reader = DirectoryReader.open(directory); Weight weight = new TFIDF(); TermInfo termInfo = new CachedTermInfo(reader, "content", 1, 100); boolean exceptionThrown; LuceneIterable iterable = new LuceneIterable(reader, "id", "content", termInfo, weight); try { Iterables.skip(iterable, Iterables.size(iterable)); exceptionThrown = false; } catch(IllegalStateException ise) { exceptionThrown = true; } assertTrue(exceptionThrown); iterable = new LuceneIterable(reader, "id", "content", termInfo,weight, -1, 1.0); try { Iterables.skip(iterable, Iterables.size(iterable)); exceptionThrown = false; } catch(IllegalStateException ise) { exceptionThrown = true; } assertFalse(exceptionThrown); iterable = new LuceneIterable(reader, "id", "content", termInfo,weight, -1, 0.5); Iterator<Vector> iterator = iterable.iterator(); Iterators.advance(iterator, 5); try { Iterators.advance(iterator, Iterators.size(iterator)); exceptionThrown = false; } catch(IllegalStateException ise) { exceptionThrown = true; } assertTrue(exceptionThrown); }
@Test(expected = IllegalStateException.class) public void testIterableNoTermVectors() throws IOException { RAMDirectory directory = createTestIndex(Field.TermVector.NO); IndexReader reader = DirectoryReader.open(directory); Weight weight = new TFIDF(); TermInfo termInfo = new CachedTermInfo(reader, "content", 1, 100); LuceneIterable iterable = new LuceneIterable(reader, "id", "content", termInfo,weight); Iterator<Vector> iterator = iterable.iterator(); iterator.hasNext(); iterator.next(); }
@Test public void testIterableSomeNoiseTermVectors() throws IOException { RAMDirectory directory = createTestIndex(Field.TermVector.YES, new RAMDirectory(), true, 0); createTestIndex(Field.TermVector.NO, directory, false, 5); IndexReader reader = DirectoryReader.open(directory); Weight weight = new TFIDF(); TermInfo termInfo = new CachedTermInfo(reader, "content", 1, 100); boolean exceptionThrown; LuceneIterable iterable = new LuceneIterable(reader, "id", "content", termInfo,weight); try { for (Object a : iterable) { } exceptionThrown = false; } catch(IllegalStateException ise) { exceptionThrown = true; } assertTrue(exceptionThrown); iterable = new LuceneIterable(reader, "id", "content", termInfo,weight, -1, 1.0); try { for (Object a : iterable) { } exceptionThrown = false; } catch(IllegalStateException ise) { exceptionThrown = true; } assertFalse(exceptionThrown); iterable = new LuceneIterable(reader, "id", "content", termInfo,weight, -1, 0.5); Iterator<Vector> iterator = iterable.iterator(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); iterator.next(); try { while (iterator.hasNext()) { iterator.next(); } exceptionThrown = false; } catch(IllegalStateException ise) { exceptionThrown = true; } assertTrue(exceptionThrown); }