Search code examples
solrdismax

{!boost ...} multiplier with dismax query parser


How can I use the q={!boost ...} multiplier with the dismax query parser?

With a standard query, you can do:

?q={!boost b=$multiplier}text:foo
&multiplier=...

However, when I try to do the equivalent for dismax:

?defType=dismax
&q={!boost b=$multiplier}foo
&qf=text
&multiplier=...

I get the following error:

{
  "error": {
    "msg": "no field name specified in query and no default specified via 'df' param",
    "code": 400
  }
}

I'm guessing that specifying {!boost ...} within q overrides defType=dismax and causes the remaining portion of q to be parsed using the standard query parser. How can I use {!boost ...} with dismax?

NOTE: I'm running Solr 4.10.4.


Solution

  • According to Solr Relevancy FAQ § How can I boost the score of newer documents,

    To boost another query parser such as a dismax query, the value of the boost query is a full sub-query and hence can use the {!queryParser} syntax. Alternately, the defType param can be used in the boost local params to set the default type to dismax. The other dismax parameters may be set as top level parameters.

    This means that in order to use dismax (or any other query parser) with the boost query parser, you need to structure the parameters as:

    ?q={!boost b=$multiplier v=$qq}
    &qq={!dismax}foo
    &qf=text
    &multiplier=...
    

    Or:

    ?q={!boost b=$multiplier defType=dismax}foo
    &qf=text
    &multiplier=...