View get-latest-created-document.xq
xquery version "3.1";
(: See discussion at http://markmail.org/message/hpu7toznx3fvdiei :)
import module namespace util="http://exist-db.org/xquery/util";
import module namespace xmldb="http://exist-db.org/xquery/xmldb";
declare function local:get-latest-created-document($collection-uri as xs:string) as map(*) {
if (xmldb:collection-available($collection-uri)) then
let $documents := xmldb:xcollection($collection-uri) ! util:document-name(.)
View frus-volume-titles.xq
xquery version "3.1";
element volumes {
let $vols := collection("/db/apps/frus/bibliography")/volume[publication-status eq "published"]
for $vol in $vols
let $vol-id := $vol/@id
let $title :=
(
$vol/title[@type eq "sub-series"],
$vol/title[@type eq "volume-number"],
View README.md

Full text search of Chinese text, with eXist-db and lucene

This gist contains some sample files showing how to configure full text queries on Chinese text with eXist.

It assumes you have already installed eXist 3.5.0+.

Set up

The default eXist installation does not ship with the "SmartCN" analyzer for Lucene, so you need to install it. To do so, download the full distribution of Lucene, being sure to download the same version of Lucene as is bundled with eXist. For eXist 3.5.0, the version of Lucene is 4.10.4, so download lucene-4.10.4.tgz or lucene-4.10.4.zip from http://archive.apache.org/dist/lucene/java/4.10.4/. Expand the archive, and find lucene-analyzers-smartcn-4.10.4.jar in the analysis/smartcn folder. Place this jar file into EXIST_HOME/extensions/indexes/lucene/lib. With this jar file in place, start eXist.

View date-processing.xqm
xquery version "3.1";
module namespace dp = "http://history.state.gov/ns/xquery/date-processing";
declare variable $dp:month-regex := "(January|February|March|April|May|June|July|August|September|October|November|December)";
declare variable $dp:day-regex := "(\d{1,2})(?:st|d|nd|rd|th)?";
declare variable $dp:regexes :=
map {
View list-abbreviations.xq
xquery version "3.1";
(: Force oXygen to indent the output :)
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare option output:method "xml";
declare option output:indent "yes";
(: Assumed context: you're running this in oXygen's XPath/XQuery Builder pane
: with an XML document open in the main editor :)
View try-catch-boilerplate.xq
xquery version "3.1";
try {
fn:error()
} catch * {
map {
"code": $err:code,
"description": $err:description,
"value": $err:value,
"module": $err:module,
View populate-github-issue.xq
xquery version "3.1";
(: Note: the environment-variable functions only work if the user running the query has DBA access :)
(: Probe available environment variables with the following query :)
(:
map:merge(
available-environment-variables() ! map:entry(., environment-variable(.))
),
:)
View install-exist-on-macos-with-homebrew.md

Install eXist via Homebrew on macOS

First time

  • Install Homebrew via instructions at http://brew.sh
  • Delete previous installation of eXist at /Applications/eXist-db.app (if present), because Homebrew will refuse to install over a non-Homebrew installation.
  • Install eXist via:
$ brew cask install exist-db
View map-find.xqm
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's map:find function for eXist, which does not support it natively as of 3.4.0.
:
: @author Joe Wicentowski
: @see https://www.w3.org/TR/xpath-functions-31/#func-map-find
:)
module namespace mf="http://joewiz.org/ns/xquery/map-find";
View unparsed-text.xqm
xquery version "3.1";
(:~
: An implementation of XQuery 3.1's fn:unparsed-text* functions for eXist, which does not support them natively as of 3.4.0.
: Known limitations:
: - Does not enforce encoding aspects of the XQuery spec beyond functionality natively supplied by the EXPath HTTP Client and eXist's internals.
:
: @author Joe Wicentowski
: @version 0.2
: @see https://www.w3.org/TR/xpath-functions-31/#func-unparsed-text