01: /*
02: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/search/CombineFilter.java,v 1.9 2007/10/09 11:09:21 lexuanttkhtn Exp $
03: * $Author: lexuanttkhtn $
04: * $Revision: 1.9 $
05: * $Date: 2007/10/09 11:09:21 $
06: *
07: * ====================================================================
08: *
09: * Copyright (C) 2002-2007 by MyVietnam.net
10: *
11: * All copyright notices regarding mvnForum MUST remain
12: * intact in the scripts and in the outputted HTML.
13: * The "powered by" text/logo with a link back to
14: * http://www.mvnForum.com and http://www.MyVietnam.net in
15: * the footer of the pages MUST remain visible when the pages
16: * are viewed on the internet or intranet.
17: *
18: * This program is free software; you can redistribute it and/or modify
19: * it under the terms of the GNU General Public License as published by
20: * the Free Software Foundation; either version 2 of the License, or
21: * any later version.
22: *
23: * This program is distributed in the hope that it will be useful,
24: * but WITHOUT ANY WARRANTY; without even the implied warranty of
25: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26: * GNU General Public License for more details.
27: *
28: * You should have received a copy of the GNU General Public License
29: * along with this program; if not, write to the Free Software
30: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31: *
32: * Support can be obtained from support forums at:
33: * http://www.mvnForum.com/mvnforum/index
34: *
35: * Correspondence and Marketing Questions can be sent to:
36: * info at MyVietnam net
37: *
38: * @author: Phong Ta Quoc
39: */
40: package com.mvnforum.search;
41:
42: import java.io.IOException;
43: import java.util.BitSet;
44:
45: import org.apache.lucene.index.IndexReader;
46: import org.apache.lucene.search.Filter;
47:
48: /**
49: * A Filter that restricts search results to match the results of both filter.
50: */
51: public class CombineFilter extends Filter {
52:
53: private Filter leftFilter;
54:
55: private Filter rightFilter;
56:
57: public CombineFilter(Filter f1, Filter f2) {
58: if ((f1 == null) && (f2 == null)) {
59: throw new IllegalArgumentException(
60: "At least f1 or f2 must not be null.");
61: }
62: leftFilter = f1;
63: rightFilter = f2;
64: }
65:
66: public BitSet bits(IndexReader reader) throws IOException {
67:
68: BitSet resultBits = null;
69: if ((leftFilter != null) && (rightFilter != null)) {
70: BitSet leftBits = leftFilter.bits(reader);
71: BitSet rightBits = rightFilter.bits(reader);
72: resultBits = (BitSet) leftBits.clone();
73: resultBits.and(rightBits);
74: } else if (leftFilter != null) {
75: resultBits = leftFilter.bits(reader);
76: } else if (rightFilter != null) {
77: resultBits = rightFilter.bits(reader);
78: } else {
79: // should never happen since we have checked it in the constructor
80: throw new IllegalArgumentException(
81: "At least f1 or f2 must not be null.");
82: }
83: return resultBits;
84: }
85:
86: public String toString() {
87: StringBuffer buffer = new StringBuffer();
88: buffer.append(leftFilter);
89: buffer.append("\n");
90: buffer.append(rightFilter);
91: return buffer.toString();
92: }
93: }
|