You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Dileepa Jayakody <di...@gmail.com> on 2013/11/07 19:31:24 UTC

Error instantiating a Custom Filter in Solr

Hi All,

I'm  a novice in Solr and I'm continuously bumping into problems with my
custom filter I'm trying to use for analyzing a fieldType during indexing
as below;

<fieldType name="stanbolRequestType" class="solr.TextField">
  <analyzer type="index">
    <tokenizer class="solr.KeywordTokenizerFactory"/>
    <filter class= "com.solr.test.analyzer.ContentFilterFactory"/>
  </analyzer>
</fieldType>

Below is my custom FilterFactory class;

*public class ContentFilterFactory extends TokenFilterFactory {*

* public ContentFilterFactory() {*
* super();*
* }*

* @Override*
* public TokenStream create(TokenStream input) {*
* return new ContentFilter(input);*
* }*
*}*

I'm getting below error stack trace [1] caused by a NoSuchMethodException
when starting the server.
Solr complains that it cannot init the Plugin (my custom filter)  as the
FilterFactory class doesn't have a init method; But in the example [2] I
was following didn't have any notion of a init method in the FilterFactory
class, nor I was required to override an init method when extending
TokenFilterFactory class.

Can someone please help me resolve this error and get my custom filter
working?

Thanks,
Dileepa

[1]
Caused by: org.apache.solr.common.SolrException: Plugin init failure for
[schema.xml] fieldType "stanbolRequestType": Plugin init failure for
[schema.xml] analyzer/filter: Error instantiating class:
'com.solr.test.analyzer.ContentFilterFactory'
at
org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:468)
... 13 more
Caused by: org.apache.solr.common.SolrException: Plugin init failure for
[schema.xml] analyzer/filter: Error instantiating class:
'com.solr.test.analyzer.ContentFilterFactory'
at
org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
at
org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
at
org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:95)
at
org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
at
org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
... 14 more
Caused by: org.apache.solr.common.SolrException: Error instantiating class:
'com.solr.test.analyzer.ContentFilterFactory'
at
org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
at
org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
at
org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
at
org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
... 18 more
Caused by: java.lang.NoSuchMethodException:
com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
at java.lang.Class.getConstructor0(Class.java:2810)
at java.lang.Class.getConstructor(Class.java:1718)
at
org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:552)
... 21 more

[2] http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/

Re: Error instantiating a Custom Filter in Solr

Posted by Dileepa Jayakody <di...@gmail.com>.
Thanks guys,

I got the problem resolved. It was a constructor API mismatch between the
code I wrote and the library I used.

I used the latest lucene-common 4.5.0 with my sample code and the startup
issue was resolved.

related stackoverflow discussion :
http://stackoverflow.com/questions/19840129/error-instantiating-the-custom-filterfactory-class-in-solr

Regards,
Dileepa


On Fri, Nov 8, 2013 at 9:21 PM, Jack Krupansky <ja...@basetechnology.com>wrote:

> Thanks for the plug Erick, but my deep dive doesn't go quite that deep
> (yet.)
>
> But I'm sure a 2,500 page book on how to develop all manner of custom Solr
> plugin would indeed be valuable though.
>
> But I do have plenty of example of using the many builtin Solr analysis
> filters.
>
> -- Jack Krupansky
>
> -----Original Message----- From: Erick Erickson
> Sent: Friday, November 08, 2013 10:36 AM
> To: solr-user@lucene.apache.org
> Subject: Re: Error instantiating a Custom Filter in Solr
>
>
> Well, I think Jack Krupansky's book has some examples, at $10 it's probably
> a steal.
>
> Best,
> Erick
>
>
>
>
> On Fri, Nov 8, 2013 at 1:49 AM, Dileepa Jayakody
> <di...@gmail.com>wrote:
>
>  Hi Erick,
>>
>> Thanks a lot for the pointer.
>> I looked at the LowerCaseFilterFactory class [1] and it's parent abstract
>> class AbstractAnalysisFactory API [2] , and modified my custom filter
>> factory class as below;
>>
>> public class ContentFilterFactory extends TokenFilterFactory {
>>
>> public ContentFilterFactory() {
>> super();
>> }
>>
>> @Override
>> public void init(Map<String, String> args) {
>> super.init(args);
>> }
>>
>> @Override
>> public ContentFilter create(TokenStream input) {
>> assureMatchVersion();
>> return new ContentFilter(input);
>> }
>> }
>>
>> I have called the parent's init method as above, but I'm still getting the
>> same error of : java.lang.NoSuchMethodException: com.solr.test.analyzer.
>> ContentFilterFactory.<init>(java.util.Map)
>>
>> Any input on this?
>> Can some one please point me to a doc/blog or any sample to implement a
>> custom filter with Solr > 4.0
>> I'm using Solr 4.5.0 server.
>>
>> Thanks,
>> Dileepa
>>
>> [1]
>>
>> http://search-lucene.com/c/Lucene:analysis/common/src/
>> java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java
>> [2]
>>
>> https://lucene.apache.org/core/4_2_0/analyzers-common/
>> org/apache/lucene/analysis/util/AbstractAnalysisFactory.html
>>
>>
>> On Fri, Nov 8, 2013 at 4:25 AM, Erick Erickson <erickerickson@gmail.com
>> >wrote:
>>
>> > Well, the example you linked to is based on 3.6, and things have
>> > changed assuming you're using 4.0.
>> >
>> > It's probably that your ContentFilter isn't implementing what it needs
>> > to
>> > or it's not subclassing from the correct class for 4.0.
>> >
>> > Maybe take a look at something simple like LowerCaseFilterFactory
>> > and use that as a model, although you probably don't need to implement
>> > the MultiTermAware bit.
>> >
>> > FWIW,
>> > Erick
>> >
>> >
>> > On Thu, Nov 7, 2013 at 1:31 PM, Dileepa Jayakody
>> > <di...@gmail.com>wrote:
>> >
>> > > Hi All,
>> > >
>> > > I'm  a novice in Solr and I'm continuously bumping into problems with
>> my
>> > > custom filter I'm trying to use for analyzing a fieldType during
>> indexing
>> > > as below;
>> > >
>> > > <fieldType name="stanbolRequestType" class="solr.TextField">
>> > >   <analyzer type="index">
>> > >     <tokenizer class="solr.KeywordTokenizerFactory"/>
>> > >     <filter class= "com.solr.test.analyzer.ContentFilterFactory"/>
>> > >   </analyzer>
>> > > </fieldType>
>> > >
>> > > Below is my custom FilterFactory class;
>> > >
>> > > *public class ContentFilterFactory extends TokenFilterFactory {*
>> > >
>> > > * public ContentFilterFactory() {*
>> > > * super();*
>> > > * }*
>> > >
>> > > * @Override*
>> > > * public TokenStream create(TokenStream input) {*
>> > > * return new ContentFilter(input);*
>> > > * }*
>> > > *}*
>> > >
>> > > I'm getting below error stack trace [1] caused by a
>> NoSuchMethodException
>> > > when starting the server.
>> > > Solr complains that it cannot init the Plugin (my custom filter)  as
>> the
>> > > FilterFactory class doesn't have a init method; But in the example [2]
>> I
>> > > was following didn't have any notion of a init method in the
>> > FilterFactory
>> > > class, nor I was required to override an init method when extending
>> > > TokenFilterFactory class.
>> > >
>> > > Can someone please help me resolve this error and get my custom filter
>> > > working?
>> > >
>> > > Thanks,
>> > > Dileepa
>> > >
>> > > [1]
>> > > Caused by: org.apache.solr.common.SolrException: Plugin init failure
>> for
>> > > [schema.xml] fieldType "stanbolRequestType": Plugin init failure for
>> > > [schema.xml] analyzer/filter: Error instantiating class:
>> > > 'com.solr.test.analyzer.ContentFilterFactory'
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.util.plugin.AbstractPluginLoader.load(
>> AbstractPluginLoader.java:177)
>> > > at org.apache.solr.schema.IndexSchema.readSchema(
>> IndexSchema.java:468)
>> > > ... 13 more
>> > > Caused by: org.apache.solr.common.SolrException: Plugin init failure
>> for
>> > > [schema.xml] analyzer/filter: Error instantiating class:
>> > > 'com.solr.test.analyzer.ContentFilterFactory'
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.util.plugin.AbstractPluginLoader.load(
>> AbstractPluginLoader.java:177)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(
>> FieldTypePluginLoader.java:400)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.schema.FieldTypePluginLoader.create(
>> FieldTypePluginLoader.java:95)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.schema.FieldTypePluginLoader.create(
>> FieldTypePluginLoader.java:43)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.util.plugin.AbstractPluginLoader.load(
>> AbstractPluginLoader.java:151)
>> > > ... 14 more
>> > > Caused by: org.apache.solr.common.SolrException: Error instantiating
>> > class:
>> > > 'com.solr.test.analyzer.ContentFilterFactory'
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.core.SolrResourceLoader.newInstance(
>> SolrResourceLoader.java:556)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.schema.FieldTypePluginLoader$3.
>> create(FieldTypePluginLoader.java:382)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.schema.FieldTypePluginLoader$3.
>> create(FieldTypePluginLoader.java:376)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.util.plugin.AbstractPluginLoader.load(
>> AbstractPluginLoader.java:151)
>> > > ... 18 more
>> > > Caused by: java.lang.NoSuchMethodException:
>> > > com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
>> > > at java.lang.Class.getConstructor0(Class.java:2810)
>> > > at java.lang.Class.getConstructor(Class.java:1718)
>> > > at
>> > >
>> > >
>> >
>> org.apache.solr.core.SolrResourceLoader.newInstance(
>> SolrResourceLoader.java:552)
>> > > ... 21 more
>> > >
>> > > [2] http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/
>> > >
>> >
>>
>>
>

Re: Error instantiating a Custom Filter in Solr

Posted by Jack Krupansky <ja...@basetechnology.com>.
Thanks for the plug Erick, but my deep dive doesn't go quite that deep 
(yet.)

But I'm sure a 2,500 page book on how to develop all manner of custom Solr 
plugin would indeed be valuable though.

But I do have plenty of example of using the many builtin Solr analysis 
filters.

-- Jack Krupansky

-----Original Message----- 
From: Erick Erickson
Sent: Friday, November 08, 2013 10:36 AM
To: solr-user@lucene.apache.org
Subject: Re: Error instantiating a Custom Filter in Solr

Well, I think Jack Krupansky's book has some examples, at $10 it's probably
a steal.

Best,
Erick




On Fri, Nov 8, 2013 at 1:49 AM, Dileepa Jayakody
<di...@gmail.com>wrote:

> Hi Erick,
>
> Thanks a lot for the pointer.
> I looked at the LowerCaseFilterFactory class [1] and it's parent abstract
> class AbstractAnalysisFactory API [2] , and modified my custom filter
> factory class as below;
>
> public class ContentFilterFactory extends TokenFilterFactory {
>
> public ContentFilterFactory() {
> super();
> }
>
> @Override
> public void init(Map<String, String> args) {
> super.init(args);
> }
>
> @Override
> public ContentFilter create(TokenStream input) {
> assureMatchVersion();
> return new ContentFilter(input);
> }
> }
>
> I have called the parent's init method as above, but I'm still getting the
> same error of : java.lang.NoSuchMethodException: com.solr.test.analyzer.
> ContentFilterFactory.<init>(java.util.Map)
>
> Any input on this?
> Can some one please point me to a doc/blog or any sample to implement a
> custom filter with Solr > 4.0
> I'm using Solr 4.5.0 server.
>
> Thanks,
> Dileepa
>
> [1]
>
> http://search-lucene.com/c/Lucene:analysis/common/src/java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java
> [2]
>
> https://lucene.apache.org/core/4_2_0/analyzers-common/org/apache/lucene/analysis/util/AbstractAnalysisFactory.html
>
>
> On Fri, Nov 8, 2013 at 4:25 AM, Erick Erickson <erickerickson@gmail.com
> >wrote:
>
> > Well, the example you linked to is based on 3.6, and things have
> > changed assuming you're using 4.0.
> >
> > It's probably that your ContentFilter isn't implementing what it needs 
> > to
> > or it's not subclassing from the correct class for 4.0.
> >
> > Maybe take a look at something simple like LowerCaseFilterFactory
> > and use that as a model, although you probably don't need to implement
> > the MultiTermAware bit.
> >
> > FWIW,
> > Erick
> >
> >
> > On Thu, Nov 7, 2013 at 1:31 PM, Dileepa Jayakody
> > <di...@gmail.com>wrote:
> >
> > > Hi All,
> > >
> > > I'm  a novice in Solr and I'm continuously bumping into problems with
> my
> > > custom filter I'm trying to use for analyzing a fieldType during
> indexing
> > > as below;
> > >
> > > <fieldType name="stanbolRequestType" class="solr.TextField">
> > >   <analyzer type="index">
> > >     <tokenizer class="solr.KeywordTokenizerFactory"/>
> > >     <filter class= "com.solr.test.analyzer.ContentFilterFactory"/>
> > >   </analyzer>
> > > </fieldType>
> > >
> > > Below is my custom FilterFactory class;
> > >
> > > *public class ContentFilterFactory extends TokenFilterFactory {*
> > >
> > > * public ContentFilterFactory() {*
> > > * super();*
> > > * }*
> > >
> > > * @Override*
> > > * public TokenStream create(TokenStream input) {*
> > > * return new ContentFilter(input);*
> > > * }*
> > > *}*
> > >
> > > I'm getting below error stack trace [1] caused by a
> NoSuchMethodException
> > > when starting the server.
> > > Solr complains that it cannot init the Plugin (my custom filter)  as
> the
> > > FilterFactory class doesn't have a init method; But in the example [2]
> I
> > > was following didn't have any notion of a init method in the
> > FilterFactory
> > > class, nor I was required to override an init method when extending
> > > TokenFilterFactory class.
> > >
> > > Can someone please help me resolve this error and get my custom filter
> > > working?
> > >
> > > Thanks,
> > > Dileepa
> > >
> > > [1]
> > > Caused by: org.apache.solr.common.SolrException: Plugin init failure
> for
> > > [schema.xml] fieldType "stanbolRequestType": Plugin init failure for
> > > [schema.xml] analyzer/filter: Error instantiating class:
> > > 'com.solr.test.analyzer.ContentFilterFactory'
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> > > at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:468)
> > > ... 13 more
> > > Caused by: org.apache.solr.common.SolrException: Plugin init failure
> for
> > > [schema.xml] analyzer/filter: Error instantiating class:
> > > 'com.solr.test.analyzer.ContentFilterFactory'
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:95)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> > > ... 14 more
> > > Caused by: org.apache.solr.common.SolrException: Error instantiating
> > class:
> > > 'com.solr.test.analyzer.ContentFilterFactory'
> > > at
> > >
> > >
> >
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> > > ... 18 more
> > > Caused by: java.lang.NoSuchMethodException:
> > > com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
> > > at java.lang.Class.getConstructor0(Class.java:2810)
> > > at java.lang.Class.getConstructor(Class.java:1718)
> > > at
> > >
> > >
> >
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:552)
> > > ... 21 more
> > >
> > > [2] http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/
> > >
> >
> 


Re: Error instantiating a Custom Filter in Solr

Posted by Erick Erickson <er...@gmail.com>.
Well, I think Jack Krupansky's book has some examples, at $10 it's probably
a steal.

Best,
Erick




On Fri, Nov 8, 2013 at 1:49 AM, Dileepa Jayakody
<di...@gmail.com>wrote:

> Hi Erick,
>
> Thanks a lot for the pointer.
> I looked at the LowerCaseFilterFactory class [1] and it's parent abstract
> class AbstractAnalysisFactory API [2] , and modified my custom filter
> factory class as below;
>
> public class ContentFilterFactory extends TokenFilterFactory {
>
> public ContentFilterFactory() {
> super();
> }
>
> @Override
> public void init(Map<String, String> args) {
> super.init(args);
> }
>
> @Override
> public ContentFilter create(TokenStream input) {
> assureMatchVersion();
> return new ContentFilter(input);
> }
> }
>
> I have called the parent's init method as above, but I'm still getting the
> same error of : java.lang.NoSuchMethodException: com.solr.test.analyzer.
> ContentFilterFactory.<init>(java.util.Map)
>
> Any input on this?
> Can some one please point me to a doc/blog or any sample to implement a
> custom filter with Solr > 4.0
> I'm using Solr 4.5.0 server.
>
> Thanks,
> Dileepa
>
> [1]
>
> http://search-lucene.com/c/Lucene:analysis/common/src/java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java
> [2]
>
> https://lucene.apache.org/core/4_2_0/analyzers-common/org/apache/lucene/analysis/util/AbstractAnalysisFactory.html
>
>
> On Fri, Nov 8, 2013 at 4:25 AM, Erick Erickson <erickerickson@gmail.com
> >wrote:
>
> > Well, the example you linked to is based on 3.6, and things have
> > changed assuming you're using 4.0.
> >
> > It's probably that your ContentFilter isn't implementing what it needs to
> > or it's not subclassing from the correct class for 4.0.
> >
> > Maybe take a look at something simple like LowerCaseFilterFactory
> > and use that as a model, although you probably don't need to implement
> > the MultiTermAware bit.
> >
> > FWIW,
> > Erick
> >
> >
> > On Thu, Nov 7, 2013 at 1:31 PM, Dileepa Jayakody
> > <di...@gmail.com>wrote:
> >
> > > Hi All,
> > >
> > > I'm  a novice in Solr and I'm continuously bumping into problems with
> my
> > > custom filter I'm trying to use for analyzing a fieldType during
> indexing
> > > as below;
> > >
> > > <fieldType name="stanbolRequestType" class="solr.TextField">
> > >   <analyzer type="index">
> > >     <tokenizer class="solr.KeywordTokenizerFactory"/>
> > >     <filter class= "com.solr.test.analyzer.ContentFilterFactory"/>
> > >   </analyzer>
> > > </fieldType>
> > >
> > > Below is my custom FilterFactory class;
> > >
> > > *public class ContentFilterFactory extends TokenFilterFactory {*
> > >
> > > * public ContentFilterFactory() {*
> > > * super();*
> > > * }*
> > >
> > > * @Override*
> > > * public TokenStream create(TokenStream input) {*
> > > * return new ContentFilter(input);*
> > > * }*
> > > *}*
> > >
> > > I'm getting below error stack trace [1] caused by a
> NoSuchMethodException
> > > when starting the server.
> > > Solr complains that it cannot init the Plugin (my custom filter)  as
> the
> > > FilterFactory class doesn't have a init method; But in the example [2]
> I
> > > was following didn't have any notion of a init method in the
> > FilterFactory
> > > class, nor I was required to override an init method when extending
> > > TokenFilterFactory class.
> > >
> > > Can someone please help me resolve this error and get my custom filter
> > > working?
> > >
> > > Thanks,
> > > Dileepa
> > >
> > > [1]
> > > Caused by: org.apache.solr.common.SolrException: Plugin init failure
> for
> > > [schema.xml] fieldType "stanbolRequestType": Plugin init failure for
> > > [schema.xml] analyzer/filter: Error instantiating class:
> > > 'com.solr.test.analyzer.ContentFilterFactory'
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> > > at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:468)
> > > ... 13 more
> > > Caused by: org.apache.solr.common.SolrException: Plugin init failure
> for
> > > [schema.xml] analyzer/filter: Error instantiating class:
> > > 'com.solr.test.analyzer.ContentFilterFactory'
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:95)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> > > ... 14 more
> > > Caused by: org.apache.solr.common.SolrException: Error instantiating
> > class:
> > > 'com.solr.test.analyzer.ContentFilterFactory'
> > > at
> > >
> > >
> >
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
> > > at
> > >
> > >
> >
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
> > > at
> > >
> > >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> > > ... 18 more
> > > Caused by: java.lang.NoSuchMethodException:
> > > com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
> > > at java.lang.Class.getConstructor0(Class.java:2810)
> > > at java.lang.Class.getConstructor(Class.java:1718)
> > > at
> > >
> > >
> >
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:552)
> > > ... 21 more
> > >
> > > [2] http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/
> > >
> >
>

Re: Error instantiating a Custom Filter in Solr

Posted by Dileepa Jayakody <di...@gmail.com>.
Hi Erick,

Thanks a lot for the pointer.
I looked at the LowerCaseFilterFactory class [1] and it's parent abstract
class AbstractAnalysisFactory API [2] , and modified my custom filter
factory class as below;

public class ContentFilterFactory extends TokenFilterFactory {

public ContentFilterFactory() {
super();
}

@Override
public void init(Map<String, String> args) {
super.init(args);
}

@Override
public ContentFilter create(TokenStream input) {
assureMatchVersion();
return new ContentFilter(input);
}
}

I have called the parent's init method as above, but I'm still getting the
same error of : java.lang.NoSuchMethodException: com.solr.test.analyzer.
ContentFilterFactory.<init>(java.util.Map)

Any input on this?
Can some one please point me to a doc/blog or any sample to implement a
custom filter with Solr > 4.0
I'm using Solr 4.5.0 server.

Thanks,
Dileepa

[1]
http://search-lucene.com/c/Lucene:analysis/common/src/java/org/apache/lucene/analysis/core/LowerCaseFilterFactory.java
[2]
https://lucene.apache.org/core/4_2_0/analyzers-common/org/apache/lucene/analysis/util/AbstractAnalysisFactory.html


On Fri, Nov 8, 2013 at 4:25 AM, Erick Erickson <er...@gmail.com>wrote:

> Well, the example you linked to is based on 3.6, and things have
> changed assuming you're using 4.0.
>
> It's probably that your ContentFilter isn't implementing what it needs to
> or it's not subclassing from the correct class for 4.0.
>
> Maybe take a look at something simple like LowerCaseFilterFactory
> and use that as a model, although you probably don't need to implement
> the MultiTermAware bit.
>
> FWIW,
> Erick
>
>
> On Thu, Nov 7, 2013 at 1:31 PM, Dileepa Jayakody
> <di...@gmail.com>wrote:
>
> > Hi All,
> >
> > I'm  a novice in Solr and I'm continuously bumping into problems with my
> > custom filter I'm trying to use for analyzing a fieldType during indexing
> > as below;
> >
> > <fieldType name="stanbolRequestType" class="solr.TextField">
> >   <analyzer type="index">
> >     <tokenizer class="solr.KeywordTokenizerFactory"/>
> >     <filter class= "com.solr.test.analyzer.ContentFilterFactory"/>
> >   </analyzer>
> > </fieldType>
> >
> > Below is my custom FilterFactory class;
> >
> > *public class ContentFilterFactory extends TokenFilterFactory {*
> >
> > * public ContentFilterFactory() {*
> > * super();*
> > * }*
> >
> > * @Override*
> > * public TokenStream create(TokenStream input) {*
> > * return new ContentFilter(input);*
> > * }*
> > *}*
> >
> > I'm getting below error stack trace [1] caused by a NoSuchMethodException
> > when starting the server.
> > Solr complains that it cannot init the Plugin (my custom filter)  as the
> > FilterFactory class doesn't have a init method; But in the example [2] I
> > was following didn't have any notion of a init method in the
> FilterFactory
> > class, nor I was required to override an init method when extending
> > TokenFilterFactory class.
> >
> > Can someone please help me resolve this error and get my custom filter
> > working?
> >
> > Thanks,
> > Dileepa
> >
> > [1]
> > Caused by: org.apache.solr.common.SolrException: Plugin init failure for
> > [schema.xml] fieldType "stanbolRequestType": Plugin init failure for
> > [schema.xml] analyzer/filter: Error instantiating class:
> > 'com.solr.test.analyzer.ContentFilterFactory'
> > at
> >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> > at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:468)
> > ... 13 more
> > Caused by: org.apache.solr.common.SolrException: Plugin init failure for
> > [schema.xml] analyzer/filter: Error instantiating class:
> > 'com.solr.test.analyzer.ContentFilterFactory'
> > at
> >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> > at
> >
> >
> org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
> > at
> >
> >
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:95)
> > at
> >
> >
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
> > at
> >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> > ... 14 more
> > Caused by: org.apache.solr.common.SolrException: Error instantiating
> class:
> > 'com.solr.test.analyzer.ContentFilterFactory'
> > at
> >
> >
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
> > at
> >
> >
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
> > at
> >
> >
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
> > at
> >
> >
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> > ... 18 more
> > Caused by: java.lang.NoSuchMethodException:
> > com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
> > at java.lang.Class.getConstructor0(Class.java:2810)
> > at java.lang.Class.getConstructor(Class.java:1718)
> > at
> >
> >
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:552)
> > ... 21 more
> >
> > [2] http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/
> >
>

Re: Error instantiating a Custom Filter in Solr

Posted by Erick Erickson <er...@gmail.com>.
Well, the example you linked to is based on 3.6, and things have
changed assuming you're using 4.0.

It's probably that your ContentFilter isn't implementing what it needs to
or it's not subclassing from the correct class for 4.0.

Maybe take a look at something simple like LowerCaseFilterFactory
and use that as a model, although you probably don't need to implement
the MultiTermAware bit.

FWIW,
Erick


On Thu, Nov 7, 2013 at 1:31 PM, Dileepa Jayakody
<di...@gmail.com>wrote:

> Hi All,
>
> I'm  a novice in Solr and I'm continuously bumping into problems with my
> custom filter I'm trying to use for analyzing a fieldType during indexing
> as below;
>
> <fieldType name="stanbolRequestType" class="solr.TextField">
>   <analyzer type="index">
>     <tokenizer class="solr.KeywordTokenizerFactory"/>
>     <filter class= "com.solr.test.analyzer.ContentFilterFactory"/>
>   </analyzer>
> </fieldType>
>
> Below is my custom FilterFactory class;
>
> *public class ContentFilterFactory extends TokenFilterFactory {*
>
> * public ContentFilterFactory() {*
> * super();*
> * }*
>
> * @Override*
> * public TokenStream create(TokenStream input) {*
> * return new ContentFilter(input);*
> * }*
> *}*
>
> I'm getting below error stack trace [1] caused by a NoSuchMethodException
> when starting the server.
> Solr complains that it cannot init the Plugin (my custom filter)  as the
> FilterFactory class doesn't have a init method; But in the example [2] I
> was following didn't have any notion of a init method in the FilterFactory
> class, nor I was required to override an init method when extending
> TokenFilterFactory class.
>
> Can someone please help me resolve this error and get my custom filter
> working?
>
> Thanks,
> Dileepa
>
> [1]
> Caused by: org.apache.solr.common.SolrException: Plugin init failure for
> [schema.xml] fieldType "stanbolRequestType": Plugin init failure for
> [schema.xml] analyzer/filter: Error instantiating class:
> 'com.solr.test.analyzer.ContentFilterFactory'
> at
>
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:468)
> ... 13 more
> Caused by: org.apache.solr.common.SolrException: Plugin init failure for
> [schema.xml] analyzer/filter: Error instantiating class:
> 'com.solr.test.analyzer.ContentFilterFactory'
> at
>
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:177)
> at
>
> org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:400)
> at
>
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:95)
> at
>
> org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:43)
> at
>
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> ... 14 more
> Caused by: org.apache.solr.common.SolrException: Error instantiating class:
> 'com.solr.test.analyzer.ContentFilterFactory'
> at
>
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:556)
> at
>
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:382)
> at
>
> org.apache.solr.schema.FieldTypePluginLoader$3.create(FieldTypePluginLoader.java:376)
> at
>
> org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:151)
> ... 18 more
> Caused by: java.lang.NoSuchMethodException:
> com.solr.test.analyzer.ContentFilterFactory.<init>(java.util.Map)
> at java.lang.Class.getConstructor0(Class.java:2810)
> at java.lang.Class.getConstructor(Class.java:1718)
> at
>
> org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:552)
> ... 21 more
>
> [2] http://solr.pl/en/2012/05/14/developing-your-own-solr-filter/
>