Damon,

thanks for clarifying some aspects of Charles' initial response. I was
about to ask about the "shotgun or" approach, but then went to look into
the whitepaper first, and lo and behold, page 24 explains it all!

http://developer.marklogic.com/pubs/architecture/Inside%20MarkLogic%20Server.pdf

Thanks again, also to Jason for this really well-written and
easy-to-understand text!
Jakob.


cheers,
Jakob.


On Tue, Jan 8, 2013 at 7:36 PM, Damon Feldman
<[email protected]>wrote:

>  Jakob,****
>
> ** **
>
> I want to highlight that Charles’ code uses range index values on both
> “sides” of the join. He pulls values using element-values(), so that comes
> from a range index. Then he uses element-range-query() to do the shotgun
> OR. This is important because the values will line up properly
> (particularly if they use the default collation or if you have a
> non-default collation set both indexes use the same one).****
>
> ** **
>
> Word queries apply stemming and ignore punctuation. Value queries can even
> be a little different from the values in the range indexes, so use range
> indexes on both sides of the join.****
>
> ** **
>
> Yours,
> Damon****
>
> ** **
>
> ** **
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Charles Greer
> *Sent:* Tuesday, January 08, 2013 10:56 AM
> *To:* MarkLogic Developer Discussion
>
> *Subject:* Re: [MarkLogic Dev General] "left join" using search:search or
> cts:search?****
>
>  ** **
>
> Hi Jakob,
>
>
> The way to accomplish this kind of thing using cts:search is pretty well
> understood right now.  Use a "scatter query" or "shotgun OR" technique --
> use cts:values to fetch the identifiers from chapter documents that
> interest you (with a subquery as needed)
>
> Then use the output of that that call as input to a cts:search on book
> documents.
>
> let $vals := cts:values($index-reference-with-book-identifiers, 0, (),
> cts:query("for chapters"))
>
> return cts:search(/, cts:element-range-query(xs:QName("bookid"), "=",
> $vals)
>
> This runs quickly because it's all XQuery on the server.
>
>
> There's no corresponding technique in search API at this time, although
> with a custom constraint one could accomplish it.  It's on my todo list to
> provide examples of this kind of custom code...  The technique would be to
> make an XQuery module with this kind of code in it, and then define a
> custom constraint that would invoke it, so
>
> book:term-in-chapter
>
> would put "term-in-chapter" into the first clause above, and then the
> extension would return results from the cts:search.
>
> Hope that helps a little.  There's good discussion of this technique in
> the "Inside MarkLogic" paper by Jason Hunter.
>
> Charles
>
>
>
> ****
>
>  On 01/08/2013 07:29 AM, Jakob Fix wrote:****
>
>  Hi,
>
> Is it possible to find documents based on a criteria match on a related
> document with the search:search (or cts:search) api ? To explain:
>
> I have separate documents for books and chapters, where each chapter has a
> reference to their parent book via an identifier, and I would like to find
> books which contain either a specific term themselves or in one of their
> chapters. I can’t seem to find a way with the cts:query to make something
> like a left join in SQL.
>
> thanks,
> Jakob. ****
>
>
>
>
> ****
>
> _______________________________________________****
>
> General mailing list****
>
> [email protected]****
>
> http://developer.marklogic.com/mailman/listinfo/general****
>
>
>
> ****
>
> -- ****
>
> Charles Greer****
>
> Senior Engineer****
>
> MarkLogic Corporation****
>
> [email protected]****
>
> Phone: +1 707 408 3277****
>
> www.marklogic.com****
>
>
> _______________________________________________
> 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