Skip to content

Instantly share code, notes, and snippets.

@dscape
Created April 26, 2010 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscape/379734 to your computer and use it in GitHub Desktop.
Save dscape/379734 to your computer and use it in GitHub Desktop.
We will begin with a review of ApplicationBuilder and the SearchAPI. We will look at what functionality is provided out of the box with these tools, and how you can extend them to suit the needs of your project. In the class we will load sample documents,

Extending Application Builder

Abstract

We will begin with a review of ApplicationBuilder and the SearchAPI. We will look at what functionality is provided out of the box with these tools, and how you can extend them to suit the needs of your project. In the class we will load sample documents, build an application, then add features to the application by extending the code that is generated by ApplicationBuilder. By the end of the afternoon session you will have used our best practices for extending the functionality of this powerful tool.

Application Builder

Materials

Links

By Nuno Job - MarkLogic

Website | Twitter

xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin"
at "/MarkLogic/admin.xqy";
let $config := admin:get-configuration()
let $config := admin:forest-create( $config, "sandbox-forest",
xdmp:host(), () )
return admin:save-configuration( $config )
;
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin"
at "/MarkLogic/admin.xqy";
let $config := admin:get-configuration()
let $config := admin:database-create( $config , "sandbox",
xdmp:database( "Security" ), xdmp:database( "Schemas" ) )
return admin:save-configuration( $config )
;
(: Attach partition to the database :)
xquery version "1.0-ml";
import module namespace admin = "http://marklogic.com/xdmp/admin"
at "/MarkLogic/admin.xqy";
let $config := admin:get-configuration()
let $config := admin:database-attach-forest( $config,
xdmp:database( "sandbox" ),
xdmp:forest( "sandbox-forest" ) )
return admin:save-configuration( $config ),
<p>Database is now ready to be used. Please select '<strong>sandbox</strong>' it in cq</p>
<?xml version="1.0" encoding="UTF-8"?>
<user>
<id>9647442</id>
<name>peteaven</name>
<screen_name>peteaven</screen_name>
<location>Half Moon Bay, CA</location>
<description>integration engineer guy, sci-fi geek, headbanger, skier,
mountain biker, voracious reader,
mental database of pop culture references, new dad</description>
<profile_image_url>
http://a1.twimg.com/profile_images/119691446/HEAD_normal.jpg
</profile_image_url>
<url>http://robotbeerbash.wordpress.com/</url>
<protected>false</protected>
<followers_count>406</followers_count>
<profile_background_color>1c80ba</profile_background_color>
<profile_text_color>000000</profile_text_color>
<profile_link_color>0a3780</profile_link_color>
<profile_sidebar_fill_color>7c797c</profile_sidebar_fill_color>
<profile_sidebar_border_color>BDDCAD</profile_sidebar_border_color>
<friends_count>565</friends_count>
<created_at>Wed Oct 24 06:38:54 +0000 2007</created_at>
<favourites_count>1027</favourites_count>
<utc_offset>-28800</utc_offset>
<time_zone>Pacific Time (US &amp; Canada)</time_zone>
<profile_background_image_url>
http://s.twimg.com/a/1271960514/images/themes/theme1/bg.png
</profile_background_image_url>
<profile_background_tile>false</profile_background_tile>
<notifications>false</notifications>
<geo_enabled>false</geo_enabled>
<verified>false</verified>
<following>false</following>
<statuses_count>3183</statuses_count>
<lang>en</lang>
<contributors_enabled>false</contributors_enabled>
<status>
<created_at>Tue Apr 27 14:23:14 +0000 2010</created_at>
<id>12947601903</id>
<text>Un nouveau Tweet pour le MUG.fr : MarkLogic User Group France
(@mugfr ) : #MUG.FR - RT @ Mat_Balza #awesome</text>
<source>web</source>
<truncated>false</truncated>
<in_reply_to_status_id/>
<in_reply_to_user_id/>
<favorited>false</favorited>
<in_reply_to_screen_name/>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
</user>
let $user := xdmp:http-get( "http://api.twitter.com/1/users/show.xml?screen_name=peteaven" ) /user
let $statuses-count := $user /statuses_count
let $pages := xs:integer ( fn:round( $statuses-count div 20 ) )
for $page in ( 1 to $pages )
return xdmp:spawn("/load-timeline.xqy",
( xs:QName("page"), $page, xs:QName("screen-name"), 'peteaven' ),
<options xmlns="xdmp:eval">
<modules> { xdmp:modules-database() } </modules>
</options> )
xquery version "1.0-ml";
import module namespace mem = "http://xqdev.com/in-mem-update"
at "/MarkLogic/appservices/utils/in-mem-update.xqy" ;
declare namespace twitter = "http://marklogic.com/2010/twitter";
declare variable $screen-name as xs:string external;
declare variable $page as xs:integer external;
declare function twitter:get-user-timeline-page($screen-name, $page) {
xdmp:http-get( fn:concat(
"http://api.twitter.com/1/statuses/user_timeline.xml",
"?screen_name=", $screen-name ,"&amp;page=", $page) ) } ;
declare function twitter:uri-for-status($screen-name, $id) {
fn:concat( "/twitter/", $screen-name, "/statuses/", $id, ".xml" ) } ;
let $_ := xdmp:log ( fn:concat ( "#twitter turns the page to ", $page ) )
for $status in twitter:get-user-timeline-page( $screen-name, $page ) //status
let $uri := twitter:uri-for-status( $screen-name, $status/id )
return if ($status)
then ( xdmp:document-insert( $uri, $status ),
xdmp:log( fn:concat("#twitter status created at ", $uri ) ) )
else xdmp:log(fn:concat("#twitter #error on ", $uri))
<?xml version="1.0" encoding="UTF-8"?>
<status>
<created_at>2010-04-28T23:36:13Z</created_at>
<id>13035135883</id>
<text type="RT">top 40 SharePoint jokes
<link>
http://www.paulswider.com/the-fantastic-40-sharepoint-jokes.html
</link> - RT <reply>JerrySilver</reply>
<hashtag>funnycauseitstrue</hashtag>
</text>
<source>Seesmic</source>
<truncated>false</truncated>
<in_reply_to_status_id/>
<in_reply_to_user_id/>
<favorited>false</favorited>
<in_reply_to_screen_name/>
<user>
<!-- User info removed -->
</user>
<geo/>
<coordinates/>
<place/>
<contributors/>
</status>
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="date">
<range type="xs:dateTime">
<computed-bucket lt="P10Y" ge="-P10Y" anchor="start-of-year" name="all">All</computed-bucket>
<computed-bucket lt="P1Y" ge="P0Y" anchor="start-of-year" name="thisyear">This Year</computed-bucket>
<computed-bucket lt="P1M" ge="P0M" anchor="start-of-month" name="thismonth">This Month</computed-bucket>
<computed-bucket lt="P15D" ge="-P1D" anchor="start-of-day" name="twoweeks">Last 2 Weeks</computed-bucket>
<computed-bucket lt="P0D" ge="-P1D" anchor="start-of-day" name="yesterday">Yesterday</computed-bucket>
<computed-bucket lt="P1D" ge="P0D" anchor="start-of-day" name="today">Today</computed-bucket>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
<element ns="" name="created_at"/>
</range>
<annotation><proj:front-page xmlns:proj="http://marklogic.com/appservices/project">true</proj:front-page><proj:side-bar xmlns:proj="http://marklogic.com/appservices/project">true</proj:side-bar></annotation>
</constraint>
<constraint name="hashtag">
<range collation="http://marklogic.com/collation/en/S1/AS/T00BB" type="xs:string">
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
<element ns="" name="hashtag"/>
</range>
<annotation><proj:front-page xmlns:proj="http://marklogic.com/appservices/project">true</proj:front-page><proj:side-bar xmlns:proj="http://marklogic.com/appservices/project">true</proj:side-bar></annotation>
</constraint>
<constraint name="link">
<range collation="http://marklogic.com/collation/en/S1" type="xs:string">
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
<element ns="" name="link"/>
</range>
<annotation><proj:front-page xmlns:proj="http://marklogic.com/appservices/project">false</proj:front-page><proj:side-bar xmlns:proj="http://marklogic.com/appservices/project">true</proj:side-bar></annotation>
</constraint>
<constraint name="reply">
<range collation="http://marklogic.com/collation/en/S1/AS/T00BB" type="xs:string">
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
<element ns="" name="reply"/>
</range>
<annotation><proj:front-page xmlns:proj="http://marklogic.com/appservices/project">true</proj:front-page><proj:side-bar xmlns:proj="http://marklogic.com/appservices/project">true</proj:side-bar></annotation>
</constraint>
<constraint name="source">
<range collation="http://marklogic.com/collation/en/S1" type="xs:string">
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
<element ns="" name="source"/>
</range>
<annotation><proj:front-page xmlns:proj="http://marklogic.com/appservices/project">false</proj:front-page><proj:side-bar xmlns:proj="http://marklogic.com/appservices/project">true</proj:side-bar></annotation>
</constraint>
<constraint name="type">
<range collation="http://marklogic.com/collation/" type="xs:string">
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
<attribute ns="" name="type"/>
<element ns="" name="text"/>
</range>
<annotation><proj:front-page xmlns:proj="http://marklogic.com/appservices/project">false</proj:front-page><proj:side-bar xmlns:proj="http://marklogic.com/appservices/project">true</proj:side-bar></annotation>
</constraint>
<return-results>false</return-results>
</options>
declare variable $js := xdmp:function( fn:QName(
"http://marklogic.com/appservices/component", "myjs"));
declare function asc:myjs() as element()* {
(asc:js(),
<script src="/js/jquery-1.4.2.min.js" type="text/javascript"><!-- --></script>,
<script src="/js/jquery.flip.min.js" type="text/javascript"><!-- --></script>)
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment