lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Earwin Burrfoot <>
Subject IndexReader plugins
Date Sun, 12 Apr 2009 23:34:38 GMT
To support my dream of kicking fieldCache out of the core and to add
some extensibility to Lucene, I want to introduce IndexReaderPlugins.
Rough pseudocode follows:

interface IndexReaderPlugin {
	void attach(SegmentReader reader);
	void detach(SegmentReader reader);

	void attach(MultiSegmentReader reader);
	void detach(MultiSegmentReader reader);
private Map<Class, IndexReaderPlugin> plugins;

on opening/closing toplevel/segment reader we iterate over plugins:
for(IndexReaderPlugin plugin : plugins)

the map is passed to toplevel reader initially, and then shared with
lowlevel readers, we can also retrieve plugins:
public <T> T plugin(Class<T> pluginType);

then we can do something like:
indexReader.plugin(ValueSource.class).doSomething // lucene code
// my code
filter.apply(indexReader.plugin(FilterCache.class)) // my code

Benefits are numerous. We get rid of alien code like:
+++ src/java/org/apache/lucene/index/	(working copy)
@@ -83,6 +86,8 @@
+  protected ValueSource valueSource;
@@ -555,6 +560,8 @@
+      valueSource = new CachingValueSource(this, new

If I don't need ValueSource attached to my readers, I won't have it.
If I need my custom caches attached to my readers, I can do it in a
natural way instead of hacking around MergeScheduler, or comparing
subreader lists.
If I want, I can replace Lucene's native ValueSource with my own
implementation, and all Lucene classes that use it will happily accept

On second thought, we shouldn't share plugin map across subreaders. If
we allow attach(SegmentReader reader) to return an instance of plugin
(plugin decides if it is the same instance always, or per-reader), and
populate the map for subreader with results of attach invoked on
toplevel reader map, we'll turn this code:
which makes more sense

Any way the general idea is still the same.

Kirill Zakharenko/Кирилл Захаренко (
Home / Mobile: +7 (495) 683-567-4 / +7 (903) 5-888-423
ICQ: 104465785

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message