Solr 使用自定义过滤器找不到 BaseTokenFilterFactory
我正在尝试为 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技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
找到了解决方案:包含自定义分析代码的新
.jar
文件应该放在Rails根目录中的solr/lib/
目录中,不在出售的太阳黑子宝石内。这是与conf/
目录相同的solr/
目录。Found the solution: the new
.jar
file containing the custom analysis code should go in thesolr/lib/
directory in the Rails root directory, not within the vendored Sunspot gem. This is the samesolr/
directory that houses theconf/
directory.根据这篇关于创建 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 classBaseTokenFilterFactory
is defined.I found the lucene-core jar file here if you need it...