Hi Rachel,

Apologies for the late reply. Looking at the dls library code suggests
that the version-id property should normally be present:

declare private function dls-latest-version(
  $uri as xs:string
) as xs:unsignedInt
{
  if (fn:exists(xdmp:directory-properties(version-directory($uri))))
  then
    let $latest :=
      cts:search(
        xdmp:document-properties(),
        cts:and-query((
          cts:element-value-query(
            xs:QName("dls:latest"),"true",
            (),0),
          cts:element-value-query(
            xs:QName("dls:document-uri"),$uri,
            ("exact"),0))),
          ("score-simple"),0)
    return
      if ($latest)
      then $latest/prop:properties/dls:version/dls:version-id
      else 0
  else 0
};

What version of MarkLogic are you running?

Kind regards,
Geert

> -----Oorspronkelijk bericht-----
> Van: general-boun...@developer.marklogic.com [mailto:general-
> boun...@developer.marklogic.com] Namens Rachel Wilson
> Verzonden: vrijdag 24 januari 2014 16:14
> Aan: MarkLogic Developer Discussion
> Onderwerp: Re: [MarkLogic Dev General] Efficient way to get the version
> number of latest dls managed document
>
> I was just wondering if anyone had any pointers in relation to this
> question.  It's been a busy week on the list and it's only a small
> question I realise, but just in case it slipped through the net...
>
> -----Original Message-----
> From: Rachel Wilson <rachel.wil...@bbc.co.uk>
> Date: Wednesday, 22 January 2014 15:04
> To: MarkLogic Developer Discussion <general@developer.marklogic.com>
> Subject: Efficient way to get the version number of latest dls managed
> document
>
> What is the most efficient way of getting back the version number of the
> latest dls managed document, in a cts:search or similar, given that it
is
> not possible to join two documents?
>
> It would be easy if the current document actually showed the
> <dls:version-id>2</dls:version-id> element (just like the previous
> versions), but it doesn't. It only shows <dls:latest>true</dls:latest>
>
> E.g. Dls properties of latest revision (what we tend to call the
"master"
> document) at /project/myproject/content/a
> <http://bgb01xuev1003.national.core.bbc.co.uk/EnterpriseVault/ViewMessag
> e.a
> sp?VaultId=18D759FC5FAC19A4B9ED689AE23969ADD1110000BGB01XUEV100
> 1&SavesetId=
> 201312147013497~201309131531480000~Z~607DFE45035DC771F5921AC26A
> EFFFB1>:
> <dls:version xmlns:dls="http://marklogic.com/xdmp/dls";>
>     <dls:latest>true</dls:latest>
>     <dls:created>2013-09-13T15:13:57.225869+01:00</dls:created>
>     <dls:author>10428144080895388018</dls:author>
>     <dls:annotation/>
>     <dls:deleted>false</dls:deleted>
>   </dls:version>
>
>
> Dls properties of a previous version at
> /project/myproject/content/a_a_versions/1-a
> <http://bgb01xuev1003.national.core.bbc.co.uk/EnterpriseVault/ViewMessag
> e.a
> sp?VaultId=18D759FC5FAC19A4B9ED689AE23969ADD1110000BGB01XUEV100
> 1&SavesetId=
> 201312147013497~201309131531480000~Z~607DFE45035DC771F5921AC26A
> EFFFB1>
> <dls:version xmlns:dls="http://marklogic.com/xdmp/dls";>
>     <dls:version-id>1</dls:version-id>
>
> <dls:document-uri>/project/testapi-editing-
> activity/content/a</dls:document
> -uri>
>     <dls:latest>false</dls:latest>
>     <dls:created>2013-09-13T15:13:55.905791+01:00</dls:created>
>     <dls:replaced>2013-09-13T15:13:56.787683+01:00</dls:replaced>
>     <dls:author>10428144080895388018</dls:author>
>     <dls:annotation/>
>     <dls:deleted>false</dls:deleted>
>   </dls:version>
>
>
> Specifically, I'd like to write a query to retrieve some user defined
> property data from the properties of the "master" document as well as
the
> version number of the latest version.
>
> This won't work because the properties for the document returned by
> dls:documents-query() doesn't have the version number.
> ---
>     for $x in cts:search(xdmp:document-properties(),
>                          cts:and-query((
>                             dls:documents-query(),
>                          ))
>               )
>
>      return
>       <content>
>
>
<fileId>{$x:/prop:properties/prop:myuserdefinedproperty/string()}</fileId>
>
>
<version>{$x/prop:properties/dls:version/dls:version-id/string()}</version
>
>     </content>
> ---
>
> And this won't work because I also need the property in the "master" dls
> document that doesn't exist on the dls versions properties
> ---
>     for $x in cts:search(xdmp:document-properties(),
>                       cts:and-query((
>
cts:element-value-query(xs:QName("dls:latest"),
> "true"),
>
> cts:element-value-query(xs:QName("dls:version-id"), "*", "wildcarded"),
>                       ))
>               )
>
>      return
>       <content>
>
>
<fileId>{$x:/prop:properties/prop:myuserdefinedproperty/string()}</fileId>
>
>
<version>{$x/prop:properties/dls:version/dls:version-id/string()}</version
>
>     </content>
> ---
>
> I suspect that some might suggest denormalising the user defined
property
> (would they?) but for the moment I'm stuck with the data structure as it
> is.
>
> Many thanks,
> Rachel
>
>
>
>
> -----------------------------
> http://www.bbc.co.uk
> This e-mail (and any attachments) is confidential and
> may contain personal views which are not the views of the BBC unless
> specifically stated.
> If you have received it in
> error, please delete it from your system.
> Do not use, copy or disclose the
> information in any way nor act in reliance on it and notify the sender
> immediately.
> Please note that the BBC monitors e-mails
> sent or received.
> Further communication will signify your consent to
> this.
> -----------------------------
> _______________________________________________
> General mailing list
> General@developer.marklogic.com
> http://developer.marklogic.com/mailman/listinfo/general
_______________________________________________
General mailing list
General@developer.marklogic.com
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to