You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucene.apache.org by "Anca Kopetz (JIRA)" <ji...@apache.org> on 2013/11/21 17:10:47 UTC

[jira] [Comment Edited] (SOLR-2649) MM ignored in edismax queries with operators

    [ https://issues.apache.org/jira/browse/SOLR-2649?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13822482#comment-13822482 ] 

Anca Kopetz edited comment on SOLR-2649 at 11/21/13 4:10 PM:
-------------------------------------------------------------

We need to apply Min should match for edismax query strings with operators (AND,OR) and mm parameter.

For example, when the below query was parsed, the mm was not applied
{code}
&q=(((termA AND termB) OR specialTerm) (termC AND termD) (termE))&mm=2&defType=edismax&qf=title
{code}

Therefore we developed our custom query parser.
The code is below, maybe it is useful for somebody who has the same requirements.
{code:title=CustomExtendedDismaxQParser.java}
public class CustomExtendedDismaxQParser extends ExtendedDismaxQParser {
   public CustomExtendedDismaxQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
      super(qstr, localParams, params, req);
   }

   @Override
   protected Query parseOriginalQuery(ExtendedSolrQueryParser up, String mainUserQuery, List<Clause> clauses, ExtendedDismaxConfiguration config) {
      Query query = super.parseOriginalQuery(up, mainUserQuery, clauses, config);
      String mmValue = this.params.get(DisMaxParams.MM);
      if(!Strings.isNullOrEmpty(mmValue)) {
         if (query instanceof BooleanQuery) {
            SolrPluginUtils.setMinShouldMatch((BooleanQuery)query, mmValue);
         }
      }
      return query;
   }
}
{code}

{code:title=solrconfig.xml}
<queryParser name="customEdismax" class="com.kelkoo.search.solr.plugins.CustomExtendedDismaxQParserPlugin"/>
{code}

Then we set defType=customEdismax in the query parameters.

With these configuration, mm is applied on top-level clauses. In our example, there are 3 top-level SHOULD clauses : 
{code} ((termA AND termB) OR specialTerm), (termC AND termD), (termE)
{code}
And the parsed query is : 
{code}
+((
    ((+(title:termA) +(title:termB)) (title:specialTerm)) 
    (+(title:termC) +(title:termD)) 
    (title:termE)
  )~2) 
{code}



was (Author: agh):
We need to apply Min should match for edismax query strings with operators (AND,OR) and mm parameter.
Therefore we developed our custom query parser.
The code is below, maybe it is useful for somebody who has the same requirements.
{code:title=CustomExtendedDismaxQParser.java}
public class CustomExtendedDismaxQParser extends ExtendedDismaxQParser {
   public CustomExtendedDismaxQParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
      super(qstr, localParams, params, req);
   }

   @Override
   protected Query parseOriginalQuery(ExtendedSolrQueryParser up, String mainUserQuery, List<Clause> clauses, ExtendedDismaxConfiguration config) {
      Query query = super.parseOriginalQuery(up, mainUserQuery, clauses, config);
      String mmValue = this.params.get(DisMaxParams.MM);
      if(!Strings.isNullOrEmpty(mmValue)) {
         if (query instanceof BooleanQuery) {
            SolrPluginUtils.setMinShouldMatch((BooleanQuery)query, mmValue);
         }
      }
      return query;
   }
}
{code}

{code:title=solrconfig.xml}
<queryParser name="kelkooEdismax" class="com.kelkoo.search.solr.plugins.CustomExtendedDismaxQParserPlugin"/>
{code}

> MM ignored in edismax queries with operators
> --------------------------------------------
>
>                 Key: SOLR-2649
>                 URL: https://issues.apache.org/jira/browse/SOLR-2649
>             Project: Solr
>          Issue Type: Bug
>          Components: query parsers
>            Reporter: Magnus Bergmark
>            Priority: Minor
>             Fix For: 4.6
>
>
> Hypothetical scenario:
>   1. User searches for "stocks oil gold" with MM set to "50%"
>   2. User adds "-stockings" to the query: "stocks oil gold -stockings"
>   3. User gets no hits since MM was ignored and all terms where AND-ed together
> The behavior seems to be intentional, although the reason why is never explained:
>   // For correct lucene queries, turn off mm processing if there
>   // were explicit operators (except for AND).
>   boolean doMinMatched = (numOR + numNOT + numPluses + numMinuses) == 0; 
> (lines 232-234 taken from tags/lucene_solr_3_3/solr/src/java/org/apache/solr/search/ExtendedDismaxQParserPlugin.java)
> This makes edismax unsuitable as an replacement to dismax; mm is one of the primary features of dismax.



--
This message was sent by Atlassian JIRA
(v6.1#6144)

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@lucene.apache.org
For additional commands, e-mail: dev-help@lucene.apache.org