[MarkLogic Dev General] db:fields

Danny Sokolsky Danny.Sokolsky at marklogic.com
Tue Oct 26 09:59:43 PDT 2010


You can also use the Admin API to help you construct the field (or other indexing options).  Just construct the elements, do not save them to the configuration (that is, do not use admin:save-configuration).  Here is an example:

xquery version "1.0-ml";

import module namespace admin = "http://marklogic.com/xdmp/admin" 
		  at "/MarkLogic/admin.xqy";
declare namespace db="http://marklogic.com/xdmp/database";
		
		
  let $config := admin:get-configuration()
  let $dbid := xdmp:database("Documents")
  let $fieldspec := admin:database-field("myField", fn:true() )
  let $includeelem :=   
    admin:database-included-element("http://myuri/namespace",
    "element-name", 1.0, "", "myAttribute", "some value")

  return
  admin:database-add-field-included-element(
    admin:database-add-field($config, $dbid, $fieldspec), $dbid, 
    "myField", $includeelem)

    //db:database[db:database-name eq "Documents"]
    //db:field[db:field-name eq "myField"]

=>
<field xmlns="http://marklogic.com/xdmp/database" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <field-name>myField</field-name>
  <include-root>true</include-root>
  <included-elements>
    <included-element>
      <namespace-uri>http://myuri/namespace</namespace-uri>
      <localname>element-name</localname>
      <weight>1</weight>
      <attribute-namespace-uri/>
      <attribute-localname>myAttribute</attribute-localname>
      <attribute-value>some value</attribute-value>
    </included-element>
  </included-elements>
  <excluded-elements/>
</field>

-Danny

-----Original Message-----
From: general-bounces at developer.marklogic.com [mailto:general-bounces at developer.marklogic.com] On Behalf Of Shannon
Sent: Tuesday, October 26, 2010 8:10 AM
To: Mary Holstege; General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] db:fields

Mary, this is helpful in multiple ways, answered all my questions, thanks a lot!

On Oct 26, 2010, at 8:47 AM, Mary Holstege wrote:

> 
> The DB index options follow the schema Config/databases.xsd but are
> not looking at your database settings unless you have the use-db-config
> option set to true (in which case all the fields will automatically
> be used).  If you want a field just for distinctive-terms, then
> the full field set up needs to be in the options node, e.g.
> 
> 
>      <field xmlns="http://marklogic.com/xdmp/database">
> 	<field-name>Sources</field-name>
> 	<include-root>false</include-root>
> 	<word-lexicons>
> 	  <word-lexicon>http://marklogic.com/collation/en/S1</word-lexicon>
> 	</word-lexicons>
> 	<included-elements>
> 	  <included-element>
> 	    <namespace-uri/>
> 	    <localname>SOUR</localname>
> 	    <weight>1.0</weight>
> 	    <attribute-namespace-uri/>
> 	    <attribute-localname/>
> 	    <attribute-value/>
> 	  </included-element>
> 	</included-elements>
> 	<excluded-elements>
> 	  <excluded-element>
> 	    <namespace-uri/>
> 	    <localname>REPO NOTE DATA</localname>
> 	  </excluded-element>
> 	</excluded-elements>
>      </field>
> 
> //Mary
> 
> 
> On Mon, 25 Oct 2010 20:14:10 -0700, Shannon <Shiflett at virginia.edu> wrote:
> 
>> Hi,
>> 
>> I get the error, "Invalid options node: /*:options/*:fields" when I try the following query:
>> 
>> cts:distinctive-terms(
>> 	doc("/product-0813925045.xml"),
>> 	<options xmlns="cts:distinctive-terms" xmlns:db="http://marklogic.com/xdmp/database">
>> 		<db:fields>true</db:fields>
>> 	</options>
>> )
>> 
>> The API reference doesn't provide an example.... This is a somewhat general problem I tend to run into when configuring options nodes, such as for search:search--more documentation in this area would be great!
>> 
>> I've tried several variations, such as <db:fields><db:field name="like-titles" collation="http://marklogic.com/collation/en/S1/CU/MO" /></db:fields>
>> 
>> Probably I'm using it incorrectly. Can I specify the field I want to use? That is what I'm aiming for. Or should I use an XPath union to narrow the path from which terms are extracted?
>> 
>> Thanks!
>> _______________________________________________
>> General mailing list
>> General at developer.marklogic.com
>> http://developer.marklogic.com/mailman/listinfo/general
> 
> 
> -- 
> Using Opera's revolutionary email client: http://www.opera.com/mail/

_______________________________________________
General mailing list
General at developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general


More information about the General mailing list