简体   繁体   English

SOLR:如何在字段值中使用通配符和问号

[英]SOLR: how to use wildcard and question mark in field value

I've read a lot of pages for last few days, but can find any samples for configuring field analizer for following situation: 最近几天我已经阅读了很多页面,但是可以找到用于以下情况的配置现场分析仪的任何示例:
- field value may contain both ? -字段值可能同时包含两者? and *: 和*:

  • abcdef1; abcdef1;
  • ab?de?2; AB德2?;
  • abc?e*. ABC?E *。
- query may contain it too: -查询也可能包含它:
  • "ab??e*" and "ab*"- as result should resolve all documents; “ ab ?? e *”和“ ab *”-结果应解决所有文档;
  • "ab1*" - only second. “ ab1 *”-仅秒。

Is it possible to configure SOLR in that way? 是否可以通过这种方式配置SOLR?

In this case you may need to create your field type and apply the same to your field. 在这种情况下,您可能需要创建字段类型并将其应用于字段。

Your field type should consist of such tokenizer and filter which will generate the tokens. 您的字段类型应包含将生成令牌的此类令牌生成器和过滤器。

You can read more on the use tokenizer and filter on the solr wiki page. 您可以在use tokenizer上阅读更多内容,并在solr Wiki页面上进行过滤。

You can also have different analyzer for indexing and query. 您也可以使用其他分析器来建立索引和查询。

This also depends on your requirement. 这也取决于您的要求。

I would suggest you to try below field type. 我建议您尝试使用以下字段类型。

You can add the below field type in your schema.xml. 您可以在schema.xml中添加以下字段类型。 Use the "partial_search" fieldType for your field(s) where you want to perform the partial/wildcard search. 在要执行部分/通配符搜索的字段中使用“ partial_search” fieldType。

Once you are done with schema.xml changes, you need to do the restart the server ans re-index the data. 完成schema.xml更改后,需要重新启动服务器并重新索引数据。

<fieldType name="partial_search" class="solr.TextField" positionIncrementGap="100">
    <analyzer type="index">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
        <tokenizer class="solr.NGramTokenizerFactory" minGramSize="2" maxGramSize="10"/>
    </analyzer>
    <analyzer type="query">
        <tokenizer class="solr.KeywordTokenizerFactory"/>
    </analyzer>
</fieldType>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM