Skip to content

Instantly share code, notes, and snippets.

@wsalesky
wsalesky / collection.xconf
Created June 16, 2014 19:35
collection.xconf file for use with XQuery Institute Shakespeare data.
<?xml version="1.0" encoding="UTF-8"?>
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index xmlns:xqi="http://xqueryinstitute.org/ns" xmlns:tei="http://www.tei-c.org/ns/1.0">
<fulltext default="none" attributes="no"/>
<lucene>
<text qname="tei:title" boost="2.0"/>
<text qname="tei:stage"/>
<text qname="tei:sp"/>
<text qname="tei:body"/>
<text qname="tei:speaker"/>
@wsalesky
wsalesky / browse.xql
Created June 17, 2014 13:17
Simple browse for #xqy14
let $collection := 'PATH TO YOUR DATA'
for $play in collection($collection)
let $title := $play//tei:titleStmt/tei:title/text()
let $uri := base-uri($play)
return
<li>
<span class="title">{$title}.</span>
<span>{$uri}</span>
</li>
@wsalesky
wsalesky / search-function.xql
Created June 17, 2014 15:46
A simple function
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace ft="http://exist-db.org/xquery/lucene";
declare function local:search($terms as xs:string*) as node(){
if(starts-with($terms,'"')) then
<query>
<phrase>{$terms}</phrase>
</query>
@wsalesky
wsalesky / search.xql
Created June 17, 2014 15:50
Simple search for #xqy14
let $collection := 'PATH TO YOUR DATA'
for $hits in collection($collection)//tei:sp[ft:query(.,'pox')]
return $hits
@wsalesky
wsalesky / search-mod.xqm
Created June 17, 2014 21:01
Search module
xquery version "3.0";
module namespace search ="http://xqueryinstitute.org/search";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare function search:search($term as xs:string?) as element()* {
(for $hits in collection('/db/apps/xq-institute/data/plays')//tei:sp[ft:query(.,$term)]
return $hits)[position() = 1 to 10]
};
@wsalesky
wsalesky / search.html
Created June 18, 2014 18:01
Basic search function for xqy14
<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
<body>
Simple Search
<form action="search.xql" method="get">
<input type="text" id="q" name="q"></input>
</form>
</body>
</html>
@wsalesky
wsalesky / search.xql
Created June 18, 2014 18:03
Main search xquery. imports @andersoncliffb's render.xqm module
xquery version "3.0";
import module namespace search = "http://xqueryinstitute.org/search" at "search.xqm";
import module namespace render = "http://xqueryinstitute.org/render" at "render.xqm";
declare variable $q {request:get-parameter('q','')};
declare variable $rows {request:get-parameter('rows',5) cast as xs:integer};
<html xmlns="http://www.w3.org/1999/xhtml">
<head></head>
@wsalesky
wsalesky / search.xqm
Created June 18, 2014 18:04
Super simple search function
xquery version "3.0";
module namespace search ="http://xqueryinstitute.org/search";
declare namespace tei="http://www.tei-c.org/ns/1.0";
(:
: Limit results/pagination
: Total hit count
:
: :)
@wsalesky
wsalesky / facets-group-by.xql
Last active August 29, 2015 14:02
Facets POC using group by rather then index-keys(). No bells or whistles but you can get the general idea.
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace xqi="http://xqueryinstitute.org/ns";
(:~
: Adds facets for speakers
: @param $hits passed from search function
: :)
declare function local:facet-speaker($hits as element()*) as element()*{
for $speakers in $hits
@wsalesky
wsalesky / persName.xql
Last active August 29, 2015 14:03
Find malformed persName elements in srophe data.
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
<div>
{
for $person in collection("/db/apps/srophe/data/persons")//tei:persName[child::text()]
let $mistake := string-join($person/text(),' ')
let $uri := string($person/parent::tei:person/@xml:id)
let $source := $person/@source