You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Per Steffensen (JIRA)" <ji...@apache.org> on 2014/01/31 16:32:10 UTC

[jira] [Commented] (LUCENE-5427) Support for changing FieldCache implementation in Lucene

    [ https://issues.apache.org/jira/browse/LUCENE-5427?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13887834#comment-13887834 ] 

Per Steffensen commented on LUCENE-5427:
----------------------------------------

For reference this is (almost) the FieldCache we use
{code}
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.FieldCacheImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MyFieldCache extends FieldCacheImpl implements FieldCache {

	private final Logger log = LoggerFactory.getLogger(MyFieldCache.class);
	
	private class CreateValueFailsCache extends Cache {
		
		private CreateValueFailsCache() {
			super(MyFieldCache.this);
		}
		
		@Override
		protected Object createValue(AtomicReader reader, CacheKey key, boolean setDocsWithField) throws IOException {
			unsupported();
			return null;
		}
		
	}
	
	@Override
	protected synchronized void init() {
		super.init();
		Map<Class<?>, Cache> newCaches = new HashMap<Class<?>, Cache>();
		for (Entry<Class<?>, Cache> entry : caches.entrySet()) {
			newCaches.put(entry.getKey(), new CreateValueFailsCache());
		}
		caches = newCaches;
	}
	
	public MyFieldCache() {
		super();
		log.debug("Using " + getClass().getName());
	}
	
	private void unsupported() {
		throw new UnsupportedOperationException("You tried to perform a search that is not supported by this system. Technical reason: It tries to use the Lucene FieldCache in an illegal way");
	}

}
{code}
It does not just throw an exception when invoking one of the methods on FieldCache, because that does not always put something in the caches. In some situations FieldCacheImpl actually uses DocValue to do its job and puts nothing in the caches, and that it just fine and allowed

> Support for changing FieldCache implementation in Lucene
> --------------------------------------------------------
>
>                 Key: LUCENE-5427
>                 URL: https://issues.apache.org/jira/browse/LUCENE-5427
>             Project: Lucene - Core
>          Issue Type: New Feature
>          Components: core/search
>    Affects Versions: 4.6
>            Reporter: Per Steffensen
>              Labels: facet, fieldcache, range, search, sort
>         Attachments: Override_FieldCache_impl_to_use.patch
>
>
> Believe in general it would be a nice feature to be able to overwrite the FieldCache-implementation in Lucene.
> For instance we override with a FieldCache-implementation that basically does not allow anything to be put in the FieldCache caches. We have so much data that it always creates memory issues.
> But I could imagine other reasons for wanting to override the FieldCache-implementation



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org