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 Summer Shire <sh...@gmail.com> on 2014/01/28 01:41:24 UTC

Overriding DefaultSimilarity Cast Exception 4.5.1

Hi all,

I am using Solr and Lucene 4.5.1
and I have a Payload Similarity that extends DefaultSimilarity

my schema.xml specifies the default Similarity tag
<similarity class="<mypackage>.PayloadSimilarity"/>

/** my similarity class**/
public class PayloadSimilarity extends DefaultSimilarity {

    public PayloadSimilarity(){

    }

    @Override
    public float scorePayload(int doc, int start, int end, BytesRef payload) {
        if (payload != null) {
          return PayloadHelper.decodeFloat(payload.bytes, payload.offset);
        } else {
          return 1.0f;
        }
      }

}

there are no compile errors but I get runtime exception

Caused by: java.lang.ClassCastException: <mypackage>.PayloadSimilarity cannot be cast to org.apache.lucene.search.similarities.Similarity
	at org.apache.solr.schema.IndexSchema$1.getSimilarity(IndexSchema.java:929)
	at org.apache.solr.schema.IndexSchema.getSimilarity(IndexSchema.java:257)
	at org.apache.solr.update.SolrIndexConfig.toIndexWriterConfig(SolrIndexConfig.java:219)
	at org.apache.solr.update.SolrIndexWriter.<init>(SolrIndexWriter.java:77)
	at org.apache.solr.update.SolrIndexWriter.create(SolrIndexWriter.java:64)
	at org.apache.solr.update.DefaultSolrCoreState.createMainIndexWriter(DefaultSolrCoreState.java:267)
	at org.apache.solr.update.DefaultSolrCoreState.getIndexWriter(DefaultSolrCoreState.java:110)
	at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1440)



Why would this be happening. if Solr was not able to find my PayloadSimilarity class then the error message would have been different.

any inputs?

thanks,

Summer


Re: Overriding DefaultSimilarity Cast Exception 4.5.1

Posted by Summer Shire <sh...@gmail.com>.
Hi Shawn and Chris,
your inputs Helped I figured it out from all these links and also what Chris mentioned.

Thanks,
Summer

On Jan 27, 2014, at 5:54 PM, Shawn Heisey <so...@elyograg.org> wrote:

> On 1/27/2014 5:41 PM, Summer Shire wrote:
>> Caused by: java.lang.ClassCastException: <mypackage>.PayloadSimilarity cannot be cast to org.apache.lucene.search.similarities.Similarity
>> 	at org.apache.solr.schema.IndexSchema$1.getSimilarity(IndexSchema.java:929)
>> 	at org.apache.solr.schema.IndexSchema.getSimilarity(IndexSchema.java:257)
>> 	at org.apache.solr.update.SolrIndexConfig.toIndexWriterConfig(SolrIndexConfig.java:219)
>> 	at org.apache.solr.update.SolrIndexWriter.<init>(SolrIndexWriter.java:77)
>> 	at org.apache.solr.update.SolrIndexWriter.create(SolrIndexWriter.java:64)
>> 	at org.apache.solr.update.DefaultSolrCoreState.createMainIndexWriter(DefaultSolrCoreState.java:267)
>> 	at org.apache.solr.update.DefaultSolrCoreState.getIndexWriter(DefaultSolrCoreState.java:110)
>> 	at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1440)
> 
> I think there must be incorrect versions of jars in unexpected places, or you're not compiling against the same version of Solr jars as the version you're running, or perhaps theSolr install you've got has old versions of jars hanging around, either from an old extracted .war file or elsewhere on the classpath.
> 
> Here's an old thread:
> 
> http://lucene.472066.n3.nabble.com/Casting-Exception-with-Similarity-td475849.html
> 
> Thanks,
> Shawn
> 


Re: Overriding DefaultSimilarity Cast Exception 4.5.1

Posted by Shawn Heisey <so...@elyograg.org>.
On 1/27/2014 5:41 PM, Summer Shire wrote:
> Caused by: java.lang.ClassCastException: <mypackage>.PayloadSimilarity cannot be cast to org.apache.lucene.search.similarities.Similarity
> 	at org.apache.solr.schema.IndexSchema$1.getSimilarity(IndexSchema.java:929)
> 	at org.apache.solr.schema.IndexSchema.getSimilarity(IndexSchema.java:257)
> 	at org.apache.solr.update.SolrIndexConfig.toIndexWriterConfig(SolrIndexConfig.java:219)
> 	at org.apache.solr.update.SolrIndexWriter.<init>(SolrIndexWriter.java:77)
> 	at org.apache.solr.update.SolrIndexWriter.create(SolrIndexWriter.java:64)
> 	at org.apache.solr.update.DefaultSolrCoreState.createMainIndexWriter(DefaultSolrCoreState.java:267)
> 	at org.apache.solr.update.DefaultSolrCoreState.getIndexWriter(DefaultSolrCoreState.java:110)
> 	at org.apache.solr.core.SolrCore.openNewSearcher(SolrCore.java:1440)

I think there must be incorrect versions of jars in unexpected places, 
or you're not compiling against the same version of Solr jars as the 
version you're running, or perhaps theSolr install you've got has old 
versions of jars hanging around, either from an old extracted .war file 
or elsewhere on the classpath.

Here's an old thread:

http://lucene.472066.n3.nabble.com/Casting-Exception-with-Similarity-td475849.html

Thanks,
Shawn


Re: Overriding DefaultSimilarity Cast Exception 4.5.1

Posted by Summer Shire <sh...@gmail.com>.
Thanks Chris for a quick response.

But I verified that I only have the following jars
lucene-analyzers-common-4.5.1
lucene-core-4.5.1
lucene-queries-4.5.1
lucene-spatial-4.5.1 
solr-solrj-4.5.1

they are all the same version.

Also how can I verify the classpath ? 

Since I do not have other lucene/solr versions I assume it might just be fine.

--additional information 
also I have added a lib tag in my solrconfig.xml
 <lib dir="../../../lib" regex=".*\.jar" /> this points to the path where i have my jar that contains my PayloadSimilarity class
also I see in the logs that 
the file gets added to  org.apache.solr.core.SolrResourceLoader 


On Jan 27, 2014, at 5:32 PM, Chris Hostetter <ho...@fucit.org> wrote:

> 
> : Caused by: java.lang.ClassCastException: <mypackage>.PayloadSimilarity 
> : cannot be cast to org.apache.lucene.search.similarities.Similarity
> 
> If you are getting this error even though you subclass DefaultSimilarity, 
> i suspect that one or both of the following has happened:
> 
> 1) you've compiled your PayloadSimilarity against a different version of 
> solr the lucene/solr jars then what you are running with
> 2) you've got multiple versions of the lucene similarity jars in your 
> classpath at runtime.
> 
> 
> 
> -Hoss
> http://www.lucidworks.com/


Re: Overriding DefaultSimilarity Cast Exception 4.5.1

Posted by Chris Hostetter <ho...@fucit.org>.
: Caused by: java.lang.ClassCastException: <mypackage>.PayloadSimilarity 
: cannot be cast to org.apache.lucene.search.similarities.Similarity

If you are getting this error even though you subclass DefaultSimilarity, 
i suspect that one or both of the following has happened:

1) you've compiled your PayloadSimilarity against a different version of 
solr the lucene/solr jars then what you are running with
2) you've got multiple versions of the lucene similarity jars in your 
classpath at runtime.



-Hoss
http://www.lucidworks.com/