我会尝试在SOLR上放置一个xml文档(现在我使用的是7.3.0版本),而不需要在data中设置特定的字段,也不需要放置一个标记来获取所有其他的字段。我尝试了无模式模式,但没有得到任何文件。有可能以某种方式做这件事,还是SOLR无法处理呢?
这是我的SOLR document.xml的一个例子。我想检测所有的标签,并得到相对的值,而不编辑任何字段。就像我说的,我尝试了无模式模式,但它没有起作用。
<?xml version="1.0" encoding="UTF-8"?>
<digital_archive xmlns="https://www.site" dataCreazione="2017-05-11T17:15:00">
<DocumentalCategory>some data</DocumentalCategory>
<customer>some data</customer>
<producer>some data</producer>
<documentOwner>some data</documentOwner>
<sources>
<source>
<idc>
<id scheme="adfr">some data</id>
<name>some data</name>
<path>sources\source\some_path.XML</path>
<hash alg="SHA-256">3748738</hash>
</idc>
<vdc>
<id scheme="some data">some data.XML</id>
<timeReference>2017-03-17T14:19:01+0100</timeReference>
</vdc>
</source>
</sources>
<ud>
<metadati>
<Name>Jane</Name>
<Surname>Doe</Surname>
<FiscalCode>dsrsd6w7hedw</FiscalCode>
<Date>29.10.2017</Date>
</metadati>我预期的结果是这样的:
<field name="DocumentalCategory">some data</DocumentalCategory>
<field name="customer">some data</customer>
<field name="producer">some data</producer>
<field name="documentOwner">some data</documentOwner>
<field name="sources">
<field name="source">
<field name="idc">
<field name="id" scheme="adfr">some data</id>
<field name="name">some data</name>
<field name="path">sources\source\some_path.XML</path>发布于 2018-05-17 11:44:55
Solr不是一个数据库,而是一个搜索引擎。它的目标是给你好的搜索结果,保留原有的结构是不那么重要的。
虽然有一些方法可以使用嵌套文档,但您会发现,随后的搜索将使您真正重新思考您的导入过程。
因此,我建议您后退一步,考虑如何首先找到这些信息,以及返回什么级别的记录/子记录。然后,您可以重新讨论导入问题。
模式不会在这里帮助您,因为它仍然希望您的文档是Solr格式,无论是XML、JSON还是CSV。这里有一种自定义XML格式。所以,你需要以某种方式改变它。您可以使用并在执行过程中定义映射或XSLT转换,使其符合Solr的期望。无论哪种方式,您都很可能需要进行一些平面化和id映射。
发布于 2020-03-06 14:22:16
使用xslt将您的自定义xml转换为solr xml,以下是我的xml:-
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="Rule.xsl"?>
<collection>
<movie>
<title>abc</title>
<year>2016</year>
<genre>comedy</genre>
</movie>
<movie>
<title>xyz</title>
<year>2017</year>
<genre>animated</genre>
</movie>
<movie>
<title>pqr</title>
<year>2018</year>
<genre>action</genre>
</movie>
</collection>下面是执行转换的xsl文件:-
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match='/collection'>
<add>
<xsl:apply-templates select="movie"/>
</add>
</xsl:template>
<!-- Ignore score (makes no sense to index) -->
<xsl:template match="movie/*[@name='score']" priority="100"></xsl:template>
<xsl:template match="movie">
<xsl:variable name="pos" select="position()"/>
<doc>
<xsl:apply-templates>
<xsl:with-param name="pos"><xsl:value-of select="$pos"/></xsl:with-param>
</xsl:apply-templates>
</doc>
</xsl:template>
<!-- Flatten arrays to duplicate field lines -->
<xsl:template match="movie/arr" priority="100">
<xsl:variable name="fn" select="@name"/>
<xsl:for-each select="*">
<xsl:element name="field">
<xsl:attribute name="name"><xsl:value-of select="$fn"/></xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:template match="movie/*">
<xsl:variable name="fn" select="@name"/>
<xsl:element name="field">
<xsl:attribute name="name"><xsl:value-of select="local-name()"/></xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>转换版本:
<add>
<doc>
<field name="title">abc</field>
<field name="year">2016</field>
<field name="genre">comedy</field>
</doc>
<doc>
<field name="title">xyz</field>
<field name="year">2017</field>
<field name="genre">animated</field>
</doc>
<doc>
<field name="title">pqr</field>
<field name="year">2018</field>
<field name="genre">action</field>
</doc>
</add>联机xslt url:在这里输入链接描述
https://stackoverflow.com/questions/50373262
复制相似问题