Number Format Exception in Solr - solr

I am trying to do data import handler in Solr.But not able to index the data from solr using the full_import command.It is giving a NumberFormatException even though I have defined the fields as string in schema.xml.I am using 5.2.1 version of Solr.
WARN - 2015-07-09 07:14:19.137;
[ king] org.apache.solr.handler.dataimport.SolrWriter;
Error creating document : SolrInputDocument(fields: [id=1, name=Ajay, _version_=1506201891385638912])
org.apache.solr.common.SolrException: ERROR: [doc=1] Error adding field 'name'='Ajay' msg=For input string: "Ajay"
at org.apache.solr.update.DocumentBuilder.toDocument(DocumentBuilder.java:176)
Can you please clarify what am I doing wrong here.When I do the same procedure in techproducts example it works fine.
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">157</int>
</lst>
<lst name="initArgs">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</lst>
<str name="command">full-import</str>
<str name="mode">debug</str>
<arr name="documents">
<lst>
<arr name="id">
<int>1</int>
</arr>
<arr name="name">
<str>Ajay</str>
</arr>
<arr name="_version_">
<long>1506202992068526080</long>
</arr>
</lst>
<lst>
<arr name="id">
<int>2</int>
</arr>
<arr name="name">
<str>Karan</str>
</arr>
<arr name="_version_">
<long>1506202992072720384</long>
</arr>
</lst>
<lst>
<arr name="id">
<int>3</int>
</arr>
<arr name="name">
<str>Raj</str>
</arr>
<arr name="_version_">
<long>1506202992077963264</long>
</arr>
</lst>
<lst>
<arr name="id">
<int>4</int>
</arr>
<arr name="name">
<str>Ramesh</str>
</arr>
<arr name="_version_">
<long>1506202992083206144</long>
</arr>
</lst>
</arr>
<lst name="verbose-output"/>
<str name="status">idle</str>
<str name="importResponse"/>
<lst name="statusMessages">
<str name="Total Requests made to DataSource">1</str>
<str name="Total Rows Fetched">4</str>
<str name="Total Documents Processed">0</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2015-07-09 07:31:48</str>
<str name="Total Documents Failed">4</str>
<str name="Time taken">0:0:0.133</str>
</lst>
</response>

Solved this by adding _s to the string field in the data-config.xml.Solved the issue.

Related

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.

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?

Solr highlighting every word individually for a phrase query

Say I have a field in Solr which has the value, "The rain in Spain falls mainly in the plain."
And I want a highlighted result for the phrase, "falls mainly".
I pass these parameters to the select...
<lst name="params">
<str name="hl.fragsize">-1</str>
<str name="q">"falls mainly"</str>
<str name="hl.q">"falls mainly"</str>
<str name="hl.simple.pre">##pre##</str>
<str name="hl.simple.post">##post##</str>
<str name="hl.fl">note</str>
<str name="hl.maxAnalyzedChars">-1</str>
<str name="hl">true</str>
<str name="rows">2147483647</str>
</lst>
And the response comes back with each phrase word individually highlighted...
<lst name="highlighting">
<lst name="test">
<arr name="note">
<str>
The rain in Spain ##pre##falls##post## ##pre##mainly##post## in the plain.
</str>
</arr>
</lst>
</lst>
What I would have expected was the phrase highlighted...
<lst name="highlighting">
<lst name="test">
<arr name="note">
<str>
The rain in Spain ##pre##falls mainly##post## in the plain.
</str>
</arr>
</lst>
</lst>
I am using Solr version 4.0.

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