Solr 通配符搜索 [英] Solr wildcard searching

查看:31
本文介绍了Solr 通配符搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个包含关键字 Chris Muench 的记录,我希望能够匹配 Mue 或 Chr.我如何使用 solr 查询来做到这一点.目前我执行以下操作:

If I have a record with keywords Chris Muench, I want to be able to match Mue or Chr. How can I do this with a solr query. Currently I do the following:

$results = $solr->search('"'.Apache_Solr_Service::escape($_GET['textsearch']).'"~100', 0, 100, array('fq' => 'type:datacollection'));

它不匹配 Mue 或 Chr,但它匹配 Muench

It doesn't match Mue or Chr, but it does match Muench

架构:

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="rocdocs" version="1.4">
  <types>
    <!-- The StrField type is not analyzed, but indexed/stored verbatim. -->
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" omitNorms="true" positionIncrementGap="0"/>
    <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>
 </types>


 <fields>
    <field name="type" type="string" indexed="true" stored="true" required="true" />
    <field name="mongo_id" type="string" indexed="true" stored="true" required="true" />
    <field name="nid" type="int" indexed="true" stored="true" required="true" />
    <field name="keywords" type="text_general" indexed="true" stored="false" />
 </fields>

 <!-- Field to use to determine and enforce document uniqueness. 
      Unless this field is marked with required="false", it will be a required field
   -->
 <uniqueKey>mongo_id</uniqueKey>

 <!-- field for the QueryParser to use when an explicit fieldname is absent -->
 <defaultSearchField>keywords</defaultSearchField>
 <!-- SolrQueryParser configuration: defaultOperator="AND|OR" -->
 <solrQueryParser defaultOperator="OR"/>
</schema>

推荐答案

您需要使用 通配符查询 例如chr* 或 mue* 匹配.
这将使客户端以这种格式输入查询或在应用程序中修改它.
否则,您可以使用 solr.EdgeNGramFilterFactory 生成令牌,这将匹配记录.例如chris 会生成 ch, chr, chri, chris ,因此会匹配所有这些组合.

You need to either use wildcard queries e.g. chr* or mue* which would match.
This would either client to either enter the query in this format or modifying it in the application.
Else, you can generate tokens using solr.EdgeNGramFilterFactory and this would match the records. e.g. chris would generate ch, chr, chri, chris and hence would match all these combination.

这篇关于Solr 通配符搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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