Casting Exception with Similarity

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Casting Exception with Similarity

Tim Patton
I'm trying toconvert some of my code over to Solr, but I keep getting
class cast exceptions when I try to use my own similarity class, like this:

Caused by: java.lang.ClassCastException:
dealcatcher.kolinka.lucene.similarity.T
estSimilarity cannot be cast to org.apache.lucene.search.Similarity
         at
org.apache.solr.schema.IndexSchema.readConfig(IndexSchema.java:363)
         ... 21 more

Here is TestSimilarity:

package dealcatcher.kolinka.lucene.similarity;

import org.apache.lucene.search.DefaultSimilarity;

public class TestSimilarity extends DefaultSimilarity
{
}

And my schema.xml:


<similarity class="dealcatcher.kolinka.lucene.similarity.TestSimilarity"/>

It works fine if I use:

<similarity class="org.apache.lucene.search.DefaultSimilarity"/>

The jar with my class is located in example/ext, I get a class not found
if I put it elsewhere.  Should I be locating this jar elsewhere?  Do I
need to put lucene-nightly in the same directory?  I also get a class
not found error if lucene isn't located there, which seems strange since
solr should be able to find lucene classes without my help.

Reply | Threaded
Open this post in threaded view
|

Re: Casting Exception with Similarity

Chris Hostetter-3

: class cast exceptions when I try to use my own similarity class, like this:

: public class TestSimilarity extends DefaultSimilarity
: {
: }

I have two alternate guesses

 1) this may be a missleading error message, the real problem may be that
    without a default constructor, it can't instantiate your Similarity.
 2) this may be the behavior when the version of
    Similarity/DefaultSimilarity you compile your class against don't
    match the versions loaded by the JVM solr is running in (i think there
    is a more specific JVM error when that happens though)

...to be safe, add a default constructor, and compile against the
lucene-core jar in the lib directory of the wolr release you are using.

: The jar with my class is located in example/ext, I get a class not found
: if I put it elsewhere.  Should I be locating this jar elsewhere?  Do I

you should create a "lib" directory in your solr.home directory and put
the jar there ... example/ext is where jars you want jetty to load in one
of the really low level class loaders live -- there's no need to put
anything SOlr specific there.

more details are in the solr home readme (example/solr/README.txt) and on
the SolrPlugins wiki...

        http://wiki.apache.org/solr/SolrPlugins

: need to put lucene-nightly in the same directory?  I also get a class

no, that's just because you tried to use example/ext which is loaded well
before hte solr.war, so in order for you to put your jar in example/ext,
everything else you jar refrences needs to be there as well.


-Hoss

Reply | Threaded
Open this post in threaded view
|

Re: Casting Exception with Similarity

Tim Patton
Chris,

I figured out my problem.  My own jar must be in the examples/solr/lib
directory (which does not exist in the download).  I found a hint to
this on the mailing list.  The docs don't indicate this anywhere
promenant.  Perhaps the lib directory should exist in the default
download in the future?

Tim

Chris Hostetter wrote:

> : class cast exceptions when I try to use my own similarity class, like this:
>
> : public class TestSimilarity extends DefaultSimilarity
> : {
> : }
>
> I have two alternate guesses
>
>  1) this may be a missleading error message, the real problem may be that
>     without a default constructor, it can't instantiate your Similarity.
>  2) this may be the behavior when the version of
>     Similarity/DefaultSimilarity you compile your class against don't
>     match the versions loaded by the JVM solr is running in (i think there
>     is a more specific JVM error when that happens though)
>
> ...to be safe, add a default constructor, and compile against the
> lucene-core jar in the lib directory of the wolr release you are using.
>
> : The jar with my class is located in example/ext, I get a class not found
> : if I put it elsewhere.  Should I be locating this jar elsewhere?  Do I
>
> you should create a "lib" directory in your solr.home directory and put
> the jar there ... example/ext is where jars you want jetty to load in one
> of the really low level class loaders live -- there's no need to put
> anything SOlr specific there.
>
> more details are in the solr home readme (example/solr/README.txt) and on
> the SolrPlugins wiki...
>
> http://wiki.apache.org/solr/SolrPlugins
>
> : need to put lucene-nightly in the same directory?  I also get a class
>
> no, that's just because you tried to use example/ext which is loaded well
> before hte solr.war, so in order for you to put your jar in example/ext,
> everything else you jar refrences needs to be there as well.
>
>
> -Hoss
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Casting Exception with Similarity

Chris Hostetter-3

: I figured out my problem.  My own jar must be in the examples/solr/lib
: directory (which does not exist in the download).  I found a hint to
: this on the mailing list.  The docs don't indicate this anywhere
: promenant.  Perhaps the lib directory should exist in the default
: download in the future?

it's mentioned in both the plugin wiki i listed, as well as the README for
solr.home (example/solr/README.txt) ... do you have any suggestions about
where else we should document it?

we don't include the lib directory in the example solr home because adding
"plugins" is considered a little above and beyond the basic usage .. we
try to keep the example as simple as possible.


-Hoss

Reply | Threaded
Open this post in threaded view
|

Re: Casting Exception with Similarity

Tim Patton


Chris Hostetter wrote:

> : I figured out my problem.  My own jar must be in the examples/solr/lib
> : directory (which does not exist in the download).  I found a hint to
> : this on the mailing list.  The docs don't indicate this anywhere
> : promenant.  Perhaps the lib directory should exist in the default
> : download in the future?
>
> it's mentioned in both the plugin wiki i listed, as well as the README for
> solr.home (example/solr/README.txt) ... do you have any suggestions about
> where else we should document it?
>
> we don't include the lib directory in the example solr home because adding
> "plugins" is considered a little above and beyond the basic usage .. we
> try to keep the example as simple as possible.
>
>
> -Hoss
>
>

Makes sense, I guess I was looking for a mention in the online
documentation for the xml file where it mentions how to specify your own
similarity.  Somehow I never stumbled on the other two spots.

Reply | Threaded
Open this post in threaded view
|

Re: Casting Exception with Similarity

Chris Hostetter-3
:
: Makes sense, I guess I was looking for a mention in the online
: documentation for the xml file where it mentions how to specify your own
: similarity.  Somehow I never stumbled on the other two spots.


Hmmm... you mean http://wiki.apache.org/solr/SchemaXml right?

yeah i can see how that would be a little confusing ... i've made some
updates, feel free to edit the docs further if you think it's still not
clear.


-Hoss

Reply | Threaded
Open this post in threaded view
|

Re: Casting Exception with Similarity

Tim Patton
Sweet, looks like someone beat me to it.

Tim

Chris Hostetter wrote:

> :
> : Makes sense, I guess I was looking for a mention in the online
> : documentation for the xml file where it mentions how to specify your own
> : similarity.  Somehow I never stumbled on the other two spots.
>
>
> Hmmm... you mean http://wiki.apache.org/solr/SchemaXml right?
>
> yeah i can see how that would be a little confusing ... i've made some
> updates, feel free to edit the docs further if you think it's still not
> clear.
>
>
> -Hoss
>
>