Examples of eDismax Queries
All of the sample URLs in this section assume you are running Solr’s “
Boost the result of the query term "hello" based on the document’s popularity:
Search for iPods OR video:
Search across multiple fields, specifying (via boosts) how important each field is relative each other:
You can boost results that have a field that matches a specific value:
mm parameter, 1 and 2 word queries require that all of the optional clauses match, but for queries with three or more clauses one missing clause is allowed:
In the example below, we see a per-field override of the
qf parameter being used to alias "name" in the query string to either the “
last_name” and “
qf=title text last_name first_name
Edismax can run queries against all query fields, and also run a query in the form of a phrase against the phrase fields. (This will work only for boosting documents, not actually for matching.) However, that phrase query can have a 'slop,' which is the distance between the terms of the query while still considering it a phrase match. For example:
With these parameters, the Dismax Query Parser generates a query that looks something like this:
(+(field1:foo^5 OR field2:foo^10) AND (field1:bar^5 OR field2:bar^10))
But it also generates another query that will only be used for boosting results:
field1:"foo bar"^50 OR field2:"foo bar"^20
Thus, any document that has the terms "foo" and "bar" will match; however if some of those documents have both of the terms as a phrase, it will score much higher because it’s more relevant.
If you add the parameter
ps (phrase slop), the second query will instead be:
ps=10 field1:"foo bar"~10^50 OR field2:"foo bar"~10^20
This means that if the terms "foo" and "bar" appear in the document with less than 10 terms between each other, the phrase will match. For example the doc that says:
*Foo* term1 term2 term3 *bar*
will match the phrase query.
How does one use phrase slop? Usually it is configured in the request handler (in
With query slop (
qs) the concept is similar, but it applies to explicit phrase queries from the user. For example, if you want to search for a name, you could enter:
A document that contains "Hans Anderson" will match, but a document that contains the middle name "Christian" or where the name is written with the last name first ("Anderson, Hans") won’t. For those cases one could configure the query field
qs, so that even if the user searches for an explicit phrase query, a slop is applied.
Finally, in addition to the phrase fields (
edismax also supports the
pf3 parameters, for fields over which to create bigram and trigram phrase queries. The phrase slop for these parameters' queries can be specified using the
ps3 parameters, respectively. If you use
pf3 but not
ps3, then the phrase slop for these parameters' queries will be taken from the
ps parameter, if any.
Synonyms Expansion in Phrase Queries with Slop
When a phrase query with slop (e.g.,
ps) triggers synonym expansions, a separate clause will be generated for each combination of synonyms. For example, with configured synonyms
cat,feline, the query
"dog chased cat" will generate the following phrase query clauses:
"dog chased cat"
"canine chased cat"
"dog chased feline"
"canine chased feline"