PredicateSearch { public Stream<Hit> stream() { if (nPostingLists == 0) { return Stream.empty(); } return StreamSupport.stream(new PredicateSpliterator(), false); } PredicateSearch(
            List<PostingList> postingLists, byte[] nPostingListsForDocument,
            byte[] minFeatureIndex, short[] intervalEnds, int  highestIntervalEnd); Stream<Hit> stream();  }
@Test public void requireThatNoStreamsReturnNoResults() { PredicateSearch search = new PredicateSearch(new ArrayList<>(), new byte[0], new byte[0], new short[0], 1); assertEquals(0, search.stream().count()); }
@Test public void requireThatSingleStreamFiltersOnConstructedCompleteIntervals() { PredicateSearch search = createPredicateSearch( new byte[]{1, 1, 1}, postingList( SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000100ff), entry(1, 0x00010001, 0x000200ff), entry(2, 0x00010042))); assertEquals(Arrays.asList(new Hit(0), new Hit(1)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatMinFeatureIsUsedToPruneResults() { PredicateSearch search = createPredicateSearch( new byte[]{3, 1}, postingList( SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000100ff), entry(1, 0x000100ff))); assertEquals(Arrays.asList(new Hit(1)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatAHighKCanYieldResults() { PredicateSearch search = createPredicateSearch( new byte[]{2}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000200ff))); assertEquals(Arrays.asList(new Hit(0)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatPostingListsAreSortedAfterAdvancing() { PredicateSearch search = createPredicateSearch( new byte[] {2, 1, 1, 1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000100ff), entry(3, 0x000100ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(1, 0x000100ff), entry(2, 0x000100ff))); assertEquals(Arrays.asList(new Hit(1), new Hit(2), new Hit(3)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatEmptyPostingListsWork() { PredicateSearch search = createPredicateSearch( new byte[0], postingList(SubqueryBitmap.ALL_SUBQUERIES)); assertEquals(Arrays.asList().toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatShorterPostingListEndingIsOk() { PredicateSearch search = createPredicateSearch( new byte[]{1, 1, 1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000100ff), entry(1, 0x000100ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(2, 0x000100ff))); assertEquals(Arrays.asList(new Hit(0), new Hit(1), new Hit(2)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatSortingWorksForManyPostingLists() { PredicateSearch search = createPredicateSearch( new byte[]{1, 5, 2, 2}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000100ff), entry(1, 0x000100ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(1, 0x000100ff), entry(2, 0x000100ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(1, 0x000100ff), entry(3, 0x000100ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(1, 0x000100ff), entry(2, 0x000100ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(1, 0x000100ff), entry(3, 0x000100ff))); assertEquals( Arrays.asList(new Hit(0), new Hit(1), new Hit(2), new Hit(3)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatInsufficientIntervalCoveragePreventsMatch() { PredicateSearch search = createPredicateSearch( new byte[]{1, 1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001), entry(1, 0x000200ff))); assertEquals(Arrays.asList().toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatIntervalsAreSorted() { PredicateSearch search = createPredicateSearch( new byte[]{1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x000300ff)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00020002))); assertEquals(Arrays.asList(new Hit(0)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatThereCanBeManyIntervals() { PredicateSearch search = createPredicateSearch( new byte[]{1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001, 0x00020002, 0x00030003, 0x000100ff, 0x00040004, 0x00050005, 0x00060006))); assertEquals(Arrays.asList(new Hit(0)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatNotIsSupported_NoMatch() { PredicateSearch search = createPredicateSearch( new byte[]{1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010000, 0x00ff0001))); assertEquals(Arrays.asList().toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatNotIsSupported_Match() { PredicateSearch search = createPredicateSearch( new byte[]{1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010000, 0x00ff0001))); assertEquals(Arrays.asList(new Hit(0)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatNotIsSupported_NoMatchBecauseOfPreviousTerm() { PredicateSearch search = createPredicateSearch( new byte[]{1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00020001, 0x00ff0001))); assertEquals(Arrays.asList().toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatIntervalSortingWorksAsUnsigned() { PredicateSearch search = createPredicateSearch( new byte[]{1}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00fe0001, 0x00ff00fe))); assertEquals(Arrays.asList(new Hit(0)).toString(), search.stream().collect(toList()).toString()); }
@Test public void requireThatMatchCanRequireMultiplePostingLists() { PredicateSearch search = createPredicateSearch( new byte[]{6}, postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010001)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x0002000b, 0x00030003)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00040003)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00050004)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00010008, 0x00060006)), postingList(SubqueryBitmap.ALL_SUBQUERIES, entry(0, 0x00020002, 0x000700ff))); assertEquals(Arrays.asList(new Hit(0)).toString(), search.stream().collect(toList()).toString()); }