lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmastroianni <>
Subject How to register new codec with sspi?
Date Thu, 02 Oct 2014 16:13:42 GMT
I added a new codec that just uses FilterCodec and Lucene42Codec, and
overrides so that I get a MemoryPostingsFormat for a field called
primary_key as follows:

import org.apache.lucene.codecs.FilterCodec;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.lucene42.Lucene42Codec;
import org.apache.lucene.codecs.memory.MemoryPostingsFormat;
import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;

public class CustomPostingsFormatCodec extends FilterCodec
    protected final MemoryPostingsFormat memoryFormat = new
    private final PostingsFormat pf = new PerFieldPostingsFormat() {
        public PostingsFormat getPostingsFormatForField(String field) {
            if(field.equals("primary_key")) return memoryFormat; 
            return PostingsFormat.forName("Lucene41");

    public CustomPostingsFormatCodec()
        super("CustomPostingsFormatCodec", new Lucene42Codec());

    public PostingsFormat postingsFormat() {
        return pf;

I added a Meta-Inf to my jar file so I had the following structure:


inside of org.apache.lucene.codec.Codec I have one line that reads as

I built an index using this (I'm using raw lucene, not Solr at present), and
all appeared to work. However, when I tried to read the resulting index
using some code in my jar (in addition to the lucene-4.4 jars), I get the

Exception in thread "main" java.lang.IllegalArgumentException: A SPI class
of type org.apache.lucene.codecs.Codec with name 'CustomPostingsFormatCodec'
does not exist. You need to add the corresponding JAR file supporting this
SPI to your classpath.The current classpath supports the following names:
[SimpleText, Appending, Lucene40, Lucene3x, Lucene41, Lucene42]
	at org.apache.lucene.util.NamedSPILoader.lookup(
	at org.apache.lucene.codecs.Codec.forName(

What did I do wrong? is this a jar file order problem? Do I need to actually
modify my Lucene sources and rebuild the lucened core jar with this in the
/META-INF/services/org.apache.lucene.codec.Codec file?

Any help would be greatly appreciated.


View this message in context:
Sent from the Lucene - Java Users mailing list archive at

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

View raw message