Solr 使用自定义过滤器找不到 BaseTokenFilterFactory

发布于 2024-12-10 14:35:16 字数 2040 浏览 1 评论 0原文

我正在尝试为 Solr 编写和使用自定义过滤器。父应用程序是一个使用 Sunspot gem 的 Rails 应用程序。

我在 myorg/solr/analysis/TestThingFilterFactory.java 中有一个过滤器工厂:

package myorg.solr.analysis;

import org.apache.lucene.analysis.TokenStream;
import org.apache.solr.analysis.BaseTokenFilterFactory;
import myorg.solr.analysis.TestThingFilter;

public class TestThingFilterFactory extends BaseTokenFilterFactory {
  public TestThingFilter create(TokenStream input) {
    return new TestThingFilter(input);
  }
}

myorg/solr/analysis/TestThingFilter.java 中有一个过滤器:

package myorg.solr.analysis;

import java.io.IOException;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;

public class TestThingFilter extends TokenFilter {
  public TestThingFilter(TokenStream input) {
    super(input);
  }

  public boolean incrementToken() throws IOException {
    // ...
  }
}

我编译了这些文件使用 javac -classpath apache-solr-core-3.2.0.jar:lucene-core-3.2.0.jar myorg/solr/analysis/*.java,然后制作从 .class 文件中提取 .jar 文件,并将 .jar 文件放入 Sunspot 的 solr/lib/ 目录中。我修改了 Solr 的 schema.xml 以包含新的过滤器:

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.ASCIIFoldingFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="myorg.solr.analysis.TestThingFilterFactory"/>
  </analyzer>
</fieldType>

重新启动 Solr 并尝试重新索引会在日志中产生此错误:

SEVERE: java.lang.NoClassDefFoundError: org/apache/solr/analysis/BaseTokenFilterFactory
...
Caused by: java.lang.ClassNotFoundException: org.apache.solr.analysis.BaseTokenFilterFactory
...

这是我编译新过滤器代码的方式存在问题,对吧?如何编译才能在运行时找到正确的类?

I'm trying to write and use a custom filter for Solr. The parent application is a Rails app using the Sunspot gem.

I've got a filter factory in myorg/solr/analysis/TestThingFilterFactory.java:

package myorg.solr.analysis;

import org.apache.lucene.analysis.TokenStream;
import org.apache.solr.analysis.BaseTokenFilterFactory;
import myorg.solr.analysis.TestThingFilter;

public class TestThingFilterFactory extends BaseTokenFilterFactory {
  public TestThingFilter create(TokenStream input) {
    return new TestThingFilter(input);
  }
}

and a filter in myorg/solr/analysis/TestThingFilter.java:

package myorg.solr.analysis;

import java.io.IOException;
import org.apache.lucene.analysis.Token;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;

public class TestThingFilter extends TokenFilter {
  public TestThingFilter(TokenStream input) {
    super(input);
  }

  public boolean incrementToken() throws IOException {
    // ...
  }
}

I compiled these files with javac -classpath apache-solr-core-3.2.0.jar:lucene-core-3.2.0.jar myorg/solr/analysis/*.java, then made a .jar file from the .class files and put the .jar file in Sunspot's solr/lib/ directory. I modified Solr's schema.xml to include the new filter:

<fieldType name="text" class="solr.TextField" omitNorms="false">
  <analyzer>
    <tokenizer class="solr.WhitespaceTokenizerFactory"/>
    <filter class="solr.ASCIIFoldingFilterFactory"/>
    <filter class="solr.LowerCaseFilterFactory"/>
    <filter class="myorg.solr.analysis.TestThingFilterFactory"/>
  </analyzer>
</fieldType>

Restarting Solr and trying to reindex produces this error in the logs:

SEVERE: java.lang.NoClassDefFoundError: org/apache/solr/analysis/BaseTokenFilterFactory
...
Caused by: java.lang.ClassNotFoundException: org.apache.solr.analysis.BaseTokenFilterFactory
...

This is a problem with how I compiled the new filter code, right? How do I compile so it can find the right classes at runtime?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帥小哥 2024-12-17 14:35:16

找到了解决方案:包含自定义分析代码的新.jar文件应该放在Rails根目录中的solr/lib/目录,不在出售的太阳黑子宝石内。这是与 conf/ 目录相同的 solr/ 目录。

Found the solution: the new .jar file containing the custom analysis code should go in the solr/lib/ directory in the Rails root directory, not within the vendored Sunspot gem. This is the same solr/ directory that houses the conf/ directory.

秋心╮凉 2024-12-17 14:35:16

根据这篇关于创建 Solr Analysis Filter 的文章,您还需要包括类路径中的 lucene-core-3.2.0.jar 文件。我相信这是定义 BaseTokenFilterFactory 类的地方。

我在 这里找到了 lucene-core jar 文件 如果你需要的话...

According to this post about creating a Solr Analysis Filter you need to also include the lucene-core-3.2.0.jar file in your classpath. I believe this is where the class BaseTokenFilterFactory is defined.

I found the lucene-core jar file here if you need it...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文