solr's suggester gives "SolrException: Unknown Search Component: spellcheck at org.apache.solr.core.SolrCore" - solr

I tried using Solr's Suggester component but it gives exception Unknown Search Component: spellcheck. I am using solr version 3.6. I made changes in solrconfig.xml so it looks like this
<searchComponent class="solr.SpellCheckComponent" name="suggester">
<lst name="spellchecker">
<str name="name">suggester</str>
<str name="field">name</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookup</str>
<float name="threshold">0.005</float>
<str name="buildOnCommit">true</str>
<str name="spellcheckIndexDir">spellchecker</str>
</lst>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggester">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">suggester</str>
<str name="spellcheck.count">10</str>
</lst>
<arr name="components">
<str>suggester</str>
</arr>
</requestHandler>
Now i saved it and started solr but it gives a 500 error. There is a long stack trace which goes like this
HTTP Status 500 - Severe errors in solr configuration. Check your log files for more detailed information on what may be wrong. If you want solr to continue after configuration errors, change: <abortOnConfigurationError>false</abortOnConfigurationError> in solr.xml ------------------------------------------------------------- org.apache.solr.common.SolrException: No cores were created, please check the logs for errors at org.apache.solr.core.CoreContainer$Initializer.initialize(CoreContainer.java:172) at org.apache.solr.servlet.SolrDispatchFilter.init(SolrDispatchFilter.java:96) at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:295) at
---lot of lines---
and some more
Caused by: org.apache.solr.common.SolrException: Unknown Search Component: spellcheck at org.apache.solr.core.SolrCore.getSearchComponent(SolrCore.java:893) at org.apache.solr.handler.component.SearchHandler.inform(SearchHandler.java:118) at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:527) at org.apache.solr.core.SolrCore.<init>(SolrCore.java:594) ... 32 more
According to the stack trace Solr is not able to find the spellcheck component but according to the Solr wiki this component comes with Solr version > 1.4.

You seem to have named your search component suggester, and your requestHandler refers to it correctly, so that's probably not where the issue is. Can you check in the rest of your solrconfig.xml whether some other requestHandler refers to a component named spellcheck in its last-components section or elsewhere? That would throw an error since it can no longer find a component with that name (it's been renamed to suggester).
The thing with solrconfig is that it comes with a lot of preconfigured search handlers, and if you change the default name of one item it could cause issues with handlers that refer to it.

Related

SOLR why does its state this 'leaderUrl' must be specified without the /replication suffix

Why when I setup a Solr follower/slave do I get this message in the Solr logs
'leaderUrl' must be specified without the /replication suffix
This used to work fine in ersion 7.6 but now in version 8.11.1 it complains. What should the value be if not /replication?
This is the XML snippet in the solrconfig.xml that does the replications
<requestHandler name="/replication" class="solr.ReplicationHandler">
<lst name="slave">
<str name="leaderUrl">http://solr1:8983/solr/bookings/replication</str>
<str name="pollInterval">00:00:20</str>
</lst>
</requestHandler>
It seems to mean the leadUrl, I seemed to be transfixed on the name of the request handler!
So going from this which worked in 7.6
<str name="masterUrl">http://solr1:8983/solr/bookings/replication</str>
to this which works in 8.11.1
<str name="leaderUrl">http://solr1:8983/solr/bookings</str>

SuggestorComponent with contextFilter in solr

Which lookup should i use for implementing context Filtering in solr Suggestor component?
I am trying to use contextFiler in FuzzyLookupFactory and AnalyzingLookupFactory but it is throwing me the below error:
Caused by:
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/categories: this suggester doesn't support contexts.
My suggestor:
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">displaySuggester</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">autoComplete</str>
<str name="contextField">productCategory</str>
<str name="suggestAnalyzerFieldType">string</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
The reference manual has the required settings:
Context filtering lets you filter suggestions by a separate context field, such as category, department or any other token. The AnalyzingInfixLookupFactory and BlendedInfixLookupFactory currently support this feature, when backed by DocumentDictionaryFactory.
It's important to note that this is the Analyzing**Infix**LookupFactory, and not the AnalyzingLookupFactory.
You're already using the DocumentDictionaryFactory, so switch to either the AnalyzingInfixLookupFactory or the BlendedInfixLookupFactory to make it work.

DSE CQL Query for Solr Suggestor

I am using DSE 5.0.1 version. Earlier we used facet query to show search suggestions. For performance reasons , looking for other alternatives to get suggestions and found solr search suggester component. But I couldn't find examples where suggester component is used from a CQL query. Its possible right?Can anyone help me on this.
Thanks in advance.
Yes, it's possible and relatively easy - you just need to understand how to map XML that you want to put into generated solrconfig.xml into JSON that is used for configuration.
For example, we want to configure suggestor to suggest on the data from field title, and use additional weights from the rating field. As per Solr documentation the XML piece should look following way:
<searchComponent class="solr.SuggestComponent" name="suggest">
<lst name="suggester">
<str name="name">titleSuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="suggestAnalyzerFieldType">TextField</str>
<str name="field">title</str>
<str name="weightField">rating</str>
<str name="buildOnCommit">false</str>
<str name="exactMatchFirst">true</str>
<str name="contextField">country</str>
</lst>
</searchComponent>
<requestHandler class="solr.SearchHandler" name="/suggest">
<arr name="components">
<str>suggest</str>
</arr>
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
</requestHandler>
In CQL, it will be converted
ALTER SEARCH INDEX CONFIG ON table ADD
searchComponent[#name='suggest',#class='solr.SuggestComponent']
WITH $$ {"suggester":[{"name":"titleSuggester"},
{"lookupImpl":"AnalyzingInfixLookupFactory"},
{"dictionaryImpl":"DocumentDictionaryFactory"},
{"suggestAnalyzerFieldType":"TextField"},
{"field":"title"}, {"weightField":"rating"},
{"buildOnCommit":"false"}, {"exactMatchFirst":"true"},
{"contextField":"country"}]} $$;
ALTER SEARCH INDEX CONFIG ON table ADD
requestHandler[#name='/suggest',#class='solr.SearchHandler']
WITH $$ {"defaults":[{"suggest":"true"},
{"suggest.count":"10"}],"components":["suggest"]} $$;
After that you need not to forget to execute:
RELOAD SEARCH INDEX ON table;
And your suggestor will work. In my example, the index for suggestor should be build explicitly because inventory doesn't change very often. This is done via HTTP call like this:
curl 'http://localhost:8983/solr/keyspace.table/suggest?suggest=true&suggest.dictionary=titleSuggester&suggest.q=Wat&suggest.cfq=US&wt=json&suggest.build=true&suggest.reload=true'
But you can control this by setting buildOnCommit to true. Or you can configure it to build suggestor index on start, etc. - see Solr's documentation.
Full example is here - this is an example of the e-commerce application.

Solr suggester in SolrCloud mode

I am running the solr in CloudSolr mode with three shards. The data is already indexed into solr. Now I have configured the solr suggester in solrconfig.xml. This is the configuration from solrconfig file. I am using solr 4.10 version.
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mysuggest</str>
<str name="lookupImpl">FuzzyLookupFactory</str>
<str name="storeDir">suggester_fuzzy_dir</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">businessName</str>
<str name="payloadField">profileId</str>
<str name="weightField">businessName</str>
<str name="suggestAnalyzerFieldType">text_general</str>
<str name="buildOnStartup">false</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">10</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
Here is the command I am using to fetch the result:
http://shard1:8900/solr/core/suggest?suggest=true&suggest.build=true&suggest.reload&suggest.dictionary=mysuggest&wt=json&indent=true&suggest.q=sale
This is the output of the command:
{
"responseHeader":{
"status":0,
"QTime":1490},
"command":"build",
"suggest":{}
}
Nothing is coming into suggest result. I have 10K records indexed into solr.
I am seeing the following into log file:
org.apache.solr.handler.component.SuggestComponent; http://shard1:8983/solr/core/ : null
org.apache.solr.handler.component.SuggestComponent; http://shard2:8900/solr/core/ : null
org.apache.solr.handler.component.SuggestComponent; http://shard3:7574/solr/core/ : null
I am not able understand what is missing here. Thanks.
It was not working because solr was running in SolrCloud mode. There is two ways to perform suggestion in solrCloud mode:
Use the distrib=false parameter. This will fetch the data from only one shard which you are accessing in the command. You can add the following into Component definition itself.
<bool name="distrib">false</bool>
Use the shards and shards.qt parameter for searching all the shards. The shards parameter will contain comma separated list of all the shards which you want to include in the query. The shards.qt parameter will define the reat API you want to access.
shards.qt: Signals Solr that requests to shards should be sent to a request handler given by this parameter. Use shards.qt=/spell when making the request if your request handler is "/spell".
shards: shards=solr-shard1:8983/solr,solr-shard2:8983/solr Distributed Search
Please check Here for more details.

How to build a dictionary for spellchecking in Solr?

I'm trying to add spell checking to an existing Solr index.
I've added the following to the solrconfig.xml
<searchComponent name="spellcheck" class="solr.SpellCheckComponent">
<str name="queryAnalyzerFiedlType">textSpell</str>
<lst name="spellchecker">
<str name="name">my_spell</str>
<str name="field">my_field</str>
<str name="buildOnOptimize">true</str>
<str nmae="spellcheckIndexDir">./spellchecker_my_spell</str>
</lst>
</searchComponent>
When I try to build the index with http://<myserver>:4103/my_index/select?&spellcheck=true&spellcheck.build=true&spellcheck.dictionary=cn_spell
I don't find any evidence that any dictionary is being built, either in the response, or in the file system.
What am I missing?
I forgot to add the query type to the query string. Adding &qt=dismax worked for me, since the spellcheck was the last-components of my dismax handler.

Resources