Package org.apache.lucene.search.filters

Source Code of org.apache.lucene.search.filters.PwaBlacklistFilter

package org.apache.lucene.search.filters;

import java.io.IOException;

import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.PwaSearchableCommon;
import org.apache.lucene.search.caches.PwaBlacklistCache;


/**
* Filter based on blacklist
* @author Miguel Costa
*/
public class PwaBlacklistFilter extends PwaFilter {
 
  private PwaBlacklistCache cache;


  /**
   * Constructor 
   * @param reader index reader
   */ 
  public PwaBlacklistFilter(IndexReader reader) throws IOException {
    this(null,reader);   
  }
 
  /**
   * Constructor
   * @param searchable documents stream
   * @param reader index reader
   */ 
  public PwaBlacklistFilter(PwaSearchableCommon searchable, IndexReader reader) throws IOException {
    super(searchable);
    this.cache = new PwaBlacklistCache(reader,null); // the PwaBlacklistCache will use the blacklist configuration (file path) from initialization
  }
 
 
  /**
   * Indicates if has document
   * @return
   */
  public boolean hasDoc() {
    return searchable.hasDoc();
  }
 
  /**
   * Get document id 
   */
  public int doc() {   
    return searchable.doc();
  }
 
  /**
   * Move to next document
   */
  public boolean next() throws IOException
    while (searchable.next()) {
      if (cache.isValid(searchable.doc())) { // return if it is not in blacklist
        return true;
      }
    }
    return false;
  }

}
TOP

Related Classes of org.apache.lucene.search.filters.PwaBlacklistFilter

TOP
Copyright © 2018 www.massapi.com. 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.