如何使用太阳黑子实现通配符搜索 [英] how to implement wildcard search with sunspot

查看:51
本文介绍了如何使用太阳黑子实现通配符搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

随时欢迎任何帮助我正在将太阳黑子与 solr 一起使用,但找不到任何好的解决方案来说明如何使用太阳黑子执行通配符搜索

any help is always welcome I am using sunspot with solr but not able to find any good solution that how to perform wildcard search with sunspot

如果我搜索 8088***

if i search for 8088***

它应该返回所有以 8088 开头但不是 228088560 的数字

it should return all numbers starts with 8088 but not 228088560

推荐答案

在/solr/conf/schema.xml 中查找以下代码行:

Look for the following lines of code in /solr/conf/schema.xml:

<fieldType name="text" class="solr.TextField" omitNorms="false">
    ...
</fieldType>

并用这个替换它们:

<fieldType name="text" class="solr.TextField" omitNorms="false">
    <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="1" maxGramSize="20" side="front" />
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StandardFilterFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

记得重启solr服务器,并在这些更改后重新索引

Remember to restart the solr server, and reindex after these changes

rake sunspot:solr:stop
rake sunspot:solr:start
rake sunspot:reindex

这篇关于如何使用太阳黑子实现通配符搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆