I had the same problem as you, and I managed to solve it. Turns out there are a few things you need to know to ensure that multiple sorts work correctly.
First you must specify the QueryComponent
in the components
list to “offer” requestHandler
in solrconfig.xml
. Otherwise, your requestHandler
does not know how to request the index, so it cannot figure out how many requests each corrected request has, so you only get one. If you added spellcheck.collateExtendedResults=true
to your query, you would see that hits
are 0, which indicates that Solr did not bother to check the corrected query for the index.
They hint at this with a slightly opaque error message:
INFO: Could not find an instance of QueryComponent. Disabling collation verification against the index.
The easiest way to add this is to use the default QueryComponent
, which is called a "query". So, in the XML that you posted above, you will change the "components" part to:
<arr name="components"> <str>suggest</str> <str>query</str> </arr>
Secondly, you need to set spellcheck.maxCollations
more than 1 (duh), and less intuitively, you need to set spellcheck.maxCollationTries
as some large number (e.g. 1000). If either of them is set by default (both values are 0), then Solr will give you only one sort. In addition, you need to set spellcheck.count
more than 1.
Third, you need to modify the query to include the field to which you want to search, and the terms must be surrounded by quotation marks to ensure proper sorting. Therefore, in the case of your request:
q=bio+ber
It really should be:
q=text:"bio+ber"
Obviously, in your case, “text” is the default field, so you don't need it. But in my case, I did not use the default field, so I had to specify it. Otherwise, Solr will count hits against the text field, and all results will have 0 hits, so ranking will be useless.
So, in my case, the query looked like this:
q=my_field:"brain+c" &spellcheck.count=5 &spellcheck.maxCollations=10 &spellcheck.maxCollationTries=1000 &spellcheck.collateExtendedResults=true
And my answer looked like this:
<response> <lst name="responseHeader"> <int name="status">0</int> <int name="QTime">4</int> </lst> <lst name="spellcheck"> <lst name="suggestions"> <lst name="brain"> <int name="numFound">1</int> <int name="startOffset">15</int> <int name="endOffset">20</int> <arr name="suggestion"> <str>brain</str> </arr> </lst> <lst name="c"> <int name="numFound">4</int> <int name="startOffset">21</int> <int name="endOffset">23</int> <arr name="suggestion"> <str>cancer</str> <str>cambrian</str> <str>contusion</str> <str>cells</str> </arr> </lst> <lst name="collation"> <str name="collationQuery">my_field:"brain cancer"</str> <int name="hits">2</int> <lst name="misspellingsAndCorrections"> <str name="brain">brain</str> <str name="c">cancer</str> </lst> </lst> <lst name="collation"> <str name="collationQuery">my_field:"brain contusion"</str> <int name="hits">1</int> <lst name="misspellingsAndCorrections"> <str name="brain">brain</str> <str name="c">contusion</str> </lst> </lst> <lst name="collation"> <str name="collationQuery">my_field:"brain cells"</str> <int name="hits">1</int> <lst name="misspellingsAndCorrections"> <str name="brain">brain</str> <str name="c">cells</str> </lst> </lst> </lst> </lst> <result name="response" numFound="0" start="0"/> </response>
Success!