gpt4 book ai didi

java - 在 Apache Solr 中将 XML 文件索引为纯文本

转载 作者:行者123 更新时间:2023-11-30 07:47:03 28 4
gpt4 key购买 nike

有没有办法将 xml 文件的所有内容转储到单个内容字段中?

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();

我正在从此网址获取输出流,并通过从数据服务器获取输入流来写入内容。

注意:

  1. 上述代码适用于除 xml、csv 和 json 之外的所有文件格式。
  2. 没有来自 solr 的错误消息

示例 XML 文件

<?xml version="1.0" encoding="UTF-8"?>
<content>just a test
</content>

最佳答案

  1. 将内容类型设置为“text/xml”
  2. 将以下行添加到您的代码中:OutputStreamWriter writer = new OutputStreamWriter(solrHttpURLConnection.getOutputStream());writer.write(your_xml_file);writer.flush();

  3. 使用此 url http://localhost:7892/solr/myCore/update?literal.id=1234&commit=true 执行请求对于 json 文件,请使用/update/json/docs

  4. 另请查看有关使用索引处理程序上传数据的文档 https://cwiki.apache.org/confluence/display/solr/Uploading+Data+with+Index+Handlers#UploadingDatawithIndexHandlers-XMLUpdateCommands

关于java - 在 Apache Solr 中将 XML 文件索引为纯文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33778981/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com