如何在Solr中进行部分搜索?

huangapple go评论58阅读模式
英文:

How to do partial search with Solr?

问题

我有一份在Solr中索引的数据,类似于"S-1234567890"。
如果我尝试使用完整值进行搜索,它会返回结果。
但是,当使用67890*进行搜索时,它不起作用。

您能否帮忙,如何在给定部分文本搜索时搜索数据?

英文:

I have a data indexed in Solr, like "S-1234567890".
If I try to search with full value it gives result.
But when search with 67890*, it does not work.

Can you please help, how to search the data when give partial text search?

答案1

得分: 1

尝试使用以下字段类型来定义您的字段。

字段类型定义

<fieldType name="text_ngrm" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="50"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>

您可以按以下方式定义字段

<field name="name" type="text_ngrm" indexed="true" stored="true"/>

您还可以尝试使用以下内容

<fieldType name="text_ngrm" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
        <filter class="solr.NGramFilterFactory" minGramSize="1" maxGramSize="50"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <filter class="solr.LowerCaseFilterFactory"/>
    </analyzer>
</fieldType>
英文:

Try by using the below fieldtype for your field.

Field type defination

&lt;fieldType name=&quot;text_ngrm&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;&gt;
    &lt;analyzer type=&quot;index&quot;&gt;
       &lt;tokenizer class=&quot;solr.WhitespaceTokenizerFactory&quot;/&gt;
        &lt;filter class=&quot;solr.NGramFilterFactory&quot; minGramSize=&quot;1&quot; maxGramSize=&quot;50&quot;/&gt;
        &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
     &lt;/analyzer&gt;
     &lt;analyzer type=&quot;query&quot;&gt;
       &lt;tokenizer class=&quot;solr.WhitespaceTokenizerFactory&quot;/&gt;
       &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
     &lt;/analyzer&gt;
     &lt;/fieldType&gt;

You can define fields as below

&lt;field name=&quot;name&quot; type=&quot;text_ngrm&quot; indexed=&quot;true&quot; stored=&quot;true&quot;/&gt;

You can also try to use below as well

&lt;fieldType name=&quot;text_ngrm&quot; class=&quot;solr.TextField&quot; positionIncrementGap=&quot;100&quot;&gt;
        &lt;analyzer type=&quot;index&quot;&gt;
           &lt;tokenizer class=&quot;solr.WhitespaceTokenizerFactory&quot;/&gt;
            &lt;filter class=&quot;solr.NGramFilterFactory&quot; minGramSize=&quot;1&quot; maxGramSize=&quot;50&quot;/&gt;
            &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
         &lt;/analyzer&gt;
         &lt;analyzer type=&quot;query&quot;&gt;
          &lt;tokenizer class=&quot;solr.KeywordTokenizerFactory&quot;/&gt;
           &lt;filter class=&quot;solr.LowerCaseFilterFactory&quot;/&gt;
         &lt;/analyzer&gt;
      &lt;/fieldType&gt;

huangapple
  • 本文由 发表于 2020年9月9日 17:29:58
  • 转载请务必保留本文链接:https://go.coder-hub.com/63808747.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定