@Test public void testLongs() throws Exception { List<Integer> docs = Arrays.asList(1, 5, 7); LongOpenHashSet hTerms = new LongOpenHashSet(); List<Long> cTerms = new ArrayList<Long>(docs.size()); for (int i = 0; i < docs.size(); i++) { long term = docs.get(i).longValue(); hTerms.add(term); cTerms.add(term); } FieldDataTermsFilter hFilter = FieldDataTermsFilter.newLongs(getFieldData(lngMapper), hTerms); int size = reader.maxDoc(); FixedBitSet result = new FixedBitSet(size); result.clear(0, size); assertThat(result.cardinality(), equalTo(0)); result.or(hFilter.getDocIdSet(reader.getContext(), reader.getLiveDocs()).iterator()); assertThat(result.cardinality(), equalTo(docs.size())); for (int i = 0; i < reader.maxDoc(); i++) { assertThat(result.get(i), equalTo(docs.contains(i))); } // filter from mapper result.clear(0, size); assertThat(result.cardinality(), equalTo(0)); result.or( lngMapper .termsFilter(ifdService, cTerms, null) .getDocIdSet(reader.getContext(), reader.getLiveDocs()) .iterator()); assertThat(result.cardinality(), equalTo(docs.size())); for (int i = 0; i < reader.maxDoc(); i++) { assertThat(result.get(i), equalTo(docs.contains(i))); } hFilter = FieldDataTermsFilter.newLongs(getFieldData(dblMapper), hTerms); assertNull(hFilter.getDocIdSet(reader.getContext(), reader.getLiveDocs())); }
@Test public void testNoTerms() throws Exception { FieldDataTermsFilter hFilterBytes = FieldDataTermsFilter.newBytes(getFieldData(strMapper), new ObjectOpenHashSet<BytesRef>()); FieldDataTermsFilter hFilterLongs = FieldDataTermsFilter.newLongs(getFieldData(lngMapper), new LongOpenHashSet()); FieldDataTermsFilter hFilterDoubles = FieldDataTermsFilter.newDoubles(getFieldData(dblMapper), new DoubleOpenHashSet()); assertNull(hFilterBytes.getDocIdSet(reader.getContext(), reader.getLiveDocs())); assertNull(hFilterLongs.getDocIdSet(reader.getContext(), reader.getLiveDocs())); assertNull(hFilterDoubles.getDocIdSet(reader.getContext(), reader.getLiveDocs())); }