在 Solr (Magento Enterprise) 中将默认运算符从 OR 更改为 AND [英] Changing the default operator from OR to AND in Solr (Magento Enterprise)

查看:23
本文介绍了在 Solr (Magento Enterprise) 中将默认运算符从 OR 更改为 AND的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Solr with Magento Enterprise. I'm trying to change the default search operator from OR to AND to make searches more specific by default.

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

The first thing I tried was to to change defaultOperator in schema.xml which did not have the desired effect (it started using AND between fields, not keywords).

<solrQueryParser defaultOperator="AND"/>

然后我阅读了 LocalParams 并尝试将其添加到几个 requestHandler solrconfig.xml 中的部分(我只是在猜测它应该去哪里,我找不到任何有用的文档).

I then read about LocalParams and tried adding that to several requestHandler sections in solrconfig.xml (I'm just guessing where it's supposed to go, I can't find any helpful documentation).

<requestHandler name="magento_en" class="solr.SearchHandler">
    <lst name="defaults">
        <str name="q.op">AND</str>

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

I also poked around in the code (app/core/core/Enterprise/Search), hard-coded {!q.op=AND} to the queries but still couldn't get it to work.

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

I imagine it's a simple configuration change, can anyone point me in the right direction?

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

To clarify, a search for "red jacket" (without quotes) should return results for "red AND jacket". I'm only interested in products that are actually red jackets, not red shoes and/or blue jackets. A manual search for "red AND jacket" returns the results that I'm after.

当前搜索执行以下查询:

Currently a search performs these queries:

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 

推荐答案

为了回答我自己的问题,我最终覆盖了 Enterprise_Search_Model_Adapter_HttpStream 模型,将 AND 注入到搜索查询.我添加了 Enterprise_Search_Model_Adapter_Solr_Abstract 中的 prepareSearchConditions() 方法:

To answer my own question, I ended up overriding the Enterprise_Search_Model_Adapter_HttpStream model to inject ANDs into the search query. I added the prepareSearchConditions() method from Enterprise_Search_Model_Adapter_Solr_Abstract:

<?php

class Foo_Search_Model_Adapter_HttpStream extends Enterprise_Search_Model_Adapter_HttpStream
{
    protected function prepareSearchConditions($query)
    {
        $query = str_replace(' ', ' AND ', str_replace(' AND ', ' ', $query));

        return parent::prepareSearchConditions($query);
    }
}

它显然与其他运营商不兼容,但就我而言,它足够好™(至少现在是这样).不过,我仍然希望找到更好的解决方案.

It doesn't play nice with other operators obviously but in my case it's good enough™ (at least for now). I'm still hoping to find a better solution though.

这篇关于在 Solr (Magento Enterprise) 中将默认运算符从 OR 更改为 AND的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆