【问题标题】:SolrConfig inclusion through Xinclude通过 Xinclude 包含 SolrConfig
【发布时间】:2026-02-10 19:10:02
【问题描述】:

我目前在 Riak KV 服务器中使用 Solr 实现。关于 Riak 的默认设置,为了不担心任何软件升级,我需要在我的核心 SolrConfig.xml 中包含额外的配置。我将通过 Ansible 命令以编程方式执行此操作。我想在出厂设置 solrconfig.xml 中添加尽可能少的行。

我需要在我的配置中包含一堆<searchComponent><requestHandler>,因为我希望使用这种模式:

    <config>
      <!-- snip -->
      <xi:include href="solrconfig_extra.xml" xpointer="xpointer(//searchComponent)" xmlns:xi="http://www.w3.org/2001/XInclude" />
      <xi:include href="solrconfig_extra.xml" xpointer="xpointer(//requestHandler)" xmlns:xi="http://www.w3.org/2001/XInclude" />
    </config>

配置文件如下所示:

<?xml version="1.0" encoding="UTF-8" ?>

<container>
  <searchComponent class="solr.SpellCheckComponent" name="suggest">
   <lst name="spellchecker">
     <str name="name">suggest</str>
     <str name="classname">org.apache.solr.spelling.suggest.Suggester</str>
     <str name="lookupImpl">org.apache.solr.spelling.suggest.tst.TSTLookupFactory</str>
     <str name="field">myterms</str>  <!-- the indexed field to derive suggestions from -->
     <float name="threshold">0</float>
     <str name="buildOnCommit">false</str>
  <!--
     <str name="sourceLocation">american-english</str>
  -->
   </lst>
  </searchComponent>

  <requestHandler class="org.apache.solr.handler.component.SearchHandler" name="/suggest">
   <lst name="defaults">
     <str name="spellcheck">true</str>
     <str name="spellcheck.dictionary">suggest</str>
     <str name="spellcheck.onlyMorePopular">true</str>
     <str name="spellcheck.count">5</str>
     <str name="spellcheck.collate">true</str>
   </lst>
   <arr name="components">
     <str>suggest</str>
   </arr>
  </requestHandler>
</container>

不幸的是,Xerces 不支持 xpointer() 架构,并且由于 element() 只接受元素索引,并且需要与包含容器有子容器一样多的插入。

我怎样才能有条不紊地实现这种包容?

  • 从 xerces 切换到另一个 xmlparser 是否容易?我必须提醒您,我不想尽可能多地更改供应商解决方案。
  • 在 SolrConfig 语法中,可能有一个中性元素允许我被包含在配置中(例如 /config/NEUTRALMAGICTAG/requestHandler 被解释为 /config/requestHandler )
  • 我应该放弃并忘记 XInclude 并通过纯 ansible 文件编辑工作吗?

【问题讨论】:

    标签: solr xerces xinclude riak-search


    【解决方案1】:

    TYPO3 使用XML includes for the Solr configuration。这可能会有所帮助。

    请注意,尽管最新的 Solr 使用动态模式,它可能会将包含所有各种包含的文件重写为统一的 托管模式 文件(例如,对于无模式模式)。您可以禁用它或从不触发重写,只需要慎重考虑即可。

    【讨论】: