0

我已经寻找了一个星期来寻找一些可行的解决方案,这些解决方案将允许以下内容:

文件:[短语:“猫”],[短语:“猫咪”],[短语:“猫”]

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

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

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

我发现第二个建议(带有计算单词)非常复杂,我无法识别如何使用第一个建议。

所以问题是你能给出一个关于如何在 Solr 中实现“关于请求的词数和使用词干(词形)的精确匹配”的提示吗?

任何想法将不胜感激。

4

1 回答 1

0

那么我已经解决了如下问题(带有前缀和后缀):

在 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"})

于 2014-06-22T09:05:58.870 回答