2 * Copyright 2004 The Apache Software Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System
.Runtime
.InteropServices
;
19 using IndexReader
= Lucene
.Net
.Index
.IndexReader
;
21 namespace Lucene
.Net
.Search
24 /// <summary> Wraps another filter's result and caches it. The caching
25 /// behavior is like {@link QueryFilter}. The purpose is to allow
26 /// filters to simply filter, and then wrap with this class to add
27 /// caching, keeping the two concerns decoupled yet composable.
30 public class CachingWrapperFilter
:Filter
32 private Filter filter
;
34 /// <todo> What about serialization in RemoteSearchable? Caching won't work. </todo>
35 /// <summary> Should transient be removed?
38 private System
.Collections
.IDictionary cache
;
40 /// <param name="filter">Filter to cache results of
42 public CachingWrapperFilter(Filter filter
)
47 public override System
.Collections
.BitArray
Bits(IndexReader reader
)
51 cache
= new System
.Collections
.Hashtable();
57 System
.Collections
.BitArray cached
= (System
.Collections
.BitArray
) cache
[reader
];
64 System
.Collections
.BitArray bits
= filter
.Bits(reader
);
75 public override System
.String
ToString()
77 return "CachingWrapperFilter(" + filter
+ ")";
80 public override bool Equals(System
.Object o
)
82 if (!(o
is CachingWrapperFilter
))
84 return this.filter
.Equals(((CachingWrapperFilter
) o
).filter
);
87 public override int GetHashCode()
89 return filter
.GetHashCode() ^
0x1117BF25;