magento - 在 Solr (Magento Enterprise) 中将默认运算符从 OR 更改为 AND

标签 magento solr

我在 Magento Enterprise 中使用 Solr。我正在尝试从 OR 更改默认搜索运算符至 AND默认情况下使搜索更具体。

我尝试的第一件事是更改 defaultOperatorschema.xml这没有达到预期的效果(它开始在字段之间使用 AND,而不是关键字)。

<solrQueryParser defaultOperator="AND"/>

然后我读到了 LocalParams并尝试将其添加到几个 requestHandler solrconfig.xml 中的部分(我只是在猜测它应该去哪里,我找不到任何有用的文档)。
<requestHandler name="magento_en" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="q.op">AND</str>

我还在代码( app/core/core/Enterprise/Search )中摸索,硬编码 {!q.op=AND}到查询,但仍然无法让它工作。

我想这是一个简单的配置更改,有人能指出我正确的方向吗?

编辑:澄清一下,搜索“红色夹克”(不带引号)应返回“红色和夹克”的结果。我只对实际上是红色夹克的产品感兴趣,而不是红色鞋子和/或蓝色夹克。手动搜索“红色和夹克”会返回我想要的结果。

目前,搜索执行以下查询:
INFO: [] webapp=/solr path=/select params={start=0&q=articles_title:red+jacket*+articles_summary:red+jacket*+articles_text:red+jacket*+cms_title:red+jacket*+cms_content:red+jacket*&json.nl=map&wt=json&fq=store_id:1+store_id:0&version=1.2&rows=4} hits=7 status=0 QTime=1 
09/01/2013 10:46:21 AM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={spellcheck=true&sort=attr_sort_score_en+desc&spellcheck.extendedResults=true&json.nl=map&wt=json&spellcheck.collate=true&version=1.2&rows=1&fl=id&start=0&q=(Red+jacket)&spellcheck.dictionary=magento_spell_en&q.op=AND&spellcheck.count=2&qt=magento_en&fq=(visibility:3+OR+visibility:4)+AND+store_id:1} hits=645 status=0 QTime=5 
09/01/2013 10:46:21 AM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={facet=on&sort=score+desc&json.nl=map&wt=json&version=1.2&rows=24&fl=id&start=0&facet.query=category_ids:8&facet.query=category_ids:46&facet.query=category_ids:88&facet.query=category_ids:126&facet.query=category_ids:168&facet.query=category_ids:180&facet.query=category_ids:207&facet.query=category_ids:224&facet.query=category_ids:242&facet.query=category_ids:276&q=(Red+jacket)&q.op=AND&facet.field=attr_nav_multi_colourway&qt=magento_en&fq=(visibility:3+OR+visibility:4)+AND+store_id:1} hits=645 status=0 QTime=5 
09/01/2013 10:46:22 AM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={facet=on&sort=attr_sort_score_en+desc&json.nl=map&wt=json&rows=100&version=1.2&start=0&facet.query=category_ids:8&facet.query=category_ids:46&facet.query=category_ids:88&facet.query=category_ids:126&facet.query=category_ids:168&facet.query=category_ids:180&facet.query=category_ids:207&facet.query=category_ids:224&facet.query=category_ids:242&facet.query=category_ids:276&q=(Red+jacket)&q.op=AND&facet.field=attr_nav_multi_colourway&qt=magento_en&fq=(visibility:3+OR+visibility:4)+AND+store_id:1} hits=645 status=0 QTime=6 
09/01/2013 10:46:22 AM org.apache.solr.core.SolrCore execute
INFO: [] webapp=/solr path=/select params={facet=on&sort=attr_sort_score_en+desc&json.nl=map&wt=json&rows=100&version=1.2&start=0&facet.query=category_ids:8&facet.query=category_ids:46&facet.query=category_ids:88&facet.query=category_ids:126&facet.query=category_ids:168&facet.query=category_ids:180&facet.query=category_ids:207&facet.query=category_ids:224&facet.query=category_ids:242&facet.query=category_ids:276&q=(Red+jacket)&q.op=AND&facet.field=attr_nav_multi_colourway&qt=magento_en&fq=(visibility:3+OR+visibility:4)+AND+store_id:1} hits=645 status=0 QTime=3 

最佳答案

感谢 Macilias 在 dismax parser plugin 上的链接我找到了一种使用 solrconfig.xml 中的设置来完成此操作的方法。在这个文件中,有一系列不同语言的 requestHandler 节点。因为我们的商店是英文的,所以我修改了英文版。默认情况下,xml 如下所示:

<requestHandler name="magento_en" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="qf">fulltext_1_en^1.0 fulltext_2_en^2.0 fulltext_3_en^3.0 fulltext_4_en^4.0 fulltext_5_en^5.0</str>
        <str name="pf">fulltext_1_en^1.0 fulltext_2_en^2.0 fulltext_3_en^3.0 fulltext_4_en^4.0 fulltext_5_en^5.0</str>
        <int name="ps">1</int>
        <str name="mm">1</str>
        <str name="defType">dismax</str>
        <str name="echoParams">explicit</str>
        <str name="spellcheck.onlyMorePopular">false</str>
        <str name="spellcheck.extendedResults">false</str>
        <str name="spellcheck.count">1</str>
    </lst>
    <arr name="last-components">
        <str>spellcheck</str>
    </arr>
</requestHandler>

这里的重要参数是“mm”,代表 Minimum 'Should' Match . dismax 解析器使用它而不是默认运算符来确定应如何处理多个搜索词。值为 1 表示只有查询中的一个术语必须匹配(与 OR 的行为相同)。值 100% 表示所有术语都必须匹配(与 AND 的行为相同)。也可以使用更复杂的值。点击上面的链接了解更多信息。更改 solrconfig.xml 文件中的设置后,您需要重新启动 Solr 服务器才能使其生效。

这个视频也是一个很好的Magento Solr资源:http://www.youtube.com/watch?v=07uIJSXdqpU
他们在 24 分钟附近谈论最小匹配。

关于magento - 在 Solr (Magento Enterprise) 中将默认运算符从 OR 更改为 AND,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14226424/

相关文章:

java - 如何在 java 中配置和使用 KStem?

search - Solr splitOnCaseChange 在查询时?

linux - 轻松自动 Magento 存储 DB + 文件 Linux 服务器备份?

javascript - 如果我们点击页面中的任何地方,值就会更新

magento - 如何在magento框架中编辑页 footer 分?

solr - 如何将 Solr 查询转换为 Elasticsearch

Magento 2.1.2 Rourter 操作工厂陷入无限循环

performance - 调整 magento 以提高性能

java - SolrJ - 连接到 Solr 5.5.4 时引发 RemoteSolrException

solr - 更改配置的 maxBooleanClauses 无效