01: package org.apache.lucene.search;
02:
03: /**
04: * Licensed to the Apache Software Foundation (ASF) under one or more
05: * contributor license agreements. See the NOTICE file distributed with
06: * this work for additional information regarding copyright ownership.
07: * The ASF licenses this file to You under the Apache License, Version 2.0
08: * (the "License"); you may not use this file except in compliance with
09: * the License. You may obtain a copy of the License at
10: *
11: * http://www.apache.org/licenses/LICENSE-2.0
12: *
13: * Unless required by applicable law or agreed to in writing, software
14: * distributed under the License is distributed on an "AS IS" BASIS,
15: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16: * See the License for the specific language governing permissions and
17: * limitations under the License.
18: */
19:
20: import java.io.IOException;
21: import java.util.BitSet;
22:
23: import org.apache.lucene.index.IndexReader;
24:
25: /**
26: * Provides caching of {@link Filter}s themselves on the remote end of an RMI connection.
27: * The cache is keyed on Filter's hashCode(), so if it sees the same filter twice
28: * it will reuse the original version.
29: * <p/>
30: * NOTE: This does NOT cache the Filter bits, but rather the Filter itself.
31: * Thus, this works hand-in-hand with {@link CachingWrapperFilter} to keep both
32: * file Filter cache and the Filter bits on the remote end, close to the searcher.
33: * <p/>
34: * Usage:
35: * <p/>
36: * To cache a result you must do something like
37: * RemoteCachingWrapperFilter f = new RemoteCachingWrapperFilter(new CachingWrapperFilter(myFilter));
38: * <p/>
39: * @author Matt Ericson
40: */
41: public class RemoteCachingWrapperFilter extends Filter {
42: protected Filter filter;
43:
44: public RemoteCachingWrapperFilter(Filter filter) {
45: this .filter = filter;
46: }
47:
48: /**
49: * Uses the {@link FilterManager} to keep the cache for a filter on the
50: * searcher side of a remote connection.
51: * @param reader the index reader for the Filter
52: * @return the bitset
53: */
54: public BitSet bits(IndexReader reader) throws IOException {
55: Filter cachedFilter = FilterManager.getInstance().getFilter(
56: filter);
57: return cachedFilter.bits(reader);
58: }
59: }
|