/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using Lucene.Net.Support;
using IndexReader = Lucene.Net.Index.IndexReader;
using OpenBitSetDISI = Lucene.Net.Util.OpenBitSetDISI;
using Lucene.Net.Util;
namespace Lucene.Net.Search
{
/// Wraps another filter's result and caches it. The purpose is to allow
/// filters to simply filter, and then wrap with this class to add caching.
///
[Serializable]
public class CachingWrapperFilter:Filter
{
protected internal Filter filter;
///
/// Expert: Specifies how new deletions against a reopened
/// reader should be handled.
///
/// The default is IGNORE, which means the cache entry
/// will be re-used for a given segment, even when that
/// segment has been reopened due to changes in deletions.
/// This is a big performance gain, especially with
/// near-real-timer readers, since you don't hit a cache
/// miss on every reopened reader for prior segments.
///
/// However, in some cases this can cause invalid query
/// results, allowing deleted documents to be returned.
/// This only happens if the main query does not rule out
/// deleted documents on its own, such as a toplevel
/// ConstantScoreQuery. To fix this, use RECACHE to
/// re-create the cached filter (at a higher per-reopen
/// cost, but at faster subsequent search performance), or
/// use DYNAMIC to dynamically intersect deleted docs (fast
/// reopen time but some hit to search performance).
///
public enum DeletesMode { IGNORE, RECACHE, DYNAMIC }
internal FilterCache cache;
[Serializable]
abstract internal class FilterCache where T : class
{
/*
* A transient Filter cache (package private because of test)
*/
// NOTE: not final so that we can dynamically re-init
// after de-serialize
volatile IDictionary