Friday 9 April 2010

MarkLogic: Techniques for querying in-memory fragments using cts:contains

This snippet demonstrates the use of cts:contains and cts:element-attribute-word-query on an in-memory fragment (something that has been stored in the Expanded Tree Cache using a let statement):


To really add power to the search, you can use cts:contains with a cts:and-query. For this example, I want to return link(s) with a class of featured and a rel containing the value "video":

This last example demonstrates the use of an additional cts:or-query. This example creates a list of featured videos and documentation. Using the 'or' query will return any links that have the "featured" class attribute and have a rel of "video" or "pdf":

xquery version '1.0-ml';

let $x :=
Mark Logic Application Builder
Mark Logic Application Builder
Mark Logic Corporation
Mark Logic 4.1 Install Guide

return

Using cts:element-attribute-word-query on an in-memory fragment

Featured Videos and Documentation

    {
    for $item in $x/a
    where cts:contains($item,

    cts:and-query((

    cts:element-attribute-word-query(
    xs:QName("a"), xs:QName("class"),
    "FEATURED", "case-insensitive"),

    cts:or-query((

    cts:element-attribute-word-query(
    xs:QName("a"), xs:QName("rel"),
    "VIDEO", "case-insensitive"),
    cts:element-attribute-word-query(
    xs:QName("a"), xs:QName("rel"),
    "PDF", "case-insensitive")
    ))
    )))
    return
  • {$item}

  • }



No comments: