Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Mobile Shakespeare Tutorial Part 3
<get path="play/:id/act/:act/scene/:scene/speech/:speech"><to>play#scene</to></get>
<get path="search"><to>search#get</to></get>
<post path="search"><to>search#get</to></post>
<div>... was <b>untimely</b> ripp'd. Accursed be ...</div>
<div><p>... was untimely ripp'd.</p><p>Accursed be ...</p>
<div>... was untimely
<annotation class="hidden tooltip">Awesome!</annotation>
ripp'd. Accursed b...</div>
<LINE>Tell thee, Macduff was from his mother's womb<LINE>
<LINE>Untimely ripp'd.</LINE>
<LINE>Accursed be the tongue ...
import module namespace search = "" at "/MarkLogic/appservices/search/search.xqy";
(: Search API options :)
declare variable $options :=
<options xmlns="">
<!-- Turning off the things we don't use -->
<sort-order direction="descending">
<term apply="term">
<!-- "" $term returns no results -->
<empty apply="no-results" />
<!-- Not sure why this isn't a default -->
<cts:and-query strength="20" xmlns:cts=""/>
<starter strength="30" apply="grouping" delimiter=")">(</starter>
<starter strength="40" apply="prefix" element="cts:not-query">-</starter>
<joiner strength="10" apply="infix" element="cts:or-query" tokenize="word">OR</joiner>
<joiner strength="20" apply="infix" element="cts:and-query" tokenize="word">AND</joiner>
<joiner strength="30" apply="infix" element="cts:near-query" tokenize="word">NEAR</joiner>
<joiner strength="30" apply="near2" consume="2" element="cts:near-query">NEAR/</joiner>
<joiner strength="50" apply="constraint">:</joiner>
<joiner strength="50" apply="constraint" compare="LT" tokenize="word">LT</joiner>
<joiner strength="50" apply="constraint" compare="LE" tokenize="word">LE</joiner>
<joiner strength="50" apply="constraint" compare="GT" tokenize="word">GT</joiner>
<joiner strength="50" apply="constraint" compare="GE" tokenize="word">GE</joiner>
<joiner strength="50" apply="constraint" compare="NE" tokenize="word">NE</joiner>
<!-- Custom rendering code for "Snippet" -->
<transform-results apply="snippet" ns="http://framework/lib/l-util" at="/lib/l-util.xqy" />
<!-- Search Form -->
<form action="/search" method="get" data-transition="fade" class="ui-body ui-body-b ui-corner-all">
<fieldset >
<label for="search-basic">Search all lines:</label>
<input type="search" name="term" id="term" value="{$term}" data-theme="b" />
<div data-role="fieldcontain">
<label for="slider2">Phrase search:</label>
<select name="phrase" id="phrase" data-role="slider" >
<option value="off">
<option value="on">
(: Dynamic inline attribute of the option element :)
if($phrase eq "on") then
attribute selected {"selected"}
<button type="submit" data-theme="b" data-transition="fade">Submit</button>
(: Search Results Area :)
Modify the typed search term.
Add Quotes if the $phrase flag is "on"
If the term is empty sequence, use ""
let $searchTerm :=
if(fn:exists($term)) then
if($phrase eq "on" and fn:not( fn:starts-with($term,'"') and fn:ends-with($term,'"'))) then
Think Functionally ...
XQuery invokes passes the evaluation of search:search
to transform-results
(: transform results into HTML5 :)
(: execute the search with the Search API :)
search:search($searchTerm, $options)//search:result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.