Disabled auto-caching.
Change-Id: If746af1523dd3a1be7ebac8e8d29ea7abe59aa67
diff --git a/src/main/java/de/ids_mannheim/korap/collection/CachedVCFilter.java b/src/main/java/de/ids_mannheim/korap/collection/CachedVCFilter.java
index 1c35233..5b1bff7 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/CachedVCFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/CachedVCFilter.java
@@ -2,6 +2,8 @@
import java.io.IOException;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.DocIdSet;
import org.apache.lucene.search.Filter;
@@ -15,11 +17,13 @@
*/
public class CachedVCFilter extends Filter {
+ public static Logger jlog = LogManager.getLogger(CachedVCFilter.class);
+
private CachedVCData cachedCollection;
- private String cacheKey;
+ private String cacheKey;
public CachedVCFilter (String cacheKey, CachedVCData cachedCollection) {
- this.cacheKey = cacheKey;
+ this.cacheKey = cacheKey;
this.cachedCollection = cachedCollection;
}
@@ -30,14 +34,14 @@
cachedCollection.getDocIdMap().get(context.hashCode());
if (docBits == null) {
- // does not exist in the cache
+ jlog.debug("LeafReaderContext is not found in the cache.");
return null;
}
return docBits.createBitDocIdSet();
}
- @Override
+ @Override
public String toString () {
- return "referTo(cached:" + this.cacheKey + ")";
+ return "referTo(cached:" + this.cacheKey + ")";
};
}
diff --git a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
index feba2d1..10f4645 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/CollectionBuilder.java
@@ -287,7 +287,9 @@
public Filter toFilter () throws QueryException {
Element element = KrillCollection.cache.get(this.reference);
+
if (element == null) {
+ log.debug(reference + " is NOT found in the cache");
KrillCollection kc = new KrillCollection();
kc.fromStore(this.reference);
@@ -307,6 +309,7 @@
);
}
else {
+ log.debug(reference + " is FOUND in the cache.");
CachedVCData cc = (CachedVCData) element.getObjectValue();
return new CachedVCFilter(this.reference, cc);
}
diff --git a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
index fe2c437..3a3675d 100644
--- a/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/collection/ToCacheVCFilter.java
@@ -10,12 +10,15 @@
import org.apache.lucene.search.Filter;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.FixedBitSet;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import de.ids_mannheim.korap.KrillCollection;
import de.ids_mannheim.korap.collection.CollectionBuilder.Interface;
import net.sf.ehcache.Element;
-/** Filter for virtual corpus / collection that should be cached.
+/**
+ * Filter for virtual corpus / collection that should be cached.
*
* @author margaretha
*
@@ -25,7 +28,11 @@
private CollectionBuilder.Interface cbi;
private String cacheKey;
private Map<Integer, DocBits> docIdMap;
+ // EM: auto caching is disabled regarding issue #44
+ private boolean isAutoCachingEnabled = false;
+ public final static Logger log = LoggerFactory.getLogger(ToCacheVCFilter.class);
+
public ToCacheVCFilter (String cacheKey, Map<Integer, DocBits> docIdMap,
Interface cbi, Filter filter) {
this.cacheKey = cacheKey;
@@ -54,22 +61,27 @@
}
else {
bitset.or(docIdSet.iterator());
- if (cbi.isNegative()){
+ if (cbi.isNegative()) {
bitset.flip(0, maxDoc);
}
}
- docIdMap.put(context.hashCode(), new DocBits(bitset.getBits(), bitset.length()));
- CachedVCData cachedVCData = new CachedVCData(new HashMap<>(docIdMap));
+ if (isAutoCachingEnabled) {
+ docIdMap.put(context.hashCode(),
+ new DocBits(bitset.getBits(), bitset.length()));
+ CachedVCData cachedVCData =
+ new CachedVCData(new HashMap<>(docIdMap));
- KrillCollection.cache.remove(cacheKey);
- KrillCollection.cache.put(new Element(cacheKey, cachedVCData));
+ KrillCollection.cache.remove(cacheKey);
+ KrillCollection.cache.put(new Element(cacheKey, cachedVCData));
+ }
+ log.debug("To cache doc bits length: "+ docIdSet.bits().length());
return docIdSet;
}
@Override
public String toString () {
- return "referTo(" + this.cacheKey + ")";
+ return "referTo(" + this.cacheKey + ")";
};
}