Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate eXist facet definitions for xconf index configuration files programmatically
xquery version "3.1";
(: WIP! :)
declare boundary-space preserve;
let $xconfs :=
array {
map {
"qname": "tei:div",
"publication": "timeline",
"category": "department",
"url": "'/departmenthistory/timeline' || (if (@xml:id) then '/' || substring-after(./@xml:id, 'chapter_') else ())",
"path": "administrative-timeline/data/collection.xconf"
},
map {
"qname": "tei:div",
"publication": "frus",
"category": "documents",
"url": "'/historicaldocuments/' || ancestor::tei:TEI/@xml:id || '/' || ./@xml:id",
"path": "administrative-timeline/data/collection.xconf",
"has-fulltext": "@type = ('section', 'document')"
},
map {
"qname": "persName",
"publication": "pocom",
"category": "department",
"url": "'/departmenthistory/people/' || parent::person/id",
"path": "pocom/people/collection.xconf"
},
map {
"qname": "trip",
"publication": "travels",
"category": "department",
"url": "'/departmenthistory/travels/president/' || util:document-name(.) => substring-before('.xml')",
"path": "travels/president/collection.xconf"
},
map {
"qname": "trip",
"publication": "travels",
"category": "department",
"url": "'/departmenthistory/travels/secretary/' || util:document-name(.) => substring-before('.xml')",
"path": "travels/secretary/collection.xconf"
},
map {
"qname": "visits",
"publication": "visits",
"category": "department",
"url": "'/departmenthistory/visits/' || year-from-date(./start-date)",
"path": "visits/data/collection.xconf"
}
}
for $xconf in $xconfs?*
return
map {
"uri": $xconf?uri,
"xconf":
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<lucene>
<analyzer class="org.apache.lucene.analysis.standard.StandardAnalyzer">
<!-- Specify stop words - or remove them entirely -->
<param name="stopwords" type="org.apache.lucene.analysis.util.CharArraySet">
<!--<value>the</value>-->
</param>
</analyzer>
<analyzer class="org.apache.lucene.analysis.core.KeywordAnalyzer" id="keyword"/>
<text qname="{$xconf?uri}" index="yes">
<!-- start required facets and fields -->
<facet dimension="hsg-category" expression="'{$xconf?category}'"/>
<facet dimension="hsg-publication" expression="'{$xconf?publication}'"/>
<facet dimension="hsg-has-fulltext" expression="'true'"/>
<field name="hsg-fulltext"/>{if (map:contains($xconf, "fulltext")) then attribute expression {$xconf?fulltext} else ()}
<field name="hsg-url" expression="{$xconf?url}"/>
<!-- end required facets and fields -->
</text>
</lucene>
</index>
</collection>
}
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.