I have created a custom filter factory for solr 4.2. It is working good. But when I am trying to upgarde solr-4.2 to 4.7 version, it is reporting errors:
Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] analyzer/filter: Error instantiating class: 'org.apache.lucene.analysis.ExtendedNameFilterFactory'
Here's the java code for the factory:
package org.apache.lucene.analysis;
import java.util.Map;
import org.apache.lucene.analysis.util.AbstractAnalysisFactory;
import org.apache.lucene.analysis.util.MultiTermAwareComponent;
import org.apache.lucene.analysis.util.TokenFilterFactory;
public class ExtendedNameFilterFactory extends TokenFilterFactory
implements MultiTermAwareComponent
{
int extendedWordCount;
public void init(Map<String, String> args)
{
super.init(args);
assureMatchVersion();
this.extendedWordCount = getInt("extendedWordCount", -1);
}
public ExtendedNameFilter create(TokenStream input) {
return new ExtendedNameFilter(this.luceneMatchVersion, input, this.extendedWordCount);
}
public AbstractAnalysisFactory getMultiTermComponent()
{
return this;
}
}
And for the Filter:
package org.apache.lucene.analysis;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;
import org.apache.lucene.analysis.tokenattributes.OffsetAttribute;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.util.CharacterUtils;
import org.apache.lucene.util.Version;
public final class ExtendedNameFilter extends TokenFilter
{
private final CharTermAttribute termAtt = (CharTermAttribute)addAttribute(CharTermAttribute.class);
private PositionIncrementAttribute posIncAttr;
private OffsetAttribute setOffsetAttr;
private final int extendedWordCount;
LinkedList<String> list = new LinkedList();
ArrayList<Integer> startOffsetList = new ArrayList();
int endOffset = 0;
int count = 0;
public ExtendedNameFilter(Version matchVersion, TokenStream in, int extendedWordCount)
{
super(in);
CharacterUtils.getInstance(matchVersion);
this.extendedWordCount = extendedWordCount;
this.posIncAttr = ((PositionIncrementAttribute)addAttribute(PositionIncrementAttribute.class));
this.setOffsetAttr = ((OffsetAttribute)addAttribute(OffsetAttribute.class));
}
public final boolean incrementToken()
throws IOException
{
int len = 0;
while (this.input.incrementToken()) {
this.list.add(this.termAtt.toString());
this.startOffsetList.add(Integer.valueOf(this.setOffsetAttr.startOffset()));
this.endOffset = this.setOffsetAttr.endOffset();
}
Iterator iterator = this.list.iterator();
len = this.list.size();
if ((len > 0) && (this.extendedWordCount < 0)) {
this.termAtt.setEmpty();
while (iterator.hasNext()) {
this.termAtt.append((CharSequence)iterator.next());
}
this.list.removeFirst();
this.posIncAttr.setPositionIncrement(10);
this.setOffsetAttr.setOffset(((Integer)this.startOffsetList.get(this.count)).intValue(), this.endOffset);
this.count += 1;
return true;
}
if ((len > 0) && (this.count < this.extendedWordCount)) {
this.termAtt.setEmpty();
while (iterator.hasNext()) {
this.termAtt.append((CharSequence)iterator.next());
}
this.list.removeFirst();
this.posIncAttr.setPositionIncrement(10);
this.setOffsetAttr.setOffset(((Integer)this.startOffsetList.get(this.count)).intValue(), this.endOffset);
this.count += 1;
return true;
}
return false;
}
}
It was working good with solr 4.2. Can anybody tell me the changes that I need to make for running it in solr 4.7.1?