1

我是java新手,但我需要使用solr作为“全文搜索”引擎......我能够安装并成功运行它,但我需要使用“建议组件”

这是我的建议器配置:

<searchComponent name="suggester" class="solr.SpellCheckComponent">
        <lst name="spellchecker" >
            <str name="name">suggester</str>
            <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
            <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookupFactory</str>
            <str name="field">name</str>
            <!-- <str name="threshold">2</str> -->
        </lst>
    </searchComponent>

    <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggester">
        <lst name="defaults">
            <str name="spellcheck"  >true</str>
            <str name="spellcheck.dictionary">suggester</str>
            <str name="spellcheck.count">10</str>
        </lst>
        <arr name="component" >
            <str>suggester</str>
        </arr>
    </requestHandler>

我用命令 java -jar start.jar 运行它(就像这个网站)并得到以下错误

INFO: Closing Searcher@1220b36 main
    fieldValueCache{lookups=0,hits=0,hitratio=0.00,inserts=0,evictions=0,size=0,warmupTime=0,cumulative_lookups=0,cumulative_hits=0,cumulative_hitratio=0.00,cumulative_inserts=0,cumulative_evictions=0}
    filterCache{lookups=0,hits=0,hitratio=0.00,inserts=0,evictions=0,size=0,warmupTime=0,cumulative_lookups=0,cumulative_hits=0,cumulative_hitratio=0.00,cumulative_inserts=0,cumulative_evictions=0}
    queryResultCache{lookups=0,hits=0,hitratio=0.00,inserts=0,evictions=0,size=0,warmupTime=0,cumulative_lookups=0,cumulative_hits=0,cumulative_hitratio=0.00,cumulative_inserts=0,cumulative_evictions=0}
    documentCache{lookups=0,hits=0,hitratio=0.00,inserts=0,evictions=0,size=0,warmupTime=0,cumulative_lookups=0,cumulative_hits=0,cumulative_hitratio=0.00,cumulative_inserts=0,cumulative_evictions=0}
Aug 9, 2012 5:14:32 PM org.apache.solr.common.SolrException log
SEVERE: org.apache.solr.common.SolrException
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:600)
    at org.apache.solr.core.CoreContainer.create(CoreContainer.java:480)
    at org.apache.solr.core.CoreContainer.load(CoreContainer.java:332)
    at org.apache.solr.core.CoreContainer.load(CoreContainer.java:216)
    at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:161)
    at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:96)
    at org.mortbay.jetty.servlet.FilterHolder.doStart(FilterHolder.java:97)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:713)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1282)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:518)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:499)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.jetty.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:156)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerCollection.doStart(HandlerCollection.java:152)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
    at org.mortbay.jetty.Server.doStart(Server.java:224)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.xml.XmlConfiguration.main(XmlConfiguration.java:985)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.mortbay.start.Main.invokeMain(Main.java:194)
    at org.mortbay.start.Main.start(Main.java:534)
    at org.mortbay.start.Main.start(Main.java:441)
    at org.mortbay.start.Main.main(Main.java:119)
Caused by: org.apache.solr.common.SolrException: Error loading class 'org.apache.solr.spelling.suggest.tst.TSTLookupFactory
'
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:394)
    at org.apache.solr.core.SolrResourceLoader.newInstance(SolrResourceLoader.java:409)
    at org.apache.solr.spelling.suggest.Suggester.init(Suggester.java:100)
    at org.apache.solr.handler.component.SpellCheckComponent.inform(SpellCheckComponent.java:598)
    at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:527)
    at org.apache.solr.core.SolrCore.<init>(SolrCore.java:594)
    ... 30 more
Caused by: java.lang.ClassNotFoundException: org.apache.solr.spelling.suggest.tst.TSTLookupFactory

    at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
    at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:615)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:378)
    ... 35 more

我查找了该类,并在 $SOLR_HOME/dist/apache-solr-core-[solr version].jar 中找到了它,因此我尝试使用命令运行 Solr

java -cp $SOLR_HOME/dist/apache-solr-core-3.6.1 -jar start.jar

但我得到了同样的错误

4

2 回答 2

2

您无需自定义任何内容即可使用 Suggester,也无需找到已包含在 Solr 中的类。我将从新下载的 Solr 3.6.1 开始(或者只是恢复您所做的更改)。问题出在您的配置中,其中包含类名称和 xml 元素结尾之间的换行符</str>。这就是 SOlr 找不到该类的原因。只需删除换行符,一切都会奏效!

于 2012-08-10T09:04:36.230 回答
0

TSTLookupFactory应该存在于 solr-core jar 中(至少在版本 3.4.0 中)。您可以通过在 WinRAR 或其他能够打开 RAR 文件的实用程序中打开 jar 文件来手动验证它(如果您使用的是其他版本)并验证它是否位于 org/apache/solr/spelling/suggest/tst 目录中罐子。如果不是,您可能使用的是旧版本的 SOLR,您必须升级。

然后确保 solr-core jar 确实在您的类路径中(以及 lucene-spellchecker jar 和其他 solr/lucene jar)。

于 2012-08-09T10:41:18.043 回答