Solr highlighting every word individually for a phrase query - solr

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.

Related

Solr suggestions with weight field - Analyzinginfixsuggester

I am using SOLR to generate suggestions. I have given a float field named length (tfloat) as the weightField in solrconfig.xml. But in my suggestions, this value does not come up in the suggestion response and shows as zero. I was expecting the suggestions to be sorted by weight and the weight to hold the value of length which represents the string length of the suggestions. I am using solr 6.2.1
<searchComponent name="suggest" class="solr.SuggestComponent">
<lst name="suggester">
<str name="name">mySuggester</str>
<str name="lookupImpl">AnalyzingInfixLookupFactory</str>
<str name="indexPath">suggester_infix_dir</str>
<str name="payloadField">payload</str>
<str name="weightField">lengthval</str>-->
<str name="dictionaryImpl">DocumentDictionaryFactory</str>
<str name="field">value</str>
<str name="suggestAnalyzerFieldType">text_general</str>
<str name="buildOnStartup">true</str>
<str name="buildOnCommit">true</str>
<str name="highlight">false</str>
<requestHandler name="/suggesthandler" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="suggest">true</str>
<str name="suggest.count">900</str>
<str name="suggest.dictionary">mySuggester</str>
</lst>
<arr name="components">
<str>suggest</str>
</arr>
</requestHandler>
Hello it started working , not sure what was wrong

How to make solr suggestion work for a specific field?

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

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.

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

Solr: I have set `hl=true` but no summaries are being output

I need to get snippets from documents where the query terms are matched to be able to output results similar to Google's snippet beneath the website URL. For example:
Snippet - Wikipedia, the free encyclopedia
en.wikipedia.org/wiki/Snippet
A snippet is defined as a small piece of something, it may in more specific contexts refer to: Sampling (music), the use of a short phrase of a recording as an ...
I have set hl=true and even hl.fl='*' in the query URL and but no summaries are being output.
Solr FAQs say:
For a field to be summarizable it must be both stored and indexed.
I'm using Nutch and Solr and have set them up using this tutorial. What additional steps to I need to take to be able to do this?
Adding sample query and output:
http://localhost:8983/solr/select/?q=test&version=2.2&start=0&rows=10&indent=on&hl=true
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">57</int>
<lst name="params">
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">test</str>
<str name="hl">true</str>
<str name="version">2.2</str>
<str name="rows">10</str>
</lst>
</lst>
<result name="response" numFound="94" start="0">
<doc>
<arr name="anchor">
<str>User:Sir Lestaty de Lioncourt</str>
</arr>
<float name="boost">0.0</float>
<str name="digest">6c27160d0b08068f3873bb2c063508b3</str>
<str name="id">
http://aa.wikibooks.org/wiki/User:Sir_Lestaty_de_Lioncourt
</str>
<str name="segment">20111029223245</str>
<str name="title">User:Sir Lestaty de Lioncourt - Wikibooks</str>
<date name="tstamp">2011-10-29T21:34:27.055Z</date>
<str name="url">
http://aa.wikibooks.org/wiki/User:Sir_Lestaty_de_Lioncourt
</str>
</doc>
...
</result>
<lst name="highlighting">
<lst name="http://aa.wikibooks.org/wiki/User:Sir_Lestaty_de_Lioncourt"/>
<lst name="http://aa.wikipedia.org/wiki/User:PipepBot"/>
<lst name="http://aa.wikipedia.org/wiki/User:Purodha"/>
...
</lst>
</response>
Looks like you aren't specifying the field to highlight (hl.fl). You should create a text field to use for highlighting (don't use string type) and have it stored/indexed.

Resources