Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include another XML file from within a Solr schema.xml?

Tags:

solr

I've got a number of different cores, each with its own schema, but they all share the same field types. I'd like to remove the duplication of the field type declarations and do something like this in my schema.xml files:

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="foo" version="1.5">
  <fields>
      <field name="_version_" ...
      <field name="id" ...
      ...
  </fields>
  <uniqueKey>id</uniqueKey>
  <include "/path/to/field_types.xml">
</schema>

I don't see any mechanism in the docs to accomplish this however. I found one post referring to this:

    <xi:include href="/path/to/field_types.xml" />

But that gives me a launch error: The prefix "xi" for element "xi:include" is not bound.

Anybody have an idea how to perform this type of raw include?

like image 377
Alex Howansky Avatar asked Jun 06 '13 18:06

Alex Howansky


2 Answers

From this past Solr Issue - SOLR-3087, it looks like <xi:include> is the correct syntax, you just need to include the xi namespace reference inline.

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="foo" version="1.5">
  <fields>
      <field name="_version_" ...
      <field name="id" ...
      ...
  </fields>
  <uniqueKey>id</uniqueKey>
  <xi:include href="/path/to/field_types.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
</schema>
like image 137
Paige Cook Avatar answered Nov 20 '22 03:11

Paige Cook


Another clean solution at this problem is add resources as external entities:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE schema
[
    <!ENTITY schemafieldtypes SYSTEM "schemafieldtypes.xml">
]>

then, in the xml, you can add everywhere this:

&schemafieldtypes;
like image 2
freedev Avatar answered Nov 20 '22 03:11

freedev