Am I missing something with highlighting in Solr? I cant get it to work in my Solr xml results page.
http://localhost:8080/solr/select?q=book&hl=true
Above is a basic query for the term book which I would like highlighted in my results.
I also have the default set in my solrconfig:
<searchComponent class="solr.HighlightComponent" name="highlight">
<highlighting>
<!-- Configure the standard fragmenter -->
<!-- This could most likely be commented out in the "default" case -->
<fragmenter name="gap"
default="true"
class="solr.highlight.GapFragmenter">
<lst name="defaults">
<int name="hl.fragsize">100</int>
</lst>
</fragmenter>
Is there something I need to set in my 'content' field in the schema?
Thank you in advance.
You need to also set the field(s) that you want highlighting results returned for:
http://localhost:8080/solr/select?q=book&hl=true&hl.fl=content
You can probably set this in the section of your as well.
Edit:
You also need to enable the highlight component in your <requestHandler name="/select" class="solr.SearchHandler"> in your solrconfig.xml file. Assuming that you are using the standard /select request handler. To do that, you need to uncomment and modify the <arr name="components"> section at the bottom of that <requestHandler> section to look like the following:
<arr name="components">
<str>highlight</str>
</arr>
That should enable the highlighting component in your searches.
Related
I have tried to run a single term search in Solr 9.0 through by using
q=term
(e.g. http://localhost:8983/solr/windowstest/select?indent=true&q.op=OR&q=yelp).
I've noticed that older versions of Solr were able to handle such a request but now I can only search all fields for that term by adding using OR
q=id:yelp OR subject:yelp OR body:yelp
(e.g. http://localhost:8983/solr/windowstest/select?indent=true&q.op=OR&q=id%3Ayelp%20OR%20subject%3Ayelp%20OR%20body%3Ayelp).
Is there a way to not have to indicate the fields?
There is no setting for "searching all fields"; however, what is usually done is to have a single field as the copyField destination for all fields. You can do this by defining a catch-all field (by default named _text_, and then configuring <copyField src="*" dest="_text_"> - making the content of all the fields get copied into _text_.
You can then set the default search field (i.e. where there isn't a field name given) with the df parameter in the query - the default field.
http://localhost:8983/solr/windowstest/selectq.op=OR&q=yelp&df=_text_
If you want to set this as the default, you configure it as a default parameter in solrconfig.xml under the specific request handler:
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="df">_text_</str>
<int name="rows">10</int>
</lst>
</requestHandler>
.. or by using initparams:
<initParams path="/update/**,/query,/select,/tvrh,/elevate,/spell">
<lst name="defaults">
<str name="df">_text_</str>
</lst>
</initParams>
I just want the default operator to be AND and not an OR for every basic search. For a particular collection, in the schema.xml and solrconfig.xml files I set the defaultOperator to AND (makes no difference) and set the mm to 100%, restart the CF Add-on Server services and still no difference when doing a search. I am on Coldfusion 2018.
<cfsearch
name='qHearings'
collection='hearings_collection'
criteria='conflicts of interest'
/>
returns me documents with words 'conflicts' OR 'interest'. If I change it to:
<cfsearch
name='qHearings'
collection='hearings_collection'
criteria='conflicts AND of AND interest'
/>
returns me documents with words 'conflicts' AND 'interest'. This is good but my users don't like be told to use AND and I hear endless comments about why can't it be like google search :(
I have been reading up on SOLR and it seems like many have the same problem but I try the suggestions but I always get an OR search result.
Anyone got basic SOLR search to default to AND?
Thank you #MatsLindh, your comments lead me to the right path! I was setting
<solrQueryParser q.op="AND"/>
in the schema.xml thinking that was where I was suppose to do it (of course, it made no difference I still got an OR search result).
I couldn't find a Solr log for Coldfusion but I played around with solrconfig.xml file for one particular collection. After re-reading your comments I added
<str name="q.op">AND</str>
to the "standard" handler and it worked! I am somewhat embarrassed because it wasn't obvious to me to do it that way and for all my googling I didn't see examples of it being done that way (I only saw it as being passed in a query parameter).
So my standard handler looks like this:
<requestHandler name="standard" class="solr.StandardRequestHandler" default="true">
<!-- default values for query parameters -->
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="hl.fl">summary title </str>
<str name="df">contents</str>
<str name="q.op">AND</str>
<str name="mm">100%</str>
<!-- omp = Only More Popular -->
<str name="spellcheck.onlyMorePopular">false</str>
<!-- exr = Extended Results -->
<str name="spellcheck.extendedResults">false</str>
<!-- The number of suggestions to return -->
<str name="spellcheck.count">1</str>
</lst>
<arr name="last-components">
<str>spellcheck</str>
</arr>
</requestHandler>
Super embarrassing for me that the solution was so simple.
I am attempting to set up a request handler that will boost certain fields by different amounts. I have the following request handler.
<requestHandler name="/select" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="start">0</str>
<int name="rows">10</int>
<str name="defType">edismax</str>
<str name="qf">
title^50.0 searchTitle^7.0 keywords^5.0 content^1.0 text^1.0
</str>
<str name="pf">
title^50.0 searchTitle^7.0 keywords^5.0 content^1.0 text^1.0
</str>
<str name="df">text</str>
</lst>
</requestHandler>
However, the fields aren't being boosted correctly, if at all. I noticed that documents with the search term in the title field aren't appearing any higher than documents with the search term in the text field. Arbitrarily re-arranging the weights produces the same document order each time.
When I go into the solr web interface/admin UI and do a search I get the same results. However, if I explicitly check the edismax checkbox and enter the field-boost data in the qf and pf boxes I get the results and the weighting I would expect.
In fact, I also just tried changing the rows value to 5 and still received the same result. It looks like my queries aren't being handled by the /select handler, even though that is what I choose both in the solr Admin UI and when I create the HttpSolrServer object to do the queries from the server.
I am using solr v4.8.0.
Any help would be appreciated.
Check setting in solrconfig for
<requestDispatcher handleSelect="false" >
If you want to use select as a requesthandler, this needs to be
<requestDispatcher handleSelect="true" >
I'm using Solr example server to do an investigation. After fed it with all cached documents, mostly html files, it works fine except the highlight part.
The request URL I'm using is as followed,
http://localhost:8983/solr/collection1/select?q=keyword&wt=xml&hl=true
And the XML response is as followed,
<response>
<lst name="responseHeader">...</lst>
<result name="response" numFound="371" start="0">
<doc>
<arr name="links">
<str>rect</str>
<str>FJU_KDJFJJ_DJ_13</str>
</arr>
<str name="id">
F:\SkyDrive\funproj\cache\adfadf\asdff.htm
</str>
<arr name="title">
<str>asdff.htm</str>
</arr>
<arr name="content_type">
<str>text/html; charset=ISO-8859-1</str>
</arr>
<str name="resourcename">
F:\SkyDrive\funproj\cache\adfadf\asdff.htm
</str>
<arr name="content">
<str>...</str>
</arr>
<long name="_version_">1418589758873927680</long>
</doc>
<doc>...</doc>
</result>
<lst name="highlighting">
<lst name="F:\SkyDrive\funproj\cache\adfadf\asdff.htm"/>
<lst name="F:\SkyDrive\funproj\cache\cvzcv\c58053e10vq.htm"/>
<lst name="F:\SkyDrive\funproj\cache\hgdfhdfgh\c00302e10vq.htm"/>
<lst name="F:\SkyDrive\funproj\cache\asdfasdf\c00945e10vq.htm"/>
<lst name="F:\SkyDrive\funproj\cache\hjmyukt\asfdf06113002_03312010.htm"/>
<lst name="F:\SkyDrive\funproj\cache\nmvbmnm\saf0q033111.htm"/>
<lst name="F:\SkyDrive\funproj\cache\lkiullkl\a10-5974_110q.htm"/>
<lst name="F:\SkyDrive\funproj\cache\jhlhjkl\fdfinal.htm"/>
<lst name="F:\SkyDrive\funproj\cache\vcbxcbvcx\zynex10q33110_5132010.htm"/>
<lst name="F:\SkyDrive\funproj\cache\yuiuiou\v185403_10q.htm"/>
</lst>
</response>
The response, no matter JSON or XML, does not have the highlight part at all. I've checked the solrconfig.xml both in local file system and the admin page of the example server. The Highlighting is default on and pre/post are set to ""/"". The example search portal itself works fine with highlight in its results. But since it's not AJAX, there's no way for me to check its result through chrome.
What did I do wrong?
You have to define the fields using hl.fl which needs to be highlighted. For example, if you want to search and highlight hits in content field, you can use query below:
http://localhost:8983/solr/collection1/select?q=content:keyword&wt=xml&hl=true&hl.q=content:keyword&hl.fl=content
By default highlighting response returns only one snippet,even if your field have multiple hits. Also the length of snippet(fragsize) is set to 100 chars by default.
You can use hl.snippets and hl.fragsize to modify them.
For example, to modify fragsize:
http://localhost:8983/solr/collection1/select?q=content:keyword&wt=xml&hl=true&hl.q=content:keyword&hl.fl=content&hl.fragsize=5000
Passing hl.fragsize=0 will make fragsize unlimited.
For changing number of snippets:
http://localhost:8983/solr/collection1/select?q=content:keyword&wt=xml&hl=true&hl.q=content:keyword&hl.fl=content&hl.snippets=10
Refer to solr wiki for more parameters.
you would need to add the field hl.fl on which the highlighting needs to be enabled.
Default value for the param is blank.
I have indexed my database tables into solr using DataImportHandler. Now when I query the server it shows me that the number of results found 665. But when i try to assign it to beans like List itemList = rsp.getBeans(Item.class), it is giving me only 10 results.
Can some one help me out on this.
Thanks in Advance.
When you don't define the amount of rows (documents) to fetch, Solr defaults to fetching 10 documents, as explained in the docs.
By default Solr returns only 10 Documents. If you want to fetch all documents, you will need to update solrConfig.xml file of Core (path : /solr/server/solr/core_name/conf/solrConfig.xml) :
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10000000</int> <!--you can update it to some large value that is higher than the possible number of rows that are expected.-->
</lst>
</requestHandler>
You might have to edit your solrconfig.xml.
There change the "/select" Request Handler like this.
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">1000</int> <!-- Change this as you want -->
<str name="df">text</str>
</lst>
</requestHandler>