How to design a SearchHandler in Solr - solr

I have designed a SearchHandler in Solr, but I don't know why the Rank and Shards does not work. Here is the config for the requestHandler:
<requestHandler name="/contentsearch" class="solr.SearchHandler">
<lst name="defaults">
<str name="shards">localhost:8983/solr/Wiki,localhost:8983/solr/iShare,localhost:8983/solr/GRA,localhost:8983/solr/ACF</str>
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="defType">edismax</str>
<str name="qf">
title^100.0 content^80.0 text^60.0
</str>
<str name="q">*:*</str>
<str name="indent">true</str>
<str name="rows">10</str>
<!-- Facet settings -->
<str name="facet">on</str>
<str name="facet.field">content_type</str>
<str name="facet.field">category</str>
<str name="facet.field">author</str>
<str name="facet.field">editor</str>
<str name="facet.field">source_type</str>
<str name="hl">on</str>
<str name="hl.fl">title content</str>
</lst>
<arr name="last-components">
<str>elevator</str>
</arr></requestHandler>
The 4 core schemas are same. What am I missing?

Related

Solr core cannot initialize because of write.lock in spellcheck index directory

I am having a lock issue when trying to initialize a Solr core:
SolrCore Initialization Failures:
MySolrCore: org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: org.apache.lucene.store.LockObtainFailedException: Lock held by this virtual machine: C:\solr-6.0.1\server\solr\MySolrCore\data\analyzingInfixSuggesterIndexDir\write.lock
I am trying to implement multiple spell checkers on this core and I get this lock error.
Some interesting notes from trying different approaches:
I tried extending the writeLockTimeout to 30 seconds and that did nothing.
None of the spellcheckIndexDir folders are getting created. I added them in hopes of fixing the lock issue. I even tried creating them manually, and no files were added to them.
If I comment out one of the components and handlers, the other one works.
If I comment out the spellecheckers that use the AnalyzingInfixLookupFactory then both of the spellcheckers that use the WFSTLookupFactory and both of the handlers work. However, the spellcheckIndexDir is not created.
How do I fix the lock issue? I think that if I can get all of the spellcheckIndexDir specified to work that the indexes will be located in different folders and there won't be a lock. Thanks for any help!
Here's my Solr config search components and handlers for the two fields.
<searchComponent name="NameSuggest" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">NameFST</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.WFSTLookupFactory</str>
<str name="field">NameFST</str>
<int name="minQueryLength">3</int>
<str name="buildOnCommit">true</str>
<str name="buildOnOptimize">true</str>
<str name="suggestAnalyzerFieldType">suggest_phrase</str>
<str name="spellcheckIndexDir">./NameFSTSuggestIndexDir</str>
</lst>
<lst name="spellchecker">
<str name="name">NameAI</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
<str name="field">NameAI</str>
<int name="minQueryLength">3</int>
<str name="buildOnCommit">true</str>
<str name="buildOnOptimize">true</str>
<str name="suggestAnalyzerFieldType">suggest_phrase</str>
<str name="spellcheckIndexDir">./NameAISuggestIndexDir</str>
</lst>
<str name="queryAnalyzerFieldType">suggest_phrase</str>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/NameSuggest" startup="lazy">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">NameFST</str>
<str name="spellcheck.dictionary">NameAI</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.collate">false</str>
<str name="spellcheck.extendedResults">true</str>
</lst>
<arr name="components">
<str>NameSuggest</str>
</arr>
</requestHandler>
<searchComponent name="DescriptionSuggest" class="solr.SpellCheckComponent">
<lst name="spellchecker">
<str name="name">DescriptionFST</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.WFSTLookupFactory</str>
<str name="field">DescriptionFST</str>
<int name="minQueryLength">3</int>
<str name="buildOnCommit">true</str>
<str name="buildOnOptimize">true</str>
<str name="suggestAnalyzerFieldType">suggest_phrase</str>
<str name="spellcheckIndexDir">./DescriptionFSTSuggestIndexDir</str>
</lst>
<lst name="spellchecker">
<str name="name">DescriptionAI</str>
<str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
<str name="lookupImpl">org.apache.solr.spelling.suggest.fst.AnalyzingInfixLookupFactory</str>
<str name="field">DescriptionAI</str>
<int name="minQueryLength">3</int>
<str name="buildOnCommit">true</str>
<str name="buildOnOptimize">true</str>
<str name="suggestAnalyzerFieldType">suggest_phrase</str>
<str name="spellcheckIndexDir">./DescriptionAISuggestIndexDir</str>
</lst>
<str name="queryAnalyzerFieldType">suggest_phrase</str>
</searchComponent>
<requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/DescriptionSuggest" startup="lazy">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="spellcheck.dictionary">DescriptionFST</str>
<str name="spellcheck.dictionary">DescriptionAI</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="spellcheck.count">10</str>
<str name="spellcheck.collate">false</str>
<str name="spellcheck.extendedResults">true</str>
</lst>
<arr name="components">
<str>DescriptionSuggest</str>
</arr>
</requestHandler>
Instead of spellcheckIndexDir I needed to use indexPath. It's working now.
<!-- <str name="spellcheckIndexDir">./NameAISuggestIndexDir</str> -->
<str name="indexPath">./NameAISuggestIndexDir</str>

Any working solr suggester example?

All:
I am using solr 4.10 default configuration now, I wonder if any one can give me a working configuration for suggester part? I tried the example in Solr in Action, but it does not work(I tried this /suggest handler in admin page, keeping other options default only specifying a keyword in q ).
<requestHandler name="/suggest"
class="org.apache.solr.handler.component.SearchHandler">
<lst name="defaults">
<str name="echoParams">none</str>
<str name="wt">json</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>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
<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.</float>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
Thanks

Not able to read results of SuggestComponent using SolrJ API

I am using SuggestComponent to get auto suggest keywords. I configured search component and request handler correctly in solrconfig.xml. I am getting expected results also.
Now my problem is i am not able to read XML output using SolrJ api. i spent couple of hours on SolrJ API, but not able to find method to read suggested keywords.
My Java Code
SolrServer server = //solrserver object creation
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("qt", "/suggest");
params.set("q", q);
QueryResponse rsp = server.query(params);
**//How to read from QueryResponse?**
Here is my solrconfig.xml configuration
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">name</str>
<str name="weightField">reviewsNum</str>
<str name="suggestAnalyzerFieldType">text_general</str>
<str name="buildOnCommit">true</str>
</lst>
</searchComponent>
<requestHandler name="/suggest" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="spellcheck">true</str>
<str name="suggest">true</str>
<str name="spellcheck.onlyMorePopular">true</str>
<str name="suggest.count">10</str>
<str name="suggest.dictionary">mySuggester</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
Response:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">24</int>
</lst>
<lst name="suggest">
<lst name="mySuggester">
<lst name="a">
<int name="numFound">10</int>
<arr name="suggestions">
<lst>
<str name="term">JNTU <b>A</b>nantapur</str>
<long name="weight">2</long>
<str name="payload"/>
</lst>
<lst>
<str name="term"><b>A</b>merican School of Bombay</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">
Society For <b>A</b>dvanced Study In Rehabilitation
</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term"><b>a</b>mrita vishwa vidyapeetham</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">
shanmugha <b>a</b>rts science technology & research <b>a</b>cademy (sastra)
</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">Montesorri Hs <b>A</b>lampur</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term"><b>A</b>ditya Ps Nehru Road Proddutur</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">Zphs <b>A</b>rakatavemula Rajupalem</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">Sri <b>A</b>ditya Ps,pamur Pamuru</str>
<long name="weight">1</long>
<str name="payload"/>
</lst>
<lst>
<str name="term">
ramakrishna mission vivekananda educational <b>a</b>nd research institute
</str>
<long name="weight">0</long>
<str name="payload"/>
</lst>
</arr>
</lst>
</lst>
</lst>
</response>
You'll have to access the SpellCheckResponse property of the response:
rsp.getSpellCheckResponse()
This returns a SpellCheckResponse object, which contains the getSuggestions() method, which in turn returns a List of SpellCheckResponse.Suggestion objects.
List<SpellCheckResponse.Suggestion> suggestions = rsp.getSpellCheckResponse().getSuggestions()
You also want to use setRequestHandler("/suggest"), and not the qt parameter.

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

Solr / Solritas 3.6 /solr/browse Not Found Issues

I have installed a solr instance with Jetty, and also I tried to follow the instructions here to install the velocityResponseWriter I just inserted the jar library that was missing the Apache Solr Velocity and when I start the service via console I get the message that the plugin was loaded ok.
but when I tried to run the solritas I got the following error:
HTTP ERROR 404
Problem accessing /solr/browse. Reason:
NOT_FOUND
Powered by Jetty://
Any ideas?
Edit: I've been trying to do that over solr 4.0 this is the file configuration section for solritas
<requestHandler name="/browse" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<!-- VelocityResponseWriter settings -->
<str name="wt">velocity</str>
<str name="v.template">browse</str>
<str name="v.layout">layout</str>
<str name="title">Solritas</str>
<!-- Query settings -->
<str name="defType">edismax</str>
<str name="qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0
</str>
<str name="df">text</str>
<str name="mm">100%</str>
<str name="q.alt">*:*</str>
<str name="rows">10</str>
<str name="fl">*,score</str>
<str name="mlt.qf">
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0
</str>
<str name="mlt.fl">text,features,name,sku,id,manu,cat,title,description,keywords,author,resourcename</str>
<int name="mlt.count">3</int>
<!-- Faceting defaults -->
<str name="facet">on</str>
<str name="facet.field">cat</str>
<str name="facet.field">manu_exact</str>
<str name="facet.field">content_type</str>
<str name="facet.field">author_s</str>
<str name="facet.query">ipod</str>
<str name="facet.query">GB</str>
<str name="facet.mincount">1</str>
<str name="facet.pivot">cat,inStock</str>
<str name="facet.range.other">after</str>
<str name="facet.range">price</str>
<int name="f.price.facet.range.start">0</int>
<int name="f.price.facet.range.end">600</int>
<int name="f.price.facet.range.gap">50</int>
<str name="facet.range">popularity</str>
<int name="f.popularity.facet.range.start">0</int>
<int name="f.popularity.facet.range.end">10</int>
<int name="f.popularity.facet.range.gap">3</int>
<str name="facet.range">manufacturedate_dt</str>
<str name="f.manufacturedate_dt.facet.range.start">NOW/YEAR-10YEARS</str>
<str name="f.manufacturedate_dt.facet.range.end">NOW</str>
<str name="f.manufacturedate_dt.facet.range.gap">+1YEAR</str>
<str name="f.manufacturedate_dt.facet.range.other">before</str>
<str name="f.manufacturedate_dt.facet.range.other">after</str>
<!-- Highlighting defaults -->
<str name="hl">on</str>
<str name="hl.fl">content features title name</str>
<str name="hl.encoder">html</str>
<str name="hl.simple.pre"><b></str>
<str name="hl.simple.post"></b></str>
<str name="f.title.hl.fragsize">0</str>
<str name="f.title.hl.alternateField">title</str>
<str name="f.name.hl.fragsize">0</str>
<str name="f.name.hl.alternateField">name</str>
<str name="f.content.hl.snippets">3</str>
<str name="f.content.hl.fragsize">200</str>
<str name="f.content.hl.alternateField">content</str>
<str name="f.content.hl.maxAlternateFieldLength">750</str>
<!-- Spell checking defaults -->
<str name="spellcheck">on</str>
<str name="spellcheck.extendedResults">false</str>
<str name="spellcheck.count">5</str>
<str name="spellcheck.alternativeTermCount">2</str>
<str name="spellcheck.maxResultsForSuggest">5</str>
<str name="spellcheck.collate">true</str>
<str name="spellcheck.collateExtendedResults">true</str>
<str name="spellcheck.maxCollationTries">5</str>
<str name="spellcheck.maxCollations">3</str>
</lst>
<!-- append spellchecking to our list of components -->
<arr name="last-components">
<str>spellcheck</str>
</arr>
Your default search field is equal to 'text' : <str name="df">text</str>, you maybe have to change it to one of your fields.
Check the command line from which you have launched start.jar (Solr), to see the exact error.

Resources