Solr4j & Collation response - solr

When I run spellcheck query against solr on browser I can see the response with suggestions and collations, however, when I run using solr4j, I only see suggestions - no collations.
Query
http://localhost:8080/solr/peeps/mySuggest?qt=%2FmySuggest&distrib=false&df=myFieldLookup&q=myFieldLookup:sc+ma&start=0&rows=0
Response
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">3</int>
</lst>
<result name="response" numFound="0" start="0"/>
<lst name="spellcheck">
<lst name="suggestions">
<lst name="sc">
<int name="numFound">1</int>
<int name="startOffset">32</int>
<int name="endOffset">34</int>
<arr name="suggestion">
<str>science</str>
</arr>
</lst>
<lst name="ma">
<int name="numFound">2</int>
<int name="startOffset">35</int>
<int name="endOffset">37</int>
<arr name="suggestion">
<str>management</str>
<str>master</str>
</arr>
</lst>
<lst name="collation">
<str name="collationQuery">myFieldLookup:science management</str>
<int name="hits">1</int>
<lst name="misspellingsAndCorrections">
<str name="sc">science</str>
<str name="ma">management</str>
</lst>
</lst>
<lst name="collation">
<str name="collationQuery">myFieldLookup:science master</str>
<int name="hits">1</int>
<lst name="misspellingsAndCorrections">
<str name="sc">science</str>
<str name="ma">master</str>
</lst>
</lst>
</lst>
</lst>
</response>
But when I call from solr4j, I get all of the above except the "collation" part of the response!
So, I tried this URL from browser (added wt=javabin & version) to see what solr4j is receiving.
http://localhost:8080/solr/peeps/mySuggest?qt=%2FmySuggest&distrib=false&df=myFieldLookup&q=myFieldLookup:sc+ma&start=0&rows=0&wt=javabin&version=2
which downloaded a file & I open that with text editor
£‡.responseHeader¢‡&status‡%QTimeB‡(responseÉ``ć*spellcheck°‡+suggestionsƒ‡"sc§‡(numFoundA‡+startOffsetP‡)endOffsetR‡*suggestionÅ'science‡"ma§ËBÈSÍUÎÇ*management&master‡)collation√‡.collationQuery?myFieldLookup:science management‡$hitsA‡:misspellingsAndCorrections¬Á'scienceÏ*managementÌ√Ó?myFieldLookup:science masterÔA¬Á'scienceÏ&master
It is not readable, but, I can see the word "collation" in there! So, why is Solr4j not picking it up?

You want to leverage the SolrJ SpellCheckResponse object to get access to the collation response. You should be able to see this using:
...
QueryResponse response = solr.query(params);
SpellCheckResponse spellCheckResponse = response.getSpellCheckResponse();
List<SpellCheckResponse.Collation> collations = spellCheckResponse.getCollatedResults();

Related

Solr Spell Checking returns suggestions with exact match, case sensitive

I am working with Solr SpellChecking.
I use the schemaless mode, default configuration is data driven and I indexed a csv file, inside the file content, there is a column Nationality, and some column values are Singapore.
Then I query spell check and I got result
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">7</int>
</lst>
<result name="response" numFound="0" start="0"></result>
<lst name="spellcheck">
<lst name="suggestions">
<lst name="singapor">
<int name="numFound">1</int>
<int name="startOffset">0</int>
<int name="endOffset">8</int>
<int name="origFreq">0</int>
<arr name="suggestion">
<lst>
<str name="word">singapore</str>
<int name="freq">104</int>
</lst>
</arr>
</lst>
</lst>
<bool name="correctlySpelled">false</bool>
<lst name="collations">
<lst name="collation">
<str name="collationQuery">singapore</str>
<int name="hits">104</int>
<lst name="misspellingsAndCorrections">
<str name="singapor">singapore</str>
</lst>
</lst>
</lst>
</lst>
</response>
I want the exact result with case sensitive Singapore, not singapore.
<str name="word">Singapore</str>

Re-do solr query with spellchecking suggestions

Using the following configuration to run the spellchecking on Solr queries:
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">textTitle</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">text</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<str name="distanceMeasure">internal</str>
<float name="accuracy">0.7</float>
<int name="maxEdits">2</int>
<int name="minPrefix">1</int>
<int name="maxInspections">10</int>
<int name="minQueryLength">3</int>
<float name="maxQueryFrequency">0.10</float>
<float name="thresholdTokenFrequency">.00001</float>
</lst>
</searchComponent>
<requestHandler name="standard" class="solr.StandardRequestHandler" default="true">
<!-- default values for query parameters -->
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.collate">true</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
I get the correct suggestions for bad spelled queries, however, is it possible to re-do the query again to return the results for the spellchecked terms instead of just returning the suggestions?

Make Solr automatically search by first suggestion in spell correction

We're trying to use Solr to correct the spelling of certain tests in a search box. We found that it works like this:
http://localhost:8080/solr/collection1/spell?q=badspelled&spellcheck=true
And it returns a set of suggested terms. But what we need is not a list of suggestions but that Solr makes a search directly using the first suggestion. Is that possible?
You will need to add the "spellcheck.collate=true" parameter to your first search query and then use the "collation" value in the response to fire a second query with that value.
Example from the plugin page:
http://localhost:8983/solr/spell?q=price:[80 TO 100] delll ultrashar&spellcheck=true&spellcheck.extendedResults=true&spellcheck.collate=true
This returns the suggestions:
<lst name="spellcheck">
<lst name="suggestions">
<lst name="delll">
<int name="numFound">1</int>
<int name="startOffset">18</int>
<int name="endOffset">23</int>
<int name="origFreq">0</int>
<arr name="suggestion">
<lst>
<str name="word">dell</str>
<int name="freq">2</int>
</lst>
</arr>
</lst>
<lst name="ultrashar">
<int name="numFound">1</int>
<int name="startOffset">24</int>
<int name="endOffset">33</int>
<int name="origFreq">0</int>
<arr name="suggestion">
<lst>
<str name="word">ultrasharp</str>
<int name="freq">2</int>
</lst>
</arr>
</lst>
<bool name="correctlySpelled">false</bool>
<str name="collation">price:[80 TO 100] dell ultrasharp</str>
</lst>
</lst>
Then fire another query with the suggested query:
http://localhost:8983/solr/spell?q=price:[80 TO 100] dell ultrasharp&spellcheck=true&spellcheck.extendedResults=true&spellcheck.collate=true
SpellCheck collate

Solr : Unexpected result

I am using highlighting feature of solr. Well its doing great except one thing. Here is the problem in response
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">9</int>
</lst>
<result name="response" numFound="1" start="0" maxScore="0.6901834">
<doc>
<str name="desc">I study in school</str>
<str name="name">school</str>
<str name="value">DPS</str>
<str name="country">India</str>
<str name="state">delhi</str>
<str name="city">New Delhi</str>
<str name="area">R.K. Puram</str>
<str name="id">c02101a4-c5c2-46a9-bb73-805208167b3c</str>
<float name="score">0.6901834</float></doc>
</result>
<lst name="highlighting">
<lst name="c02101a4-c5c2-46a9-bb73-805208167b3c">
<arr name="name">
<str>school</str>
</arr>
<arr name="value">
<str><em>DP</em>S</str>
</arr>
</lst>
</lst>
</response>
In highlighting section , Why am I getting "name":"school" field ??? Even though it is not getting highlighted like "value":"DPS" ..
Thanks

How to configure solrconfig.xml for suggester in solr?

I have configured my solrconfig.xml to use Suggester component as suggested in http://wiki.apache.org/solr/Suggester.
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<lst name="spellchecker">
<str name="name">suggest</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookup</str>
<str name="field">name</str>
<!-- the indexed field to derive suggestions from -->
<float name="threshold">0.005</float>
<str name="buildOnCommit">true</str>
<!--
<str name="sourceLocation">american-english</str>
-->
</lst>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggest</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.collate">true</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
However, when i browse from the browser url i am not getting any suggestions.
http://localhost:8080/solr/collection1/suggest?q=ava&fq=type%3ACategory&wt=xml
<response>
<lst name="responseHeader">
<int name="status">
0
</int>
<int name="QTime">
0
</int>
</lst>
<lst name="spellcheck">
<lst name="suggestions"/>
</lst>
</response>
Even if i remove the fq filter, I am not getting the suggestions.
Please help.
Thanks
I am not sure, can you try adding spellcheck=on
http://localhost:8080/solr/collection1/suggest?q=ava&spellcheck=on&fq=type%3ACategory&wt=xml

Resources