我正在使用SolrNet从.NET应用程序搜索Solr。 当我搜索英文单词时,一切正常。但是,如果我 使用西班牙语单词如español
,但我没有收到搜索结果,尽管我已使用 对它们进行了索引。当我通过Solr进行调试时,发现查询 被解析为espaA+ol
。通过SolrNet提供的非英语语言支持
我必须做一些UTF-8编码吗?或者SolrNet是否只支持通过ASCII字符搜索?
我正在使用SolrNet从.NET应用程序搜索Solr。 当我搜索英文单词时,一切正常。但是,如果我 使用西班牙语单词如español
,但我没有收到搜索结果,尽管我已使用 对它们进行了索引。当我通过Solr进行调试时,发现查询 被解析为espaA+ol
。通过SolrNet提供的非英语语言支持
我必须做一些UTF-8编码吗?或者SolrNet是否只支持通过ASCII字符搜索?
不确定是否要特别将这些字符保留在索引中?如果你不需要,它会更好地使用像
<charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
所以“西班牙语”将被索引为“猎犬”和搜索其中的任何会发现“西班牙语”(同一个, ü等)。
这不是一个SolrNet问题,它与Solr如何处理不在第127个ASCII字符集中的字符有关。最好的建议是将ASCIIFoldingFilterFactory添加到您存储西班牙文单词的Solr字段中。
作为一个例子,如果你使用text_general
字段类型如Solr的例子是设置为在Schema.xml文件定义如下:
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
</analyzer>
</fieldType>
我建议修改它如下添加ASCIIFoldingFilterFactory到索引和查询分析器。
<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
<analyzer type="index">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<!-- in this example, we will only use synonyms at query time
<filter class="solr.SynonymFilterFactory" synonyms="index_synonyms.txt" ignoreCase="true" expand="false"/>
-->
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory"/>
</analyzer>
<analyzer type="query">
<tokenizer class="solr.StandardTokenizerFactory"/>
<filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
<filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
<filter class="solr.LowerCaseFilterFactory"/>
<filter class="solr.ASCIIFoldingFilterFactory"/>
</analyzer>
</fieldType>
此外,请注意,您需要在更改此架构后将索引中的更改反映为索引后重新索引数据。
有没有办法将实际的Unicode字符存储到索引中?因为虽然这可能适用于西班牙语,但它会不会对中国人造成严重影响? – soandos
在http://wiki.apache.org/solr/LanguageAnalysis上还有语言特定的分析组件。在大多数情况下,您需要使用特定语言进行测试,并找到适合您需求的正确分析组合。 –
索引工作正常。我可以索引包含西班牙文字符的文档,但使用相同的字符集查询时不会给我提供任何结果,因为它是按照上面解释的方式编码的。 –