我正在使用Solr和Magento Enterprise.我试图更改默认的搜索运营商OR,以AND使默认的搜索更加具体.
我想的第一件事就是改变defaultOperator在schema.xml其中并没有收到预期的效果(它开始使用AND字段之间,而不是关键字).
<solrQueryParser defaultOperator="AND"/>
Run Code Online (Sandbox Code Playgroud)
然后我阅读了有关LocalParams的内容,并尝试将其添加到几个requestHandler部分中solrconfig.xml(我只是猜测它应该去哪里,我找不到任何有用的文档).
<requestHandler name="magento_en" class="solr.SearchHandler">
<lst name="defaults">
<str name="q.op">AND</str>
Run Code Online (Sandbox Code Playgroud)
我也在代码(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
Run Code Online (Sandbox Code Playgroud)
小智 13
感谢Macilias在dismax解析器插件上的链接,我找到了一种方法来实现这一点,使用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>
Run Code Online (Sandbox Code Playgroud)
这里的重要参数是"mm",代表最小'应该'匹配.dismax解析器使用它而不是默认运算符来确定应该如何处理多个搜索项.值为1表示查询中只有一个术语必须匹配(与OR相同的行为).值100%表示所有术语必须匹配(与AND相同的行为).也可以使用更复杂的值.请点击上面的链接获取更多信息.更改solrconfig.xml文件中的设置后,您需要重新启动Solr服务器才能生效.
这个视频也是一个很好的Magento Solr资源:http://www.youtube.com/watch?v = 07uIJSXdqpU 他们谈论24分钟左右的最小匹配.
为了回答我自己的问题,我最终重写了模型Enterprise_Search_Model_Adapter_HttpStream以将 s 注入AND到搜索查询中。我添加了prepareSearchConditions()以下方法Enterprise_Search_Model_Adapter_Solr_Abstract:
<?php\n\nclass Foo_Search_Model_Adapter_HttpStream extends Enterprise_Search_Model_Adapter_HttpStream\n{\n protected function prepareSearchConditions($query)\n {\n $query = str_replace(' ', ' AND ', str_replace(' AND ', ' ', $query));\n\n return parent::prepareSearchConditions($query);\n }\n}\nRun Code Online (Sandbox Code Playgroud)\n\n显然,它与其他运算符配合得不好,但就我而言,\xe2\x84\xa2 已经足够好了(至少现在是这样)。但我仍然希望找到更好的解决方案。
\n| 归档时间: |
|
| 查看次数: |
18259 次 |
| 最近记录: |