Hi Gaya,

If you put the documents in a shared database, and separate them using 
collections, then something resembling David's (pseudo) code sample will work:

for $doc1 in collection("DB1"), $doc2 in collection("DB2")
where $doc1//doc_k...@doc_key_context="a"]
   eq $doc2//doc_k...@doc_key_context="a"]
return $doc1

Otherwise you will have to capture the documents from the other database 
separately. I am pretty sure that won't work efficiently when you are dealing 
with large numbers of files:

let $docs_db2 := xdmp:eval("doc()", (), <options 
xmlns="xdmp:eval"><database-id>{xdmp:database("DB2")}</database-id></options>)
for $doc1 in doc(), $doc2 in $docs_db2
where $doc1//doc_k...@doc_key_context="a"]
   eq $doc2//doc_k...@doc_key_context="a"]
return $doc1

Note: there are more efficient algorithms possible utilizing the cts lexicons 
and cts search functions. But that may requiring renaming <doc_key 
doc_key_context="a"> kind of elements to some uniquely named element..

Kind regards,
Geert

> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Gaya Rac
> Sent: woensdag 31 maart 2010 17:54
> To: General Mark Logic Developer Discussion
> Subject: Re: [MarkLogic Dev General] Inner join
> 
> The XML fragment is part of larger file. 
> 
> Database 1 holds sample XML files like below:
> <document coll="coll1">
> <subdoc coll="coll1">
> <grp1>
> <doc_key doc_key_context="a">2004120487</doc_key>
> <doc_key doc_key_context="b">20487</doc_key>
> </grp1>
> <grp2>
> ...
> </grp2>
> </subdoc>
> </document>
> 
> Database 2 holds sample XML files like below:
> <document coll="coll2">
> <subdoc coll="coll2">
> <grp1>
> <doc_key doc_key_context="a">2004120487</doc_key>
> <doc_key doc_key_context="b">20487</doc_key>
> </grp1>
> <grp3>
> ...
> </grp3>
> </subdoc>
> </document>
> 
> The join should happen on <doc_key 
> doc_key_context="a">2004120487</doc_key>
> 
> I'll also look into holding all the XML docs in one database 
> and logically separate them.
> 
> Thanks, Gaya
> 
> 
> 
> On Wed, Mar 31, 2010 at 11:35 AM, Geert Josten 
> <[email protected]> wrote:
> 
> 
>       Hi Gaya,
>       
>       I am a bit confused by your XML fragment. It not 
> well-formed XML. The decimal number, is that an attribute 
> name, attribute value or the value of the element itself? And 
> is each <doc_key> element stored as a separate document or 
> are they part of one large file?
>       
>       Next to this, it is less optimal to access across 
> databases. You will need an xdmp:eval with database-id option 
> to retrieve documents from one database to compare them with 
> documents from another. It is better to put all documents in 
> one database and logically separate them by putting them in a 
> separate directory or collection..
>       
> 
>       Kind regards,
>       Geert
>       
>       >
>       
>       
>       drs. G.P.H. (Geert) Josten
>       Consultant
>       
>       
>       Daidalos BV
>       Hoekeindsehof 1-4
>       2665 JZ Bleiswijk
>       
>       T +31 (0)10 850 1200
>       F +31 (0)10 850 1199
>       
>       mailto:[email protected]
>       http://www.daidalos.nl/
>       
>       KvK 27164984
>       
>       P Please consider the environment before printing this mail.
>       De informatie - verzonden in of met dit e-mailbericht - 
> is afkomstig van Daidalos BV en is uitsluitend bestemd voor 
> de geadresseerde. Indien u dit bericht onbedoeld hebt 
> ontvangen, verzoeken wij u het te verwijderen. Aan dit 
> bericht kunnen geen rechten worden ontleend.
>       
>       
>       > From: [email protected]
>       > [mailto:[email protected]] On 
> Behalf Of Gaya Rac
>       
>       > Sent: woensdag 31 maart 2010 16:32
>       
>       > To: General Mark Logic Developer Discussion
>       
>       > Subject: Re: [MarkLogic Dev General] Inner join
>       
>       >
>       > Thanks Lee.
>       > If we want to find matching records from all the XMLs in
>       > database: DB1 with all the XMLs in database: DB2, then we
>       > need to access DB2 from DB1 and then perform the join right?
>       >
>       > Also the doc_key element, has an attribute field
>       > doc_key_context and we want to find matching records based on
>       >  <doc_key doc_key_context="a" 20021234>
>       >
>       >
>       > On Wed, Mar 31, 2010 at 10:17 AM, Lee, David
>       > <[email protected]> wrote:
>       >
>       >
>       >       for $a = doc("DB1.xml")//doc_key
>       >
>       >        for $b = doc("DB2.xml")//doc_key
>       >
>       >          where $a/doc_key_context eq $b/doc_key_context
>       >
>       >         return ..
>       >
>       >
>       >
>       >       From: [email protected]
>       > [mailto:[email protected]] On 
> Behalf Of Gaya Rac
>       >       Sent: Tuesday, March 30, 2010 12:07 PM
>       >       To: [email protected]
>       >       Subject: [MarkLogic Dev General] Inner join
>       >
>       >
>       >
>       >       Hi,
>       >
>       >       Is there a way to perform joins on Mark logic databases?
>       >
>       >       I've a database:DB1 which has key field
>       >       <doc_key doc_key_context="a" 20021234>
>       >       <doc_key doc_key_context="b" 1234>
>       >
>       >       I've a second database:DB2 which has same key field
>       >       <doc_key doc_key_context="a" 20021234>
>       >       <doc_key doc_key_context="b" 1234>
>       >
>       >       How can I return all the matching documents 
> from DB1, DB2.
>       >
>       >       Thanks, Gayathri
>       >
>       >
>       >       _______________________________________________
>       >       General mailing list
>       >       [email protected]
>       >       http://xqzone.com/mailman/listinfo/general
>       >
>       >
>       >
>       >
>       >
>       _______________________________________________
>       General mailing list
>       [email protected]
>       http://xqzone.com/mailman/listinfo/general
>       
> 
> 
> _______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to