Solr : Make XML as response in Solr 4.8.1 - solr

I am using solr 4.8.1.
When I execute any query for testing purpose from Dashboard I get response in JSON(BY DEFAULT)
Can I change it and make XML as default.
Plz refer below screen.
I am taking about dashboard only.
Thanks for looking here.... :)

The default values for your requestHandlers (which is what responds when a query is sent to /query or /select etc.), is set in solrconfig.xml. Here's the example from example/solr in the distribution:
<!-- A request handler that returns indented JSON by default -->
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
</lst>
</requestHandler>
Changing wt to xml will give you a requestHandler that returns it response as XML by default, unless overridden at query time with the wt parameter. There might be parts of the web interface that assumes the response will be json, but I'm pretty sure those supply a value for wt anyway.

I dont know if there is administration for web UI defaults, but you can change html easily:
in
solr-4.8.1\example\solr-webapp\webapp\tpl\query.html
change order of options
<select name="wt" id="wt" title="The writer type (response format).">
<option>xml</option>
<option>json</option>
<option>python</option>
<option>ruby</option>
<option>php</option>
<option>csv</option>
</select>
Whatever option you put on first will be default, or set it selected:
<option selected="selected">
You may also change this html in war file in solr-4.8.1\example\webapps.
Note that path is relative to example from 4.8.1 release

Related

How to highlight multiple words using different formatters in Solr?

I need to perform highlighting for multiple words into the same field but for each one using a specific formatter (prefix and postfix).
Let's say that I have the description field and for a document it has the value: Einstein always excelled at math and physics from a young age. How to highlight math with a pair of a specific prefix and postfix AND ALSO physicswith a different prefix-postfix pair? So, in the end I would like to obtain:
Einstein always excelled at <em class="hl-red">math</em> and <em class="hl-green">physics</em> from a young age
The reason is that in the frontend I have different CSS classes with background-color: red; for hl-red and background-color: green for hl-green for example.
However, I was managed to highlight multiple words into the same field but with the same prefix-postfix pair all over the places, which is not what I want actually. In addition, I tried to add multiple HtmlFormatter entries in solrconfig.xml:
<highlighting>
..............
<formatter name="html" default="true" class="solr.highlight.HtmlFormatter">
<lst name="defaults">
<str name="hl.simple.pre"><![CDATA[<em>]]></str>
<str name="hl.simple.post"><![CDATA[</em>]]></str>
</lst>
<lst name="hl-red">
<str name="hl.simple.pre"><![CDATA[<em class="hl-red">]]></str>
<str name="hl.simple.post"><![CDATA[</em>]]></str>
</lst>
<lst name="hl-green">
<str name="hl.simple.pre"><![CDATA[<em class="hl-green">]]></str>
<str name="hl.simple.post"><![CDATA[</em>]]></str>
</lst>
</formatter>
..............
</highlighting>
but I got HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr: Unknown formatter: hl-green. Also, I didn't find a way to specify an array of prefixes in Solr Admin UI nor in spring-data-solr, just a simple query like this:
SimpleHighlightQuery query = new SimpleHighlightQuery(Objects.requireNonNull(criteria));
HighlightOptions highlightOptions = new HighlightOptions()
.addFields(fields)
.setSimplePrefix(prefix)
.setSimplePostfix(postfix);
query.setHighlightOptions(highlightOptions);
query.setPageRequest(pageable);
return solrTemplate.queryForHighlightPage(MY_CORE, query, MyModel.class);
My assumption is that it is a limitation of the Solr itself.
I was thinking about to write a custom fragmentsBuilder but I do not know exactly if it is the case nor how to do that. For another workaround I was thinking to execute for each word a highlight query, then to store the result, then to execute for the second word another highlight query, store the result and so on. But I don't think it is a good and elegant solution because I will have problems when executing the second query if the second word is: "em" or "class" or "red"/"green" (nested undesired highlighting will occur).
I am using spring-data-solr into a Spring Boot application and Solr 6.6.5 as a (http) service.
Does anyone know how to solve this? Please give me an advice! Any idea will be much appreciated!

How to set default parameters for solr CoreAdminHandler?

Since Solr 7.0 version all handlers return JSON format response. I know I can use <initParams> to configure default response format for known handlers. Though, I can't seem to apply <initParams> configuration to /admin/cores requests that are processed by a special handler CoreAdminHandler that is not defined in solrconfig.xml.
I tried adding <initParams> configuration mapping it to path /admin/cores but that had no effect.
<initParams path="/admin/cores">
<lst name="defaults">
<str name="wt">xml</str>
</lst>
</initParams>
I still get JSON response when I call /admin/cores?action=status.
Is it possible to influence response format for CoreAdminHandler requests via configuration?

SOLR more-like-this query parser returns no results

I am trying to get the more-like-this query parser working on my test system. The test system has SOLR cloud 6.5.0 installed. The MLT handler is enabled with the following configuration:
<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
<lst name="defaults">
<str name="mlt.qf">search_text_st</str>
<str name="mlt.fl">search_text_st</str>
<int name="mlt.minwl">4</int>
<int name="mlt.maxwl">18</int>
</lst>
</requestHandler>
When I query for document similar to a specific document with the handler, I get expected results. For example:
http://localhost:8983/solr/MyCloud/mlt?q=id:123
The above query will return results:
"response":{"numFound":361,"start":0,"maxScore":113.24594,"docs":[...]}
However, when I try an equivalent query using the MLTQParser with {!mlt qf=search_text_st fl=search_text_st minwl=4 maxwl=18}123, I get no results:
http://localhost:8983/solr/MyCloud/select?q=%7B!mlt+qf%3Dsearch_text_st+fl%3Dsearch_text_st+minwl%3D4+maxwl%3D18%7D123
The response looks like this:
"response":{"numFound":0,"start":0,"maxScore":0.0,"docs":[]}
I have done nothing so far to enable or configure MLTQParser, but it does appear to be enabled because I get an error when using a document ID that doesn't exist.
Any idea why this is not working?
I eventually figured out why this was failing. The search_text_st field was being created using copyField. The Cloud MLT Query Parser uses the realtime get handler to retrieve the fields to be mined for keywords. Because of the way the realtime get handler is implemented, it does not return data for fields populated using copyField. (see https://issues.apache.org/jira/browse/SOLR-3743)
Changing the configuration to use the source fields made it work.

Set default search fields in Apache Solr

I am trying to Implement Apache Solr search through SolrNet library.So far I have managed to run an instance of Solr in my machine and make some queries based on specific fields.
My code to do it looks like this
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = solr.Query(new SolrQueryByField("id", "SP2514N"));
This one works fine now,But I would like to make queries with out specifying a field , So that when I enter a search key word solr will look in to the all fields available and return a result.I have Found the code to make it in SolrNet library from here
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = solr.Query(new SolrQuery("SP2514N"));
But this never worked,When I drilled down to bottom ,I found that I need to set default search fields in Solr instance so that Solr will search that fields when nothing else is selected(This is how i understood it I am not sure about this).
So I went to set default fields in Solr ,I took Solrconfig.XML and edited it like this
<requestHandler name="/query" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
<str name="df">id</str>
</lst>
</requestHandler>
[just added <str name="df">id</str> this field as extra].But this too never helped And I am stuck ,Can any one tell me How I could set default search field in Solr correctly?Or am i doing any thing else wrong?
I have Uploaded My Solrconfig file here
I do not know about SolrNet library, but to make a default field for search you need to define DefaultSearchField in schema.xml i.e. <defaultSearchField>FieldName</defaultSearchField>.
You can find this file # <SOLR_HOME>\apache-solr-3.6.0\example\example-DIH\solr\testsyndrome\conf\schema.xml
I hope that's what you are looking for.
Don't start from SolrNet, use Solr's built-in Web Admin interface. Iterate there until you understand the request handlers and the parameters. Then, go back to SolrNet.
In your case, it seems that you changed default request handler and tried to use df parameter twice. I would stick to the original request handler for now just to avoid the extra issue.
With using df parameter, are you trying to search a single field or multiple fields? If single field, keep only one value for the parameter. If multiple, you need to switch to using eDisMax, where you can provide a set of fields.
Again, admin interface lets you experiment with it, then you can add it into the handler's default parameter.

calling a custom request handler from another one in solr

Is there a way to call one custom request handler from another in Solr. eg : i have /myhandler1 and /myhandler2 defined as custom request handlers in the solrconfig.xml. Defined like this
<requestHandler name="/my handler1" class="solr.CSVRequestHandler">
<lst name="defaults">
<str name="update.chain">mylogupdate</str>
<str name="stream.contentType">application/csv</str>
</lst>
</requestHandler>
and
<requestHandler name="/myhandler2" class="solr.CSVRequestHandler">
<lst name="defaults">
<str name="update.chain">mylogupdate</str>
<str name="stream.contentType">application/csv</str>
</lst>
</requestHandler>
is there a way to call /myhandler2 from /myhandler1. basically i want to use handler 1 to do some processing and then redirect it to another handler to do a second task.
the larger problem is this:
given a line like this ,
2012-01-04 23:11:41,450 AltQ:RCR-TRP: 101863261
i can split this on a comma separator and get two fields. i further want the second field to be split on a space separator and i want to store these values to different fields
like
val1:450
val2: altQ:RCR-TRP:
val3:101863261
and so on...
For the benefit of the ppl .. I still haven't found a way to redirect requests handlers..but the other problem however was solved . I found a work around to it by defining my own custom processor < that extends update request processor >
http://wiki.apache.org/solr/UpdateRequestProcessor#Processor_Customization_Examples
and i used JAVA to manipulate the document !

Resources