首页 > 解决方案 > 如何用 Solr 搜索汉字?

问题描述

基本上我正在研究 Drupal 并使用 Solr 作为搜索引擎。它搜索一些简体中文单词/字符和一些不像下面的

为美朝朝朝同盟进行的美国取得进展

它不是简单的字符搜索。

所以我经历了两个

https://lucene.apache.org/solr/guide/7_4/language-analysis.html http://www.opencms-wiki.org/wiki/Solr_-_configuration_for_Chinese_and_correct_results_for_german_umlauts

& 在我下面的 solr 配置文件中

<fieldType name="text_chinese" class="solr.TextField">
  <analyzer class="org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer"/>
  <analyzer>
      <tokenizer class="solr.HMMChineseTokenizerFactory"/>
      <filter class="solr.CJKWidthFilterFactory"/>
      <filter class="solr.StopFilterFactory"
              words="org/apache/lucene/analysis/cn/smart/stopwords.txt"/>
      <filter class="solr.PorterStemFilterFactory"/>
      <filter class="solr.LowerCaseFilterFactory"/>
 </analyzer>
</fieldType>

它在给

本地:org.apache.solr.common.SolrException:org.apache.solr.common.SolrException:无法为核心本地加载conf:[schema.xml]字段类型“text_chinese”的插件初始化失败:无法加载分析器:org。 apache.lucene.analysis.cn.smart.SmartChineseAnalyzer。架构文件是 /var/solr/cores/local/conf/schema.xml

仍然没有给出结果。

不确定是否缺少配置中的某些内容。

标签: searchdrupalsolr

解决方案


The error message is telling you that Solr isn't able to find the implementing class of the analyzer you have defined - Cannot load analyzer: org.apache.lucene.analysis.cn.smart.SmartChineseAnalyzer.

The SmartCN analyzer isn't loaded by default, but it's included in the binary build under contrib/analysis-extras/lucene-libs/lucene-analyzers-smartcn-<version number>.jar.

Add the directory to the list of directories that Solr can load libraries from in solrconfig.xml:

<lib dir="../../../contrib/analysis-extras/lucene-libs" regex=".*smartcn.*\.jar" />

推荐阅读