Package org.apache.lucene.search

Examples of org.apache.lucene.search.Filter


    NumericRangeFilterBuilder filterBuilder = new NumericRangeFilterBuilder();
    filterBuilder.setStrictMode(false);

    String xml = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='NaN'/>";
    Document doc = getDocumentFromString(xml);
    Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
    Directory ramDir = newDirectory();
    IndexWriter writer = new IndexWriter(ramDir, newIndexWriterConfig(TEST_VERSION_CURRENT, null));
    writer.commit();
    try {
      AtomicReader reader = SlowCompositeReaderWrapper.wrap(DirectoryReader.open(ramDir));
      try {
        assertNull(filter.getDocIdSet(reader.getContext(), reader.getLiveDocs()));
      }
      finally {
        reader.close();
      }
    }
View Full Code Here


    NumericRangeFilterBuilder filterBuilder = new NumericRangeFilterBuilder();
    filterBuilder.setStrictMode(true);

    String xml = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10'/>";
    Document doc = getDocumentFromString(xml);
    Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
    assertTrue(filter instanceof NumericRangeFilter<?>);

    NumericRangeFilter<Integer> numRangeFilter = (NumericRangeFilter<Integer>) filter;
    assertEquals(Integer.valueOf(-1), numRangeFilter.getMin());
    assertEquals(Integer.valueOf(10), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());

    String xml2 = "<NumericRangeFilter fieldName='AGE' type='int' lowerTerm='-1' upperTerm='10' includeUpper='false'/>";
    Document doc2 = getDocumentFromString(xml2);
    Filter filter2 = filterBuilder.getFilter(doc2.getDocumentElement());
    assertTrue(filter2 instanceof NumericRangeFilter);

    NumericRangeFilter<Integer> numRangeFilter2 = (NumericRangeFilter) filter2;
    assertEquals(Integer.valueOf(-1), numRangeFilter2.getMin());
    assertEquals(Integer.valueOf(10), numRangeFilter2.getMax());
View Full Code Here

    NumericRangeFilterBuilder filterBuilder = new NumericRangeFilterBuilder();
    filterBuilder.setStrictMode(true);

    String xml = "<NumericRangeFilter fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000'/>";
    Document doc = getDocumentFromString(xml);
    Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
    assertTrue(filter instanceof NumericRangeFilter<?>);

    NumericRangeFilter<Long> numRangeFilter = (NumericRangeFilter) filter;
    assertEquals(Long.valueOf(-2321L), numRangeFilter.getMin());
    assertEquals(Long.valueOf(60000000L), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());

    String xml2 = "<NumericRangeFilter fieldName='AGE' type='LoNg' lowerTerm='-2321' upperTerm='60000000' includeUpper='false'/>";
    Document doc2 = getDocumentFromString(xml2);
    Filter filter2 = filterBuilder.getFilter(doc2.getDocumentElement());
    assertTrue(filter2 instanceof NumericRangeFilter<?>);
    NumericRangeFilter<Long> numRangeFilter2 = (NumericRangeFilter) filter2;
    assertEquals(Long.valueOf(-2321L), numRangeFilter2.getMin());
    assertEquals(Long.valueOf(60000000L), numRangeFilter2.getMax());
    assertEquals("AGE", numRangeFilter2.getField());
View Full Code Here

    filterBuilder.setStrictMode(true);

    String xml = "<NumericRangeFilter fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023'/>";
    Document doc = getDocumentFromString(xml);

    Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
    assertTrue(filter instanceof NumericRangeFilter<?>);

    NumericRangeFilter<Double> numRangeFilter = (NumericRangeFilter) filter;
    assertEquals(Double.valueOf(-23.21d), numRangeFilter.getMin());
    assertEquals(Double.valueOf(60000.00023d), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());

    String xml2 = "<NumericRangeFilter fieldName='AGE' type='doubLe' lowerTerm='-23.21' upperTerm='60000.00023' includeUpper='false'/>";
    Document doc2 = getDocumentFromString(xml2);
    Filter filter2 = filterBuilder.getFilter(doc2.getDocumentElement());
    assertTrue(filter2 instanceof NumericRangeFilter<?>);

    NumericRangeFilter<Double> numRangeFilter2 = (NumericRangeFilter) filter2;
    assertEquals(Double.valueOf(-23.21d), numRangeFilter2.getMin());
    assertEquals(Double.valueOf(60000.00023d), numRangeFilter2.getMax());
View Full Code Here

    filterBuilder.setStrictMode(true);

    String xml = "<NumericRangeFilter fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23'/>";
    Document doc = getDocumentFromString(xml);

    Filter filter = filterBuilder.getFilter(doc.getDocumentElement());
    assertTrue(filter instanceof NumericRangeFilter<?>);

    NumericRangeFilter<Float> numRangeFilter = (NumericRangeFilter) filter;
    assertEquals(Float.valueOf(-2.321432f), numRangeFilter.getMin());
    assertEquals(Float.valueOf(32432.23f), numRangeFilter.getMax());
    assertEquals("AGE", numRangeFilter.getField());
    assertTrue(numRangeFilter.includesMin());
    assertTrue(numRangeFilter.includesMax());

    String xml2 = "<NumericRangeFilter fieldName='AGE' type='FLOAT' lowerTerm='-2.321432' upperTerm='32432.23' includeUpper='false' precisionStep='2' />";
    Document doc2 = getDocumentFromString(xml2);

    Filter filter2 = filterBuilder.getFilter(doc2.getDocumentElement());
    assertTrue(filter2 instanceof NumericRangeFilter<?>);
   
    NumericRangeFilter<Float> numRangeFilter2 = (NumericRangeFilter) filter2;
    assertEquals(Float.valueOf(-2.321432f), numRangeFilter2.getMin());
    assertEquals(Float.valueOf(32432.23f), numRangeFilter2.getMax());
View Full Code Here

    new FieldQuery(q, reader, true, true );
  }
 
  public void testFlattenFilteredQuery() throws Exception {
    initBoost();
    Query query = new FilteredQuery(pqF( "A" ), new Filter() {
      @Override
      public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs)
          throws IOException {
        return null;
      }
View Full Code Here

          }
          ddq.add(paths);
        }
      }

      Filter filter;
      if (random().nextInt(7) == 6) {
        if (VERBOSE) {
          System.out.println("  only-even filter");
        }
        filter = new Filter() {
            @Override
            public DocIdSet getDocIdSet(AtomicReaderContext context, Bits acceptDocs) throws IOException {
              int maxDoc = context.reader().maxDoc();
              final FixedBitSet bits = new FixedBitSet(maxDoc);
              for(int docID=0;docID < maxDoc;docID++) {
View Full Code Here

  private void buildFilters() {
    ChainedFilter chainedFilter = new ChainedFilter();
    if ( !filterDefinitions.isEmpty() ) {
      for ( FullTextFilterImpl fullTextFilter : filterDefinitions.values() ) {
        Filter filter = buildLuceneFilter( fullTextFilter );
        if ( filter != null ) {
          chainedFilter.addFilter( filter );
        }
      }
    }
View Full Code Here

    Object instance = createFilterInstance( fullTextFilter, def );
    FilterKey key = createFilterKey( def, instance );

    // try to get the filter out of the cache
    Filter filter = cacheInstance( def.getCacheMode() ) ?
        searchFactoryImplementor.getFilterCachingStrategy().getCachedFilter( key ) :
        null;

    if ( filter == null ) {
      filter = createFilter( def, instance );
View Full Code Here

  private boolean isPreQueryFilterOnly(FilterDef def) {
    return def.getImpl().equals( ShardSensitiveOnlyFilter.class );
  }

  private Filter createFilter(FilterDef def, Object instance) {
    Filter filter;
    if ( def.getFactoryMethod() != null ) {
      try {
        filter = (Filter) def.getFactoryMethod().invoke( instance );
      }
      catch (IllegalAccessException e) {
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.Filter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.