[英]Index XML files in Apache Solr as plain text
有什么办法可以将xml文件的所有内容转储到单个content字段中?
schema.xml中
<field name="id" type="string" indexed="true" stored="true" required="true" multiValued="false" />
<field name="content" type="text_general" indexed="true" stored="true" multiValued="false" termVectors="true" termPositions="true" termOffsets="true"/>
用于索引的代码
HttpUrlConnection solrHttpURLConnection = "http://localhost:7892/solr/myCore/update/extract?literal.id=1234&commit=true "
solrHttpURLConnection.setDoOutput(true);
solrHttpURLConnection.setDoInput(true);
solrHttpURLConnection.setUseCaches(false);
solrHttpURLConnection.setAllowUserInteraction(false);
solrHttpURLConnection.setRequestProperty("Content-type", type);
solrHttpURLConnection.connect();
我正在从此url中获取输出流,并通过从dataServer中获取输入流来编写内容。
注意:
样本XML文件
<?xml version="1.0" encoding="UTF-8"?>
<content>just a test
</content>
将以下行添加到您的代码中:OutputStreamWriter writer = new OutputStreamWriter(solrHttpURLConnection.getOutputStream()); writer.write(your_xml_file); writer.flush();
使用此URL执行请求http:// localhost:7892 / solr / myCore / update?literal.id = 1234&commit = true对于json文件,请使用/ update / json / docs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.