Querying an alias with 5 collections and getting suggestions for correct words as well.
Ex:- Collection1 has "tire policy" in it
Collection2 has a word "polite" in it.
When I query "tire policy" it checks and returns "polite" as a suggestion for "policy".
P.S. - During query time i am passing
spellcheck.maxResultsForSuggest=0
As without it spellchecker does not correct the wrong spellings.
I am using DirectSolrSpellchecker
Adjusted the
<float name="maxQueryFrequency">0.01</float> to
<float name="maxQueryFrequency">1</float>
but getting the same issue.
Direct solr spellchecker code-
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">text</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<str name="distanceMeasure">org.apache.lucene.search.spell.LevenshteinDistance</str>
<float name="accuracy">0.5</float>
<int name="maxEdits">2</int>
<int name="minPrefix">1</int>
<int name="maxInspections">5</int>
<int name="minQueryLength">3</int>
<float name="maxQueryFrequency">1</float>
</lst>
spellchecker inside handler
<str name="spellcheck.dictionary">default</str>
<str name="spellcheck.dictionary">wordbreak</str>
<str name="spellcheck.dictionary">file</str>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.alternativeTermCount">5</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
There should not be any suggestions for policy as "maxqueryfreqency" is set to "1".
Have you tried to adjust the maxResultsForSuggest parameter?
With your current value of 5, if your query
returns 5 or fewer results, the spellchecker will report
"correctlySpelled=false" and also offer suggestions
solr 8.1 documentation
Related
In the SOLR admin, we can see there is a spellcheck option but it is not showing the result.
How this is works with the select query.
If I searched with the spell URL direct, It gives me result as expected
http://localhost:8983/solr/prashant1/spell?q=blakc&spellcheck=on&wt=json
Result
{
"responseHeader":{
"status":0,
"QTime":8},
"response":{"numFound":0,"start":0,"docs":[]
},
"spellcheck":{
"suggestions":[
"blakc",{
"numFound":10,
"startOffset":0,
"endOffset":5,
"origFreq":0,
"suggestion":[{
"word":"black",
"freq":65146},
{
"word":"blanc",
"freq":151},
{
"word":"blake",
"freq":10},
{
"word":"blac",
"freq":2},
{
"word":"block",
"freq":1863},
{
"word":"blanca",
"freq":32},
{
"word":"blank",
"freq":31},
{
"word":"blade",
"freq":23},
{
"word":"blacks",
"freq":12},
{
"word":"blanco",
"freq":11}]}],
"correctlySpelled":false,
"collations":[]}}
But I need the same result with the select query which is not working from the SOLR admin.
Solrconfig.xml
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">text_general</str>
<!-- Multiple "Spell Checkers" can be declared and used by this
component
-->
<!-- a spellchecker built from a field of the main index -->
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">Name</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<!-- the spellcheck distance measure used, the default is the internal levenshtein -->
<str name="distanceMeasure">internal</str>
<!-- minimum accuracy needed to be considered a valid spellcheck suggestion -->
<float name="accuracy">0.5</float>
<!-- the maximum #edits we consider when enumerating terms: can be 1 or 2 -->
<int name="maxEdits">2</int>
<!-- the minimum shared prefix when enumerating terms -->
<int name="minPrefix">1</int>
<!-- maximum number of inspections per result. -->
<int name="maxInspections">5</int>
<!-- minimum length of a query term to be considered for correction -->
<int name="minQueryLength">4</int>
<!-- maximum threshold of documents a query term can appear to be considered for correction -->
<float name="maxQueryFrequency">0.01</float>
<!-- uncomment this to require suggestions to occur in 1% of the documents
<float name="thresholdTokenFrequency">.01</float>
-->
</lst>
</searchComponent>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck.dictionary">default</str>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.alternativeTermCount">5</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
It should work with:
http://localhost:8983/solr/prashant1/select?q=Name%3Ablakc&spellcheck.q=blakc&spellcheck=on
Is there any setting and steps to be done?
Try by adding the spellcheck component to the standard query handler like
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
You can then call it like this:
http://localhost:8983/solr/select?q=yogik&spellcheck=true
Also don't forget to build the spellcheck dictionary before you use it:
http://localhost:8983/solr/select/?q=*:*&spellcheck=true&spellcheck.build=true
When I use the "spellcheck" in Solr I have always 1 result even if it should be more. For example if I have the word "conjecture" and I search "conjicture" I will find it, the same thing if I have the word "conjoncture" but if I have the two words (conjecture and conjoncture) I will have only one result.
Currently, I'm using this :
searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFieldType">text_spell</str>
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">copie_content</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<str name="distanceMeasure">internal</str>
<float name="accuracy">0.5</float>
<int name="maxEdits">2</int>
<int name="minPrefix">0</int>
<int name="maxInspections">10</int>
<int name="minQueryLength">4</int>
<float name="maxQueryFrequency">0.01</float>
<str name="spellcheck.maxResultsForSuggest">5</str>
</lst>
</searchComponent>
I'm having an annoying issue with the spellcheck component of solr 6.5.0. If I run a query through the spellcheck request handler, /spell, the query works as expected and I get suggested spelling for the incorrect words.
{
"responseHeader":{
"status":0,
"QTime":42},
"response":{"numFound":0,"start":0,"docs":[]
},
"spellcheck":{
"suggestions":{
"injary":{
"numFound":3,
"startOffset":0,
"endOffset":6,
"origFreq":0,
"suggestion":[{
"word":"injury",
"freq":121},
{
"word":"inward",
"freq":3},
{
"word":"injure",
"freq":1}]}},
"correctlySpelled":false,
"collations":{
"collation":{
"collationQuery":"injury",
"hits":121,
"misspellingsAndCorrections":[
"injary","injury"]},
"collation":{
"collationQuery":"inward",
"hits":3,
"misspellingsAndCorrections":[
"injary","inward"]},
"collation":{
"collationQuery":"injure",
"hits":1,
"misspellingsAndCorrections":[
"injary","injure"]}}}}
But if I run a query through the standard request handler, /select, I get no suggestions.
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"injary",
"indent":"on",
"spellcheck":"on",
"wt":"json",
"_":"1492780436450"}},
"response":{"numFound":0,"start":0,"docs":[]
}}
Any help would be greatly appreciated.
I modified the solrconfig.xml to bring the two request handlers into line as follows, the rest is default:
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">content</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<str name="distanceMeasure">internal</str>
<float name="accuracy">0.5</float>
<int name="maxEdits">2</int>
<int name="minPrefix">1</int>
<int name="maxInspections">5</int>
<int name="minQueryLength">4</int>
<float name="maxQueryFrequency">0.01</float>
<float name="thresholdTokenFrequency">.0001</float>
</lst>
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<!-- Solr will use suggestions from both the 'default' spellchecker
and from the 'wordbreak' spellchecker and combine them.
collations (re-written queries) can include a combination of
corrections from both spellcheckers -->
<str name="spellcheck.dictionary">default</str>
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.alternativeTermCount">5</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">10</str>
<str name="spellcheck.maxCollations">5</str>
<str name="wt">json</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
<requestHandler name="/select" class="solr.SearchHandler">
<!-- default values for query parameters can be specified, these
will be overridden by parameters in the request
-->
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="df">_text_</str>
<str name="wt">json</str>
<!-- spell check component configuration -->
<str name="spellcheck">true</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.maxCollationTries">5</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
It appears the issue was related to my managed-schema file.
I am parsing XML files and solr automatically adds the fields of the XML files to the managed-schema file as type strings. When I changed my dictionary field to type text_general it starting working as expected.
I hostly can't see how this worked but I made no other changes. I deleted my core and started from scratch to make sure I wasn't mistaken but it worked.
I am trying to implement the auto suggest of solr this is the changes that I made in solrconfig.xml file
<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>
<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.tst.TSTLookupFactory</str>
<str name="field">displayName</str> <!-- the indexed field to derive suggestions from -->
<float name="threshold">0.005</float>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
when I try to query with sample input as 'p'
http://localhost:8983/solr/food/suggest?q=p&wt=json&indent=true
it returns 5 words
"pizza", "potato", "pasta", "protein", "premium"
but in the displayName field I got words like paneer , palak etc which is not showing up why is it so?
Can you added the following to your configuration and run the below query. Don't forget to reload the solr core after putting these changes.
<str name="suggestAnalyzerFieldType">string</str>
<str name="storeDir">suggester_fuzzy_dir</str>
http://localhost:8983/solr/food/suggest?suggest=true&suggest.build=true&suggest.dictionary=suggest&wt=json&suggest.q=p&suggest.count=10
I'm trying to use the suggest component (solr 4.6) with multiple cores. I have added a search component and a request handler in my solrconfig. That works fine for 1 core but querying my solr instance with the shards parameter does not work.
But did you mean' (spell check ) is working fine with multiple cores using shard.
Here is the configuration part of solrconfig file :
<searchComponent class="solr.SpellCheckComponent" name="suggest">
<lst name="spellchecker">
<str name="name">suggestDictionary</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.FSTLookupFactory</str>
<str name="field">suggest</str>
<float name="threshold">0.0005</float>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="org.apache.solr.handler.component.SearchHandler">
<lst name="defaults">
<str name="echoParams">none</str>
<str name="wt">xml</str>
<str name="indent">false</str>
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggestDictionary</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.collate">false</str>
<str name="qt">/suggest</str>
<str name="shards.qt">/suggest</str>
<str name="shards">localhost:8080/cores/core1,localhost:8080/cores/core2</str>
<bool name="distrib">false</bool>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
<shardHandlerFactory class="HttpShardHandlerFactory">
<int name="socketTimeOut">1000</int>
<int name="connTimeOut">5000</int>
</shardHandlerFactory>
</requestHandler>
It works for me..
You can get the suggestions using this RestURL
http://localhost:8983/solr/demo/spell?q=howoo&wt=json&indent=true&qt=spell&shards.qt=/spell&shards=localhost:8983/solr/demo_shard2_replica1,localhost:8983/solr/demo_shard1_replica2
OR Simply use this :
http://localhost:8983/solr/demo/spell?q=hoo&wt=json&indent=true&shards.qt=/spell
shards.qt=/spell : Need to add that allows suggestion on shards
Here, you have make changes and apply for things which requires.
Collection = demo
Shards = demo_shard2_replica1, demo_shard1_replica2
Replace collection and shards names with your names of collection and shards.