Создание собственного анализатора в Solr. Ниже приведен код для пользовательского анализатора и сборка jar с именем lucene-analysis.jar, скопированная в пользовательскую папку.
package com.demo.luceneanalysis;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.LowerCaseFilter;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.core.WhitespaceTokenizer;
import org.apache.lucene.analysis.snowball.SnowballFilter;
public class SnowBallAnalyzer extends Analyzer{
public SnowBallAnalyzer() {
}
@Override
protected TokenStreamComponents createComponents(String fieldName) {
// TODO Auto-generated method stub
final Tokenizer source = new WhitespaceTokenizer();
return new TokenStreamComponents(source, new SnowballFilter
(new LowerCaseFilter(source), "English"));
}
}
[solrconfig.xml]
<lib dir="${solr.install.dir:../../../..}/custom/" regex="lucene-analysis.jar" />
[managed- схема]
<fieldType name="nametext" class="solr.TextField">
<analyzer class="com.demo.luceneanalysis.SnowBallAnalyzer"/>
</fieldType>
при загрузке схемы ниже приведена ошибка.
Caused by: org.apache.solr.common.SolrException: Cannot load analyzer: com.demo.luceneanalysis.SnowBallAnalyzer
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:302)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:104)
at org.apache.solr.schema.FieldTypePluginLoader.create(FieldTypePluginLoader.java:53)
at org.apache.solr.util.plugin.AbstractPluginLoader.load(AbstractPluginLoader.java:152)
... 16 more
Caused by: org.apache.solr.common.SolrException: Error loading class 'com.demo.luceneanalysis.SnowBallAnalyzer'
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:556)
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:487)
at org.apache.solr.schema.FieldTypePluginLoader.readAnalyzer(FieldTypePluginLoader.java:285)
... 19 more
Caused by: java.lang.ClassNotFoundException: com.demo.luceneanalysis.SnowBallAnalyzer
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.net.FactoryURLClassLoader.loadClass(URLClassLoader.java:817)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.apache.solr.core.SolrResourceLoader.findClass(SolrResourceLoader.java:540)
... 21 more