如何在Solr中将ResponseWriter设置为非默认值 [英] How to set ResponseWriter to non-default in Solr

查看:93
本文介绍了如何在Solr中将ResponseWriter设置为非默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,它们只是在搜索Solr Server.

SolrServer server = new CommonsHttpSolrServer(url);
SolrQuery searchquery = new SolrQuery("company profile");
QueryResponse response = server.query(searchquery)

我希望在json中有响应,而不是默认值xml.因此,我进入了solrconfig.xml文件并启用了以下行:

<queryResponseWriter name="json" class="org.apache.solr.request.JSONResponseWriter" />

但是,从控制台,我仍然将wt = javabin编码为搜索查询请求.

此外,我已经修改了上面的代码,如下所示:

SolrServer server = new CommonsHttpSolrServer(url);
SolrQuery searchquery = new SolrQuery("company profile");
searchquery.setParam("wt", "json");
QueryResponse response = server.query(searchquery)

但是我仍然要进行wt=javabin编码和wt=json附加,这样查询现在看起来像这样:

webapp/solr path=/select params={wt=javabin&wt=json}

我在做错什么吗?

谢谢

解决方案

SolrJ仅支持javabinxml格式(可通过

I want to have the response in json, other than the default which is xml. So I went into the solrconfig.xml file and enabled the following line:

<queryResponseWriter name="json" class="org.apache.solr.request.JSONResponseWriter" />

However, from the console, I'm still getting wt=javabin encoded to the search query request.

Also, I've modified the above code like this:

SolrServer server = new CommonsHttpSolrServer(url);
SolrQuery searchquery = new SolrQuery("company profile");
searchquery.setParam("wt", "json");
QueryResponse response = server.query(searchquery)

But I'm still getting wt=javabin encoded and wt=json also appended, such that the query now looks like this:

webapp/solr path=/select params={wt=javabin&wt=json}

Is there anything I'm doing wrong?

Thanks

解决方案

SolrJ only supports the javabin and xml formats (configurable with CommonHttpSolrServer.setParser).

But why would you want to use JSON? Javabin is by far the format which provides the best decompression speed, its drawback being that is is not human-readable, on the contrary to JSON and XML (which is not a problem in this case since SolrJ is parsing the result for you).

这篇关于如何在Solr中将ResponseWriter设置为非默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆