where to set default solr query parameters for all requests - solr

I am still new to Solr. I am trying to find a place where I can put default query parameters.
I know I can set default query parameters in places such as
<requestHandler name="/select" class="solr.SearchHandler">
,
<requestHandler name="/query" class="solr.SearchHandler">
, and
<requestHandler name="/browse" class="solr.SearchHandler">.
But what I really want is to set default query parameters for all the above three (or more) sections.
Example default parameters:
<str name="defType">edismax</str>
<str name="qf">
id^2.5
name^2
</str>
Where should I place the above lines in `solrconfig.xml'

In the latest Solr, you would use initParams section for that. The examples shipped with Solr demonstrate it.

Related

General Search Query in Solr

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>

Solr edismax qf and pf defaults not working to boost fields

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" >

Is it possible to filter Solr results using solrconfig.xml?

I have a set of documents in Solr which I search through two different requestHandlers. One requestHandler is used internally and should be able to see all documents. The other is used by a public-facing search engine.
Is there a way I can apply an fq parameter in my requestHandler definition, so that a subset of the documents won't be returned?
In this instance I only want to return documents where the "fivi" field is NOT ZERO.
The request handler wiki page shows how to specify default values:
<requestHandler name="/foo" class="my.package.CustomRequestHandler" />
<!-- initialization args may optionally be defined here -->
<lst name="defaults">
<int name="rows">10</int>
<str name="fl">*</str>
<str name="version">2.1</str>
</lst>
</requestHandler>
But if you don't want them to be able to override the values then use invariants instead of defaults for the name of the lst element.

Solr Highlighting Setup

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.

why i can read only 10 Documents out of 665 results into beans in solr

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>

Resources