Hi David,

You specify the data-type to be used for an index in the index definition 
itself. So, if it finds an elem or attr that matches one of the indexes, it 
tries to cast its value to the one of the index and insert it in the index. No 
schema involved there. If casting fails, for instance because an element is not 
following the correct date format, then the indexation of that element fails. 
Not sure, but this could be logged. If you try to query that particular 
element, it will throw an exception telling that indexation wasn't successful..

Schemas are not used for auto recognition of data-typed indexes. You always get 
a word index, but that is string based..

Kind regards,
Geert

-----Oorspronkelijk bericht-----
Van: [email protected] 
[mailto:[email protected]] Namens Lee, David
Verzonden: vrijdag 24 juni 2011 17:06
Aan: General MarkLogic Developer Discussion
Onderwerp: Re: [MarkLogic Dev General] Applying schemas to schema-less documents

Thanks for this info.
Question:  Is there anything that the initial load or indexing of documents 
uses the schema ?
That is, is there a performance/indexing advantage to pre-declaring the schema 
at load time as apposed to importing it in a given xquery.

For example I could imagine indexes indexing date types differently than string 
types - but it would have to know at the time the document was loaded.



----------------------------------------
David A. Lee
Senior Principal Software Engineer
Epocrates, Inc.
[email protected]
812-482-5224


-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Michael Blakeley
Sent: Friday, June 24, 2011 10:37 AM
To: General MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Applying schemas to schema-less documents

The server applies schemas dynamically, looking at whatever happens to be 
available. So yes it's possible. However that can lead to a problem: if I have 
a node 'run/elapsed', I might have two different schemas that contain an 
element 'run'. The server will use the first one it finds.

Because of this I strongly recommend using namespaces and schemas together. A 
schema that targets {mynamespace}run is much less likely to conflict with some 
other schema. You can also disambiguate which schema you want using an 'import 
schema...' prolog expression.

Let's see... there used to be a quick schema tutorial on the developer site. 
Here it is: http://developer.marklogic.com/learn/2007-04-schema

-- Mike

On 24 Jun 2011, at 07:28 , Lee, David wrote:

> Suppose I have a bunch of documents with no namespace and no schemas.
> I would like to apply a schema to these documents so that
>  
> 1) I can avoid lots of casting in my xquery such as
>                 fn:avg(($runs[@status eq 'true']/@elapsed)
> instead of
>                 fn:avg( xs:dayTimeDuration($runs[@status eq 'true']/@elapsed 
> ))
>  
> 2) So that indexes are built knowing about the element and attribute types so 
> that things like
>                 fn:max( xdmp:directory("/logs/" )//run/@elapsed )
> can go through an index instead and be sorted correctly (by dateTimeDuration 
> instead of by string
>  
> Is this possible ?
> If so how ?
>  
> Thanks for suggestions and pointers to RTFM's
>  
>  
>  
>  
> ----------------------------------------
> David A. Lee
> Senior Principal Software Engineer
> Epocrates, Inc.
> [email protected]
> 812-482-5224
>  
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to