将我自己的 类 添加到 solr 5.3.1

Adding my own classes to solr 5.3.1

我想将基于 solr 的应用程序从 Solr 4 更新到 Solr 5.3.1

我刚刚发现,自从 Solr 5.2 以来,不再可能 运行 将 Solr 作为 WebApp。 因此,不是将项目(使用 solr 作为 Maven 依赖项)打包为 WAR 并使用单独的 Jetty 运行 将其打包,现在我需要将源代码放入 Solr。 但是我该怎么做呢?

我尝试将我的项目打包为 JAR 并将其放入文件夹 /solr-5.3.1/contrib/mySearchApplication/lib/mysearch.jar 并在 solrconfig.xml <lib dir="${solr.install.dir:../../../..}/contrib/mySearchApplication/lib" regex=".*\.jar" /> 中添加了此路径但是当我尝试 运行 Solr 它仍然找不到我的 类,例如我的自定义令牌过滤器。

那么如何将我的 java 类 添加到 solr?

我收到此错误消息:

ERROR (coreLoadExecutor-6-thread-1) [ ] o.a.s.c.CoreContainer Error creating core [myCollection]: Could not load conf for core myCollection: Plugin init failure for [schema.xml] fieldType "text_en": Plugin init failure for [schema.xml] analyzer/filter: Error loading class 'com.mySearchApplication.lucene.analysis.pattern.SplitOnPatternFilterFactory'. Schema file is /var/tmp/solr/myCollection/conf/schema.xml org.apache.solr.common.SolrException: Could not load conf for core myCollection: Plugin init failure for [schema.xml] fieldType "text_en": Plugin init failure for [schema.xml] analyzer/filter: Error loading class 'com.mySearchApplication.lucene.analysis.pattern.SplitOnPatternFilterFactory'. Schema file is /var/tmp/solr/myCollection/conf/schema.xml at org.apache.solr.core.ConfigSetService.getConfig(ConfigSetService.java:80) at org.apache.solr.core.CoreContainer.create(CoreContainer.java:721) at org.apache.solr.core.CoreContainer.call(CoreContainer.java:443) at org.apache.solr.core.CoreContainer.call(CoreContainer.java:434) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at org.apache.solr.common.util.ExecutorUtil$MDCAwareThreadPoolExecutor.run(ExecutorUtil.java:210) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.solr.common.SolrException: Plugin init failure for [schema.xml] fieldType "text_en": Plugin init failure for [schema.xml] analyzer/filter: Error loading class 'com.mySearchApplication.lucene.analysis.pattern.SplitOnPatternFilterFactory'. Schema file is /var/tmp/solr/myCollection/conf/schema.xml at org.apache.solr.schema.IndexSchema.readSchema(IndexSchema.java:596) at org.apache.solr.schema.IndexSchema.<init>(IndexSchema.java:175) at org.apache.solr.schema.IndexSchemaFactory.create(IndexSchemaFactory.java:55) at org.apache.solr.schema.IndexSchemaFactory.buildIndexSchema(IndexSchemaFactory.java:69) at org.apache.solr.core.ConfigSetService.createIndexSchema(ConfigSetService.java:104) at org.apache.solr.core.ConfigSetService.getConfig(ConfigSetService.java:75) ... 8 more

您可以将 sharedLib 参数添加到 solr.xml 文件中。

This parameter specifies the path to a common library directory that will be shared across all cores. Any JAR files in this directory will be added to the search path for Solr plugins. This path is relative to the top-level container's Solr Home.

我是这样做的。

<?xml version='1.0' encoding='UTF-8'?>
<solr>
      <str name='sharedLib'>/opt/shared-lib</str>

      <solrcloud>
          <str name="host">${host:}</str>
          <int name="hostPort">${hostPort:8080}</int>
          <str name="hostContext">${hostContext:solr}</str>
          <int name="zkClientTimeout">${zkClientTimeout:15000}</int>
          <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>
      </solrcloud>

      <shardHandlerFactory name="shardHandlerFactory"
          class="HttpShardHandlerFactory">
          <int name="socketTimeout">${socketTimeout:0}</int>
          <int name="connTimeout">${connTimeout:0}</int>
      </shardHandlerFactory>

</solr>

在 Windows solr.xml 中可能如下所示:

<solr>
  <str name='sharedLib'>F:\solr_deployment\solr-7.6.0\contrib\analysis-extras\lucene-libs</str>

  <solrcloud>

    <str name="host">${host:}</str>
    <int name="hostPort">${jetty.port:8983}</int>
    <str name="hostContext">${hostContext:solr}</str>

    <bool name="genericCoreNodeNames">${genericCoreNodeNames:true}</bool>

    <int name="zkClientTimeout">${zkClientTimeout:30000}</int>
    <int name="distribUpdateSoTimeout">${distribUpdateSoTimeout:600000}</int>
    <int name="distribUpdateConnTimeout">${distribUpdateConnTimeout:60000}</int>
    <str name="zkCredentialsProvider">${zkCredentialsProvider:org.apache.solr.common.cloud.DefaultZkCredentialsProvider}</str>
    <str name="zkACLProvider">${zkACLProvider:org.apache.solr.common.cloud.DefaultZkACLProvider}</str>

  </solrcloud>

  <shardHandlerFactory name="shardHandlerFactory"
    class="HttpShardHandlerFactory">
    <int name="socketTimeout">${socketTimeout:600000}</int>
    <int name="connTimeout">${connTimeout:60000}</int>
  </shardHandlerFactory>

</solr>

或者,solrconfig.xml 文件中可能有:

<config>
        <luceneMatchVersion>7.6.0</luceneMatchVersion>

        <lib dir="${solr.install.dir:../../../..}/contrib/extraction/lib" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-cell-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/clustering/lib/" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-clustering-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/langid/lib/" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-langid-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/velocity/lib" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-velocity-\d.*\.jar" />

        <lib dir="${solr.install.dir:../../../..}/contrib/analysis-extras/lucene-libs" regex=".*\.jar" />
        <lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-analysis-\d.*\.jar" />
...
</config>