multifilter.java
来自「Jive是基于JSP/JAVA技术构架的一个大型BBS论坛系统,这是Jive论坛」· Java 代码 · 共 94 行
JAVA
94 行
/* * $RCSfile: MultiFilter.java,v $ * $Revision: 1.2 $ * $Date: 2002/05/10 22:19:38 $ * * Copyright (C) 1999-2002 CoolServlets, Inc. All rights reserved. * * This software is the proprietary information of CoolServlets, Inc. * Use is subject to license terms. */package com.jivesoftware.forum.database;import java.util.*;import java.io.IOException;import org.apache.lucene.index.*;import org.apache.lucene.search.*;/** * A Filter that logically combines multiple other Filters. An arbitrary * number of Filter objects can be added to each MultiFilter. When a Query is * executed with a MultiFilter, each Document in the HitList must pass every * Filter in the MultiFilter filter list.<p> * * For example, consider a MultiFilter that is created with a FilterX filter * and FilterY filter. When a search is executed with the MultiFilter, in order * for Document A to appear in the results, it must pass both the FilterX * <b>and</b> FilterY filters.<p> * * If no Filter objects are added to a MultiFilter before it is used in a * search, this will have the affect of filtering out all search results. * * @author Matt Tucker */public class MultiFilter extends org.apache.lucene.search.Filter { /** * An ArrayList to store the filters that are part of this MultiFilter. We * use an ArrayList instead of a Vector for increased performance. If you * require JDK1.1 support, change to a Vector. */ private List filterList; /** * Creates a new MultiFilter. */ public MultiFilter() { filterList = new ArrayList(); } /** * Creates a new MultiFilter with the specified initial capacity. Providing * an initial capacity equal to the size of the eventual MultiFilter size * provides a slight performance advantage over letting the MultiFilter * grow automatically. * * @param initialCapacity an initial capacity size for the MultiFilter. */ public MultiFilter(int initialCapacity) { filterList = new ArrayList(initialCapacity); } /** * Adds a filter to the MuliFilter filter list. * * @param filter a Filter to add to the MultiFilter filter list. */ public void add(Filter filter) { filterList.add(filter); } public BitSet bits(IndexReader reader) throws IOException { // Iterate through list of filters and apply the boolean AND operation // on each bitSet. The AND operator has the affect that only documents // that are allowed by every single filter in the filter list will be // allowed by this MultiFilter. int filterListSize = filterList.size(); if (filterListSize > 0) { BitSet bits = ((Filter)filterList.get(0)).bits(reader); for (int i=1; i<filterListSize; i++) { bits.and( ((Filter)filterList.get(i)).bits(reader) ); } return bits; } // There are no filters defined. In this case, we return a new // BitSet that will filter out all documents. This is probably the most // consistent behavior with the Lucene API. It's also a lot more // efficient considering the BitSet implementation. else { return new BitSet(reader.maxDoc()); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?