Search in sources :

Example 1 with IntersectionProvider

use of com.greplin.lucene.util.IntersectionProvider in project greplin-lucene-utils by Cue.

the class PhraseFilterTest method testIntersectionWithPredicate.

@Test
public void testIntersectionWithPredicate() throws Exception {
    IndexReader reader = createReaderWithSampleDocuments();
    IntersectionProvider predicate = new BitsProviderIntersectionProvider(new BitsProvider() {

        @Override
        public Bits get(IndexReader reader) throws IOException {
            return new Bits() {

                @Override
                public boolean get(int index) {
                    return index != 0;
                }

                @Override
                public int length() {
                    return 3;
                }
            };
        }
    });
    assertFilterBitsEqual(reader, new PhraseFilter("f", "world"), true, true, true);
    assertFilterBitsEqual(reader, new PhraseFilter(predicate, "f", "world"), false, true, true);
    assertFilterBitsEqual(reader, new PhraseFilter("f", "hello", "world"), true, false, true);
    assertFilterBitsEqual(reader, new PhraseFilter(predicate, "f", "hello", "world"), false, false, true);
}
Also used : BitsProviderIntersectionProvider(com.greplin.lucene.util.BitsProviderIntersectionProvider) IndexReader(org.apache.lucene.index.IndexReader) Bits(org.apache.lucene.util.Bits) BitsProvider(com.greplin.lucene.predicate.BitsProvider) IOException(java.io.IOException) BitsProviderIntersectionProvider(com.greplin.lucene.util.BitsProviderIntersectionProvider) FilterIntersectionProvider(com.greplin.lucene.util.FilterIntersectionProvider) IntersectionProvider(com.greplin.lucene.util.IntersectionProvider) Test(org.junit.Test)

Example 2 with IntersectionProvider

use of com.greplin.lucene.util.IntersectionProvider in project greplin-lucene-utils by Cue.

the class PhraseFilterTest method testIntersectionWithFilter.

@Test
public void testIntersectionWithFilter() throws Exception {
    IndexReader reader = createReaderWithSampleDocuments();
    IntersectionProvider filter = new FilterIntersectionProvider(TermsFilter.from(new Term("name", "one"), new Term("name", "two")));
    assertFilterBitsEqual(reader, new PhraseFilter("f", "world"), true, true, true);
    assertFilterBitsEqual(reader, new PhraseFilter(filter, "f", "world"), true, true, false);
    assertFilterBitsEqual(reader, new PhraseFilter("f", "hello", "world"), true, false, true);
    assertFilterBitsEqual(reader, new PhraseFilter(filter, "f", "hello", "world"), true, false, false);
}
Also used : FilterIntersectionProvider(com.greplin.lucene.util.FilterIntersectionProvider) IndexReader(org.apache.lucene.index.IndexReader) Term(org.apache.lucene.index.Term) BitsProviderIntersectionProvider(com.greplin.lucene.util.BitsProviderIntersectionProvider) FilterIntersectionProvider(com.greplin.lucene.util.FilterIntersectionProvider) IntersectionProvider(com.greplin.lucene.util.IntersectionProvider) Test(org.junit.Test)

Aggregations

BitsProviderIntersectionProvider (com.greplin.lucene.util.BitsProviderIntersectionProvider)2 FilterIntersectionProvider (com.greplin.lucene.util.FilterIntersectionProvider)2 IntersectionProvider (com.greplin.lucene.util.IntersectionProvider)2 IndexReader (org.apache.lucene.index.IndexReader)2 Test (org.junit.Test)2 BitsProvider (com.greplin.lucene.predicate.BitsProvider)1 IOException (java.io.IOException)1 Term (org.apache.lucene.index.Term)1 Bits (org.apache.lucene.util.Bits)1