【问题标题】:Solr exact match regarding words numberSolr 关于字数的完全匹配
【发布时间】:2014-06-21 18:45:23
【问题描述】:

我已经找了一个星期来寻找一些可行的解决方案,以实现以下目标:

文档:[phrase:"cat"]、[phrase:"pussy cat"]、[phrase:"cats"]

搜索查询:“cat” => 结果:“cat”、“cats”(但不是“pussy cat”

搜索查询:“cats” => 结果:“cats”、“cat”(但不是“pussy cat”

我在网上看到了一些关于如何实现这一点的建议。 Somewhere 我看到一个建议,在索引时在字段值的开头和结尾插入标记标记,然后执行包含这些标记标记的“短语查询”。 In other place我看到了一个计算每个文档中唯一术语数量的建议。

我发现第二个建议(计算单词)相当复杂,我不知道如何使用第一个建议。

所以问题是您能否提供有关如何在 Solr 中实现“关于请求的单词编号和使用词干(单词形式)的精确匹配”的提示?

任何想法都会非常感激。

【问题讨论】:

    标签: solr exact-match


    【解决方案1】:

    好吧,我已经解决了如下问题(有前缀和后缀):

    在 solrconfig.xml 中:

    <updateRequestProcessorChain name="exact"> 
        <processor class="solr.CloneFieldUpdateProcessorFactory">
            <str name="source">phrase</str>
            <str name="dest">phraseExact</str>
        </processor>
        <processor class="solr.RegexReplaceProcessorFactory">
            <str name="fieldName">phraseExact</str>
            <str name="pattern">^(.*)$</str>
            <str name="replacement">_prefix_ $1 _suffix_</str>
            <bool name="literalReplacement">false</bool>
        </processor>
        <processor class="solr.LogUpdateProcessorFactory" />
        <processor class="solr.RunUpdateProcessorFactory" />
    </updateRequestProcessorChain>
    <!-- other contents of solrconfig.xml... -->
    <requestHandler name="/update" class="solr.UpdateRequestHandler">
        <lst name="defaults">
            <str name="update.chain">exact</str>
        </lst>
    </requestHandler>
    

    在 schema.xml 中:

    <field name="phrase" type="text_en" indexed="true" stored="true"/>
    <field name="phraseExact" type="text_en" indexed="true" stored="true"/>
    

    更改后需要重新启动 Solr 实例,然后重新索引(重新添加)所有文档。

    现在我们有这样的文件:

    {
        "phrase": "test",
        "id": "9c95fac2ed78149c",
        "phraseExact": "_prefix_ test _suffix_",
        "_version_": 1471599816879374300
     },
     {
        "phrase": "test phrase",
        "id": "9c95fac2ed78123c",
        "phraseExact": "_prefix_ test phrase _suffix_",
        "_version_": 1471599816123474300
     },
    

    如果通过类似查询来搜索文档

    "q=phraseExact:"_prefix_ test _suffix_"
    "q=phraseExact:"_prefix_ testing _suffix_"
    "q=phraseExact:"_prefix_ tests _suffix_"
    

    我们只会收到 {"phrase":"test"} 文档(而不是 {"phrase":"test phrase"})

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多