use of org.apache.lucene.search.Filter in project querydsl by querydsl.
the class LuceneQueryTest method list_with_filter.
@Test
public void list_with_filter() {
Filter filter = new DuplicateFilter("year");
assertEquals(4, query.fetch().size());
assertEquals(3, query.filter(filter).fetch().size());
}
use of org.apache.lucene.search.Filter in project greplin-lucene-utils by Cue.
the class FilterBitsProviderTest method testGetShouldHandleNullDocIdSetIterator.
@Test
public void testGetShouldHandleNullDocIdSetIterator() throws Exception {
Filter test = new TestFilter();
FilterBitsProvider testProvider = new FilterBitsProvider(test);
try {
Bits testBits = testProvider.get(this.reader);
} catch (NullPointerException npe) {
Assert.fail("NPE");
}
Assert.assertTrue(true);
}
use of org.apache.lucene.search.Filter in project greplin-lucene-utils by Cue.
the class FiltersTest method testNot.
@Test
public void testNot() throws Exception {
Filter dog = TermsFilter.from(new Term("f", "dog"));
assertDocIds(dog.getDocIdSet(this.reader), true, true);
assertDocIds(Filters.not(dog).getDocIdSet(this.reader), false, false);
Filter cat = TermsFilter.from(new Term("f", "cat"));
assertDocIds(cat.getDocIdSet(this.reader), true, false);
assertDocIds(Filters.not(cat).getDocIdSet(this.reader), false, true);
}
use of org.apache.lucene.search.Filter in project greplin-lucene-utils by Cue.
the class Filters method and.
/**
* Returns a filter that allows documents that match every constituent
* filter. For convenience, null values are accepted and ignored. If
* all values are null, null will be returned.
* @param filters the filters to combine
* @return the combined filter
*/
@Nullable
public static Filter and(final Iterable<Filter> filters) {
final BooleanFilter booleanFilter = new BooleanFilter();
Filter lastFilter = null;
int count = 0;
for (Filter filter : filters) {
if (filter != null) {
booleanFilter.add(new FilterClause(filter, BooleanClause.Occur.MUST));
count += 1;
lastFilter = filter;
}
}
if (count == 0) {
return null;
} else if (count == 1) {
return lastFilter;
} else {
return booleanFilter;
}
}
Aggregations