2012-03-12 112 views
1

当我使用solrj添加文档solr时,内容是否被编码?solrj是否对内容进行编码?

CommonsHttpSolrServer server = new CommonsHttpSolrServer(
      "http://localhost:8080/solr/"); 
SolrInputDocument doc = new SolrInputDocument(); 
doc.addField("id", 1); 
doc.addField("city", "Zürich"); 
server.add(doc); 
server.commit(); 

因为当我用下面的代码搜索它,我找不到它(其他城镇工作)。

SolrQuery solrQuery = new SolrQuery(); 
solrQuery.set(CommonParams.WT, "json"); 
solrQuery.setQuery("Zürich"); 

QueryResponse rsp = locationSearchServer.query(solrQuery); 
return rsp.getBeans(City.class); 

我可以在该查询参数自动编码,以UTF-8的调试器看到。

我也添加了UTF-8属性到tomcat http://wiki.apache.org/solr/SolrTomcat#URI_Charset_Config但没有任何效果。

我必须添加编码的内容还是为我做solrj?

回答

2

问题是通过GET的查询可能会失败并显示国际字符。通常这应该由Tomcat-Param解决,但在我的情况下不是。

其中工程八方通解决方案是把它作为POST

QueryResponse rsp = locationSearchServer.query(solrQuery, METHOD.POST);