在 MarkLogic 中一次性向字段添加多个选项

Adding multiple options to fields at one go in MarkLogic

似乎由于 databases.xsd,在 MarkLogic 7 中,您无法将所有不同的选项添加到字段在添加字段期间作为字段 xml 的一部分,就像您在 MarkLogic 5 中所做的那样。 示例:

 <three-character-searches> true </three-character-searches>
 <three-character-word-positions> true </three-character-word-positions>
 <two-character-searches> true </two-character-searches>

我可以添加的选项很少。一次性添加它们而不是为每个选项使用 API 的方法是什么,例如

admin:database-set-field-stemmed-searches

等等

编辑

以下代码在 ML 5.0.5 上有效。

 xquery version "1.0-ml";

  import module namespace admin = "http://marklogic.com/xdmp/admin" 
          at "/MarkLogic/admin.xqy";

let $field:=<field xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://marklogic.com/xdmp/database">
      <field-name>myField</field-name>
      <include-root>false</include-root>
      <word-lexicons>
        <word-lexicon>http://marklogic.com/collation/codepoint</word-lexicon>
      </word-lexicons>
      <stemmed-searches>decompounding</stemmed-searches>
      <word-searches>true</word-searches>
      <fast-phrase-searches>true</fast-phrase-searches>
      <fast-case-sensitive-searches>true</fast-case-sensitive-searches>
      <fast-diacritic-sensitive-searches>true</fast-diacritic-sensitive-searches>
      <trailing-wildcard-searches>true</trailing-wildcard-searches>
      <trailing-wildcard-word-positions>true</trailing-wildcard-word-positions>
      <three-character-searches>true</three-character-searches>
      <three-character-word-positions>true</three-character-word-positions>
      <two-character-searches>true</two-character-searches>
      <one-character-searches>true</one-character-searches>
      <included-elements>
        <included-element>
          <namespace-uri>ns</namespace-uri>
          <localname>in</localname>
          <weight>9</weight>
          <attribute-namespace-uri/>
          <attribute-localname/>
          <attribute-value/>
        </included-element>
       </included-elements>
      <excluded-elements>
        <excluded-element>
          <namespace-uri>ns</namespace-uri>
          <localname>ex</localname>
        </excluded-element>
      </excluded-elements>
    </field>



let $config := admin:get-configuration()

let $config:=admin:database-add-field($config,xdmp:database(),$field)
return admin:save-configuration($config)

看来是讲究顺序了。当您通过 Admin UI 创建字段时,我将您的代码与 MarkLogic 记录的内容进行了比较。基于此,我将 进一步向下移动。

xquery version "1.0-ml";

import module namespace admin = "http://marklogic.com/xdmp/admin" 
          at "/MarkLogic/admin.xqy";

let $field:=
  <field xmlns="http://marklogic.com/xdmp/database" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <field-name>myField</field-name>
    <include-root>false</include-root>
    <stemmed-searches>decompounding</stemmed-searches>
    <word-searches>true</word-searches>
    <fast-phrase-searches>true</fast-phrase-searches>
    <fast-case-sensitive-searches>true</fast-case-sensitive-searches>
    <fast-diacritic-sensitive-searches>true</fast-diacritic-sensitive-searches>
    <trailing-wildcard-searches>true</trailing-wildcard-searches>
    <trailing-wildcard-word-positions>true</trailing-wildcard-word-positions>
    <three-character-searches>true</three-character-searches>
    <three-character-word-positions>true</three-character-word-positions>
    <two-character-searches>true</two-character-searches>
    <one-character-searches>true</one-character-searches>
    <word-lexicons>
      <word-lexicon>http://marklogic.com/collation/codepoint</word-lexicon>
    </word-lexicons>
    <included-elements>
      <included-element>
        <namespace-uri>ns</namespace-uri>
        <localname>in</localname>
        <weight>9</weight>
        <attribute-namespace-uri/>
        <attribute-localname/>
        <attribute-value/>
      </included-element>
    </included-elements>
    <excluded-elements>
      <excluded-element>
        <namespace-uri>ns</namespace-uri>
        <localname>ex</localname>
      </excluded-element>
    </excluded-elements>
  </field>

let $config := admin:get-configuration()
let $config:=admin:database-add-field($config, xdmp:database(), $field)
return admin:save-configuration($config)

成功了。

话虽如此,我还是不得不指出您是在围绕 API 而不是使用它,这让人感觉很脆弱。谨慎行事。