Search in sources :

Example 6 with Filter

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());
}
Also used : DuplicateFilter(org.apache.lucene.sandbox.queries.DuplicateFilter) DuplicateFilter(org.apache.lucene.sandbox.queries.DuplicateFilter) Filter(org.apache.lucene.search.Filter) Test(org.junit.Test)

Example 7 with Filter

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);
}
Also used : Filter(org.apache.lucene.search.Filter) Bits(org.apache.lucene.util.Bits) Test(org.junit.Test)

Example 8 with Filter

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);
}
Also used : Filter(org.apache.lucene.search.Filter) Term(org.apache.lucene.index.Term) Test(org.junit.Test)

Example 9 with Filter

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;
    }
}
Also used : BooleanFilter(org.apache.lucene.search.BooleanFilter) Filter(org.apache.lucene.search.Filter) BooleanFilter(org.apache.lucene.search.BooleanFilter) FilterClause(org.apache.lucene.search.FilterClause) Nullable(javax.annotation.Nullable)

Aggregations

Filter (org.apache.lucene.search.Filter)9 Test (org.junit.Test)6 Nullable (javax.annotation.Nullable)2 Term (org.apache.lucene.index.Term)2 DuplicateFilter (org.apache.lucene.sandbox.queries.DuplicateFilter)2 BooleanFilter (org.apache.lucene.search.BooleanFilter)2 FilterClause (org.apache.lucene.search.FilterClause)2 IOException (java.io.IOException)1 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)1 ParseException (org.apache.lucene.queryParser.ParseException)1 QueryParser (org.apache.lucene.queryParser.QueryParser)1 BooleanQuery (org.apache.lucene.search.BooleanQuery)1 DocIdSet (org.apache.lucene.search.DocIdSet)1 DuplicateFilter (org.apache.lucene.search.DuplicateFilter)1 Hits (org.apache.lucene.search.Hits)1 IndexSearcher (org.apache.lucene.search.IndexSearcher)1 Query (org.apache.lucene.search.Query)1 RangeFilter (org.apache.lucene.search.RangeFilter)1 Sort (org.apache.lucene.search.Sort)1 TermQuery (org.apache.lucene.search.TermQuery)1