lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mmastroianni <mmastroia...@placester.com>
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:

package com.myCompany.search;
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
MemoryPostingsFormat();
    
    private final PostingsFormat pf = new PerFieldPostingsFormat() {
        @Override
        public PostingsFormat getPostingsFormatForField(String field) {
            if(field.equals("primary_key")) return memoryFormat; 
            return PostingsFormat.forName("Lucene41");
        }
      };
      

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

    @Override
    public PostingsFormat postingsFormat() {
        return pf;
    }
}

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

/META-INF/services/org.apache.lucene.codec.Codec

inside of org.apache.lucene.codec.Codec I have one line that reads as
follows:
com.myCompany.search.CustomPostingsFormatCodec

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
error

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(NamedSPILoader.java:109)
	at org.apache.lucene.codecs.Codec.forName(Codec.java:95)
	at org.apache.lucene.index.SegmentInfos.read(SegmentInfos.java:332)
	at
org.apache.lucene.index.StandardDirectoryReader$1.doBody(StandardDirectoryReader.java:56)
	at
org.apache.lucene.index.SegmentInfos$FindSegmentsFile.run(SegmentInfos.java:812)
	at
org.apache.lucene.index.StandardDirectoryReader.open(StandardDirectoryReader.java:52)
	at org.apache.lucene.index.DirectoryReader.open(DirectoryReader.java:66)

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.

regards,
Michael



--
View this message in context: http://lucene.472066.n3.nabble.com/How-to-register-new-codec-with-sspi-tp4162344.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.

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


Mime
View raw message