add a marker CachedFilter

this allows to easily and globally check if we cache a filter or not, all filter caching uses this marker interface
This commit is contained in:
Shay Banon 2012-12-06 10:13:47 +01:00
parent 2786e29a10
commit c2f8ee105b
4 changed files with 35 additions and 14 deletions

View File

@ -0,0 +1,32 @@
/*
* Licensed to ElasticSearch and Shay Banon under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. ElasticSearch 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.
*/
package org.elasticsearch.common.lucene.search;
import org.apache.lucene.search.Filter;
/**
* A marker indicating that this is a cached filter.
*/
public abstract class CachedFilter extends Filter {
public static boolean isCached(Filter filter) {
return filter instanceof CachedFilter;
}
}

View File

@ -43,8 +43,6 @@ public interface FilterCache extends IndexComponent, CloseableComponent {
Filter cache(Filter filterToCache);
boolean isCached(Filter filter);
void clear(IndexReader reader);
void clear(String reason);

View File

@ -54,11 +54,6 @@ public class NoneFilterCache extends AbstractIndexComponent implements FilterCac
return filterToCache;
}
@Override
public boolean isCached(Filter filter) {
return false;
}
@Override
public void clear(String reason) {
// nothing to do here

View File

@ -33,6 +33,7 @@ import org.apache.lucene.util.FixedBitSet;
import org.elasticsearch.ElasticSearchException;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.lucene.docset.DocIdSets;
import org.elasticsearch.common.lucene.search.CachedFilter;
import org.elasticsearch.common.lucene.search.NoCacheFilter;
import org.elasticsearch.common.metrics.CounterMetric;
import org.elasticsearch.common.metrics.MeanMetric;
@ -122,18 +123,13 @@ public class WeightedFilterCache extends AbstractIndexComponent implements Filte
if (filterToCache instanceof NoCacheFilter) {
return filterToCache;
}
if (isCached(filterToCache)) {
if (CachedFilter.isCached(filterToCache)) {
return filterToCache;
}
return new FilterCacheFilterWrapper(filterToCache, this);
}
@Override
public boolean isCached(Filter filter) {
return filter instanceof FilterCacheFilterWrapper;
}
static class FilterCacheFilterWrapper extends Filter {
static class FilterCacheFilterWrapper extends CachedFilter {
private final Filter filter;