Maybe collections could help here?  If the latest
version of each document is in the "LATEST" collection,
then it's simply:

     cts:search (doc(), cts:and-query (cts:collection-query ("LATEST"), 
$random-query))

   You just need to make sure you manage collections
on ingest, so that when a new version of a document is
loaded, the previous latest version is removed from the
"LATEST" collection.

On Aug 22, 2011, at 2:08 AM, Michael Sokolov wrote:

> I'm looking for advice about how best to solve a querying problem for 
> one of our customers using MarkLogic.  We need to be able to search 
> documents that are stored in various versions, and we only want to 
> search the newest version. What I am interested in here is whether it is 
> possible to do this if the "newest version" property has to be computed, 
> not stored.  So something like:
> 
> for $doc in cts:search(doc(), $random-query)
> where $doc/@version = max(doc()/doc[@uri=$doc/@uri]/@version)
> return $doc
> 
> our documents store the document identifier that associates different 
> versions as /doc/@uri
> 
> Is that it? Maybe a range index on /doc/@uri would help there?
> 
> The real kicker is that we also need to be apply an additional 
> constraint in that some users may have access only to certain 
> document-versions, so in those cases we need to search only the newest 
> accessible version of each doc.
> 
> Of course there can be lots of docs matching the $random-query, we want 
> to be able to apply sorting criteria, and get the first page of results 
> efficiently.
> 
> Currently I am planning to generate tags at load-time that should make 
> the querying efficient (basically I will mark, for every possible 
> accessibility condition, the most current version - this is possible, if 
> irritating, due to the structure of the access control rules), but this 
> will introduce pain during document ingestion, and relies on 
> restrictions of the kind of access control rules we can have. So I'm 
> wondering if there is a passable query-time implementation I could use.
> 
> -Mike
> _______________________________________________
> General mailing list
> [email protected]
> http://developer.marklogic.com/mailman/listinfo/general

---
Ron Hitchens {mailto:[email protected]}   Ronsoft Technologies
     +44 7879 358 212 (voice)          http://www.ronsoft.com
     +1 707 924 3878 (fax)              Bit Twiddling At Its Finest
"No amount of belief establishes any fact." -Unknown




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

Reply via email to