本文介绍了SOLR不区分大小写的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SOLR搜索中遇到问题。
我有这样的数据:

I've a problem in SOLR Search.
I have a data like this:

我使用solr admin使用如下查询来查找此数据:

I use solr admin to find this data using query like this:

address_s:*Nadi*

并找到了这些数据。但是当我使用以下查询时:

and found those data. But when I use this query:

address_s:*nadi*

什么都没找到。
我已经在Google上进行了搜索,找到了使用以下脚本创建字段的答案:

it doesn't found anything.
I've googling and I found an answer to create a field with the following script:

<fieldType name="c_text" class="solr.TextField">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>

    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

我已将这些脚本复制粘贴到schema.xml中,但仍然无法正常工作。我该怎么办?有人可以帮我吗?

I've copy paste those script into schema.xml, but it still doesn't work. What should I do? Can anyone help me?

推荐答案

address_s字段应定义为-

The address_s field should be defined as -

<field name="address_s" type="c_text" indexed="true" stored="true"/>

如果您使用默认的schema.xml,则此定义应在-

If you are using the default schema.xml, this defination should come before -

<dynamicField name="*_s"  type="string"  indexed="true"  stored="true"/>

将其定义为不执行分析的字符串字段类型。

which defines it as a string field type with no analysis performed.

通配符查询不会进行分析。

因此,如果在索引时间查询中应用小写过滤器 address_s:* nadi *

但是,查询 address_s:* Nadi *不会,因为 Nadi 与索引中的 nadi 不匹配,则需要在客户端查询小写。

Wildcard queries does not undergo analysis.
So if you apply lower case filter at index time query address_s:*nadi* would work.
However, query address_s:*Nadi* would not, as Nadi will not match nadi in index and you would need to lower case the queries at client side.

这篇关于SOLR不区分大小写的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 07:27