Skip to content
GitLab
Explore
Sign in
Register
You need to sign in or sign up before continuing.
Commits on Source (2)
Update to latest tei publisher
· 6ef9bd45
Wolfgang
authored
Jun 22, 2019
6ef9bd45
Fix search autocomplete
· c2b2f2e6
Wolfgang
authored
Jun 23, 2019
c2b2f2e6
Show whitespace changes
Inline
Side-by-side
collection.xconf
View file @
c2b2f2e6
...
...
@@ -14,6 +14,7 @@
<field name="to" expression="nav:get-metadata(ancestor::tei:TEI, 'to')"/>
<field name="place" expression="nav:get-metadata(ancestor::tei:TEI, 'place')"/>
<field name="date" expression="nav:get-metadata(ancestor::tei:TEI, 'date')" type="xs:date"/>
<field name="file" expression="util:document-name(.)"/>
<ignore qname="tei:body"/>
</text>
<text qname="tei:head"/>
...
...
modules/config.xqm
View file @
c2b2f2e6
...
...
@@ -187,6 +187,13 @@ declare variable $config:tex-command := function($file) {
(
"/usr/local/bin/pdflatex"
,
"-interaction=nonstopmode"
,
$file
)
};
(:
: Temporary directory to write .tex output to. The LaTeX process will receive this
: as working director.
:)
declare
variable
$config:tex-temp-dir
:=
util:system-property
(
"java.io.tmpdir"
);
(:~
: Configuration for epub files.
:)
...
...
@@ -239,7 +246,15 @@ declare variable $config:app-root :=
declare
variable
$config:data-root
:=
$config:app-root
||
"/data"
;
declare
variable
$config:data-exclude
:=
();
(:~
: The root of the collection hierarchy whose files should be displayed
: on the entry page. Can be different from $config:data-root.
:)
declare
variable
$config:data-default
:=
$config:data-root
;
declare
variable
$config:data-exclude
:=
doc
(
$config:data-root
||
"/taxonomy.xml"
)
/
tei:TEI
;
declare
variable
$config:default-odd
:=
"vangogh.odd"
;
...
...
@@ -257,6 +272,8 @@ declare variable $config:repo-descriptor := doc(concat($config:app-root, "/repo.
declare
variable
$config:expath-descriptor
:=
doc
(
concat
(
$config:app-root
,
"/expath-pkg.xml"
))
/
expath:package
;
declare
variable
$config:session-prefix
:=
$config:expath-descriptor
/
@abbrev
/
string
();
(:~
: Return an ID which may be used to look up a document. Change this if the xml:id
: which uniquely identifies a document is *not* attached to the root element.
...
...
modules/db-query.xql
View file @
c2b2f2e6
...
...
@@ -24,11 +24,10 @@ declare namespace db="http://docbook.org/ns/docbook";
import module namespace config="http://www.tei-c.org/tei-simple/config" at "config.xqm";
import module namespace nav="http://www.tei-c.org/tei-simple/navigation/docbook" at "navigation-dbk.xql";
declare variable $dbs:QUERY_OPTIONS :=
<options>
<leading-wildcard>yes</leading-wildcard>
<filter-rewrite>yes</filter-rewrite>
</options>;
declare variable $dbs:QUERY_OPTIONS := map {
"leading-wildcard": "yes",
"filter-rewrite": "yes"
};
declare function dbs:query-default($fields as xs:string+, $query as xs:string, $target-texts as xs:string*) {
if(string($query)) then
...
...
@@ -39,29 +38,52 @@ declare function dbs:query-default($fields as xs:string+, $query as xs:string, $
if ($target-texts) then
for $text in $target-texts
return
$config:data-root ! doc(. || "/" || $text)//db:title[ft:query(., $query,
$
dbs:
QUERY_OPTIONS
)]
$config:data-root ! doc(. || "/" || $text)//db:title[ft:query(., $query, dbs:
options()
)]
else
collection($config:data-root)//db:title[ft:query(., $query, $dbs:QUERY_OPTIONS)]
default return
if ($target-texts) then
for $text in $target-texts
return
$config:data-root ! doc(. || "/" || $text)//db:section[ft:query(., $query,
$
dbs:
QUERY_OPTIONS
)] |
$config:data-root ! doc(. || "/" || $text)//db:article[ft:query(., $query,
$
dbs:
QUERY_OPTIONS
)]
$config:data-root ! doc(. || "/" || $text)//db:section[ft:query(., $query, dbs:
options()
)] |
$config:data-root ! doc(. || "/" || $text)//db:article[ft:query(., $query, dbs:
options()
)]
else
collection($config:data-root)//db:section[ft:query(., $query,
$
dbs:
QUERY_OPTIONS
)] |
collection($config:data-root)//db:article[ft:query(., $query,
$
dbs:
QUERY_OPTIONS
)]
collection($config:data-root)//db:section[ft:query(., $query, dbs:
options()
)] |
collection($config:data-root)//db:article[ft:query(., $query, dbs:
options()
)]
else ()
};
declare function dbs:options() {
map:merge((
$dbs:QUERY_OPTIONS,
map {
"facets":
map:merge((
for $param in request:get-parameter-names()[starts-with(., 'facet-')]
let $dimension := substring-after($param, 'facet-')
return
map {
$dimension: request:get-parameter($param, ())
}
))
}
))
};
declare function dbs:autocomplete($doc as xs:string?, $fields as xs:string+, $q as xs:string) {
for $field in $fields
return
switch ($field)
case "author" return
distinct-values(ft:search($config:data-root, "author:" || $q || "*", "author")//field)
collection($config:data-root)/ft:index-keys-for-field("author", $q,
function($key, $count) {
$key
}, 30)
case "file" return
distinct-values(ft:search($config:data-root, "file:" || $q || "*", "file")//field)
collection($config:data-root)/ft:index-keys-for-field("file", $q,
function($key, $count) {
$key
}, 30)
case "text" return
if ($doc) then (
doc($config:data-root || "/" || $doc)/util:index-keys-by-qname(xs:QName("db:section"), $q,
...
...
@@ -94,15 +116,15 @@ declare function dbs:autocomplete($doc as xs:string?, $fields as xs:string+, $q
$key
}, 30, "lucene-index")
default return
collection($config:data-root)/
util
:index-keys-
by-qname(xs:QName("db:
title"
)
, $q,
collection($config:data-root)/
ft
:index-keys-
for-field("
title", $q,
function($key, $count) {
$key
},
-1, "lucene-index"
)
},
30
)
};
declare function dbs:query-metadata($field as xs:string, $query as xs:string, $sort as xs:string) {
for $doc in collection($config:data-root)//db:section[ft:query(., $field || ":" || $query, map { "fields": $sort
})]
return
for $doc in collection($config:data-root)//db:section[ft:query(., $field || ":" || $query, map { "fields": $sort
})]
return
root($doc)/*
};
...
...
@@ -132,8 +154,8 @@ declare function dbs:get-breadcrumbs($config as map(*), $hit as element(), $pare
: on it.
:)
declare function dbs:expand($data as element()) {
let $query := session:get-attribute(
"apps.simple
.query")
let $field := session:get-attribute(
"apps.simple
.field")
let $query := session:get-attribute(
$config:session-prefix || "
.query")
let $field := session:get-attribute(
$config:session-prefix || "
.field")
let $div := $data
let $expanded :=
util:expand(dbs:query-default-view($div, $query, $field), "add-exist-id=all")
...
...
modules/facets.xql
View file @
c2b2f2e6
...
...
@@ -17,20 +17,20 @@ declare function local:sort($facets as map(*)?) {
}
};
declare function local:print-table($config as map(*), $node as element(), $values as xs:string*, $params as xs:string*) {
declare function local:print-table($config as map(*), $node
s
as element()
+
, $values as xs:string*, $params as xs:string*) {
let $all := exists($config?max) and request:get-parameter("all-" || $config?dimension, ())
let $count := if ($all) then
()
else $config?max
let $count := if ($all) then
50
else $config?max
let $facets :=
if (exists($values)) then
ft:facets($node, $config?dimension, $count, $values)
ft:facets($node
s
, $config?dimension, $count, $values)
else
ft:facets($node, $config?dimension, $count)
ft:facets($node
s
, $config?dimension, $count)
return
if (map:size($facets) > 0) then
<table>
{
array:for-each(local:sort($facets), function($entry) {
map:for-each($entry, function($label, $
count
) {
map:for-each($entry, function($label, $
freq
) {
<tr>
<td>
<paper-checkbox class="facet" name="facet-{$config?dimension}" value="{$label}">
...
...
@@ -44,14 +44,14 @@ declare function local:print-table($config as map(*), $node as element(), $value
}
</paper-checkbox>
</td>
<td>{$
count
}</td>
<td>{$
freq
}</td>
</tr>
})
}),
if (empty($params)) then
()
else
let $nested := local:print-table($config, $node, ($values, head($params)), tail($params))
let $nested := local:print-table($config, $node
s
, ($values, head($params)), tail($params))
return
if ($nested) then
<tr class="nested">
...
...
@@ -67,34 +67,38 @@ declare function local:print-table($config as map(*), $node as element(), $value
()
};
declare function local:display($config as map(*), $node as element()) {
declare function local:display($config as map(*), $nodes as element()+) {
let $params := request:get-parameter("facet-" || $config?dimension, ())
let $table := local:print-table($config, $nodes, (), $params)
where $table
return
<div>
<h3>{$config?heading}
{
if (exists($config?max)) then
<paper-checkbox class="facet" name="all-{$config?dimension}">
{ if (request:get-parameter("all-" || $config?dimension, ())) then attribute checked { "checked" } else () }
Show
all
</paper-checkbox>
Show
top
50
</paper-checkbox>
else
()
}
</h3>
{
let $params := request:get-parameter("facet-" || $config?dimension, ())
return
local:print-table($config, $node, (), $params)
</h3> {
$table
}
</div>
};
let $hits := session:get-attribute(
"apps.simple
")
let $hits := session:get-attribute(
$config:session-prefix || ".hits
")
where count($hits) > 0
return
<div>
{
for $config in $config:facets?*
return
local:display($config, $hits
[1]
)
local:display($config, $hits)
}
</div>
modules/lib/browse.xql
View file @
c2b2f2e6
...
...
@@ -15,7 +15,7 @@
: You should have received a copy of the GNU General Public License
: along with this program. If not, see <http://www.gnu.org/licenses/>.
:)
xquery version "3.
0
";
xquery version "3.
1
";
module namespace app="http://www.tei-c.org/tei-simple/templates";
...
...
@@ -55,28 +55,13 @@ declare
%templates:wrap
function app:sort($items as element()*, $sortBy as xs:string?) {
let $items :=
if (
count
($config:data-exclude)
= 1
) then
$items
[not(matches(util:collection-name(.),
$config:data-exclude
))]
if (
exists
($config:data-exclude)) then
$items
except
$config:data-exclude
else
$items
return
if ($sortBy) then
for $item in $items
let $field :=
if ($sortBy = "date") then
ft:field($item, "date", "xs:date")
else
ft:field($item, $sortBy)
let $content :=
if (exists($field)) then
$field
else
let $data := nav:get-metadata(map { "type": nav:document-type($item) }, $item, $sortBy)
return
replace(string-join($data, " "), "^\s*(.*)$", "$1", "m")
order by $content
return
$item
nav:sort($sortBy, $items)
else
$items
};
...
...
@@ -90,26 +75,27 @@ declare
%templates:default("sort", "title")
function app:list-works($node as node(), $model as map(*), $filter as xs:string?, $root as xs:string,
$browse as xs:string?, $odd as xs:string?, $sort as xs:string) {
let $odd := ($odd, session:get-attribute("teipublisher.odd"))[1]
let $params := app:params2map()
let $odd := ($odd, session:get-attribute($config:session-prefix || ".odd"))[1]
let $oddAvailable := $odd and doc-available($config:odd-root || "/" || $odd)
let $odd := if ($oddAvailable) then $odd else $config:default-odd
let $cached := session:get-attribute(
"teipublisher
.works")
let $cached := session:get-attribute(
$config:session-prefix || "
.works")
let $filtered :=
if (exists($filter)) then
query:query-metadata($browse, $filter, $sort)
else if (exists($cached) and $filter = session:get-attribute("teipublisher.filter")) then
if (app:use-cache($params, $cached)) then
$cached
else if (exists($filter)) then
query:query-metadata($browse, $filter, $sort)
else
let $options := app:options($sort)
return
$config:data-root ! collection(. || "/" || $root)//tei:body[ft:query(., (), $options)]/ancestor::tei:TEI
nav:get-root($root, $options)
let $sorted := app:sort($filtered, $sort)
return (
session:set-attribute(
'apps.simple', $filtered
),
session:set-attribute(
"teipublisher.works", $sort
ed),
session:set-attribute(
"teipublisher.browse", $browse
),
session:set-attribute(
"teipublisher.filter
", $
fil
te
r
),
session:set-attribute(
"teipublisher
.odd", $odd),
session:set-attribute(
$config:session-prefix || ".timestamp", current-dateTime()
),
session:set-attribute(
$config:session-prefix || '.hits', $filter
ed),
session:set-attribute(
$config:session-prefix || '.params', $params
),
session:set-attribute(
$config:session-prefix || ".works
", $
sor
te
d
),
session:set-attribute(
$config:session-prefix || "
.odd", $odd),
map {
"all" : $sorted,
"mode": "browse"
...
...
@@ -117,6 +103,25 @@ function app:list-works($node as node(), $model as map(*), $filter as xs:string?
)
};
declare %private function app:params2map() {
map:merge(
for $param in request:get-parameter-names()[not(. = ("start", "per-page"))]
return
map:entry($param, request:get-parameter($param, ()))
)
};
declare function app:use-cache($params as map(*), $cached) {
let $cachedParams := session:get-attribute($config:session-prefix || ".params")
let $timestamp := session:get-attribute($config:session-prefix || ".timestamp")
return
if (exists($cached) and exists($cachedParams) and deep-equal($params, $cachedParams) and exists($timestamp)) then
empty(xmldb:find-last-modified-since(collection($config:data-root), $timestamp))
else
false()
};
declare function app:options($sortBy as xs:string) {
map {
"facets":
...
...
@@ -128,7 +133,9 @@ declare function app:options($sortBy as xs:string) {
$dimension: request:get-parameter($param, ())
}
)),
"fields": $sortBy
"fields": $sortBy,
"leading-wildcard": "yes",
"filter-rewrite": "yes"
}
};
...
...
modules/lib/components-list-odds.xql
View file @
c2b2f2e6
...
...
@@ -26,7 +26,7 @@ import module namespace dbutil = "http://exist-db.org/xquery/dbutil";
declare option output:method "json";
declare option output:media-type "application/json";
let $odd := (request:get-parameter("odd", ()), session:get-attribute(
"teipublisher
.odd"), $config:odd)[1]
let $odd := (request:get-parameter("odd", ()), session:get-attribute(
$config:session-prefix || "
.odd"), $config:odd)[1]
let $allOdds :=
dbutil:scan-resources(xs:anyURI($config:odd-root), function ($resource) {
if (ends-with($resource, ".odd")) then
...
...
modules/lib/components-odd.xql
View file @
c2b2f2e6
...
...
@@ -108,7 +108,7 @@ let $delete := request:get-parameter("delete", ())
let $new_odd := request:get-parameter("new_odd", ())
let $byExample := request:get-parameter("byExample", ())
let $title := request:get-parameter("title", ())
let $odd := (request:get-parameter("odd", ()), session:get-attribute(
"teipublisher
.odd"), $config:odd)[1]
let $odd := (request:get-parameter("odd", ()), session:get-attribute(
$config:session-prefix || "
.odd"), $config:odd)[1]
let $user := request:get-attribute($config:login-domain || ".user")
return (
if ($delete) then
...
...
modules/lib/components.xql
View file @
c2b2f2e6
...
...
@@ -102,7 +102,7 @@ return
else
$xml?data
let $data :=
if (empty($xpath) and $highlight and exists(session:get-attribute(
"apps.simple
.query"))) then
if (empty($xpath) and $highlight and exists(session:get-attribute(
$config:session-prefix || "
.query"))) then
query:expand($xml?config, $mapped)[1]
else
$mapped
...
...
modules/lib/i18n.xql
View file @
c2b2f2e6
...
...
@@ -53,7 +53,7 @@ declare function i18n:process($nodes as node()*, $selectedLang as xs:string?, $p
: @param $model a sequence of items which will be passed to all called template functions. Use this to pass
: information between templating instructions.
:)
declare function i18n:process($node as node(), $selectedCatalogue as node()) {
declare function i18n:process($node as node(), $selectedCatalogue as node()
+
) {
typeswitch ($node)
case document-node() return
for $child in $node/node() return i18n:process($child, $selectedCatalogue)
...
...
@@ -76,12 +76,12 @@ declare function i18n:process($node as node(), $selectedCatalogue as node()) {
$node
};
declare function i18n:translateAttributes($node as node(), $selectedCatalogue as node()){
declare function i18n:translateAttributes($node as node(), $selectedCatalogue as node()
+
){
for $attribute in $node/@*
return i18n:translateAttribute($attribute, $node, $selectedCatalogue)
};
declare function i18n:translateAttribute($attribute as attribute(), $node as node(),$selectedCatalogue as node()){
declare function i18n:translateAttribute($attribute as attribute(), $node as node(),$selectedCatalogue as node()
+
){
if(starts-with($attribute, 'i18n(')) then
let $key :=
if(contains($attribute, ",")) then
...
...
@@ -109,7 +109,7 @@ declare %private function i18n:get-display-value-for-key($key, $catalog-working)
: Get the localized value for a given key from the given catalgue
: if no localized value is available, the default value is used
:)
declare function i18n:getLocalizedText($textNode as node(), $selectedCatalogue as node()){
declare function i18n:getLocalizedText($textNode as node(), $selectedCatalogue as node()
+
){
if(exists($selectedCatalogue//msg[@key eq $textNode/@key])) then (
i18n:get-display-value-for-key($textNode/@key, $selectedCatalogue)
)
...
...
@@ -124,7 +124,7 @@ declare function i18n:getLocalizedText($textNode as node(), $selectedCatalogue a
: @param $node i18n:translate node eclosing i18n:text and parameters to substitute
: @param $text the processed(!) content of i18n:text
:)
declare function i18n:translate($node as node(),$text as xs:string,$selectedCatalogue as node()) {
declare function i18n:translate($node as node(),$text as xs:string,$selectedCatalogue as node()
+
) {
if(contains($text,'{')) then
(: text contains parameters to substitute :)
let $params := $node//i18n:param
...
...
@@ -156,7 +156,7 @@ declare function i18n:translate($node as node(),$text as xs:string,$selectedCata
: @param $paramKey currently processed parameterKey (numerical or alphabetical)
: @param $text the processed(!) content of i18n:text
:)
declare function i18n:replaceParam($node as node(), $param as node(),$paramKey as xs:string, $text as xs:string,$selectedCatalogue as node()) {
declare function i18n:replaceParam($node as node(), $param as node(),$paramKey as xs:string, $text as xs:string,$selectedCatalogue as node()
+
) {
if(exists($param/i18n:text)) then
(: the parameter has to be translated as well :)
let $translatedParam := i18n:getLocalizedText($param/i18n:text, $selectedCatalogue)
...
...
modules/lib/latex.xql
View file @
c2b2f2e6
...
...
@@ -18,8 +18,6 @@ declare option output:method "text";
declare option output:html-version "5.0";
declare option output:media-type "text/text";
declare variable $local:WORKING_DIR := system:get-exist-home() || "/webapp";
let $id := request:get-parameter("id", ())
let $token := request:get-parameter("token", ())
let $source := request:get-parameter("source", ())
...
...
@@ -45,10 +43,10 @@ return (
if ($source) then
$tex
else
let $serialized := file:serialize-binary(util:string-to-binary($tex), $
local:WORKING_DIR
|| "/" || $file || ".tex")
let $serialized := file:serialize-binary(util:string-to-binary($tex), $
config:tex-temp-dir
|| "/" || $file || ".tex")
let $options :=
<option>
<workingDir>{$
local:WORKING_DIR
}</workingDir>
<workingDir>{$
config:tex-temp-dir
}</workingDir>
</option>
let $output :=
for $i in 1 to 3
...
...
@@ -58,7 +56,7 @@ return (
)
return
if ($output[last()]/@exitCode < 2) then
let $pdf := file:read-binary($
local:WORKING_DIR
|| "/" || $file || ".pdf")
let $pdf := file:read-binary($
config:tex-temp-dir
|| "/" || $file || ".pdf")
return
response:stream-binary($pdf, "media-type=application/pdf", $file || ".pdf")
else
...
...
modules/lib/pages.xql
View file @
c2b2f2e6
...
...
@@ -258,7 +258,7 @@ declare
function pages:view($node as node(), $model as map(*), $action as xs:string) {
let $view := pages:determine-view($model?config?view, $model?data)
let $data :=
if ($action = "search" and exists(session:get-attribute(
"apps.simple
.query"))) then
if ($action = "search" and exists(session:get-attribute(
$config:session-prefix || "
.query"))) then
query:expand($model?config, $model?data)
else
$model?data
...
...
@@ -408,32 +408,6 @@ declare function pages:get-content($config as map(*), $div as element()) {
nav:get-content($config, $div)
};
declare function pages:breadcrumbs($node as node(), $model as map(*)) {
let $parent := ($model?data/self::tei:body, $model?data/ancestor-or-self::tei:div[1])[1]
let $parent-id := config:get-identifier($parent)
let $current-view:=
if($model?config?view != $config:default-view) then "&view=" || $model?config?view else ()
let $current-odd:=
if($model?config?odd != $config:odd) then "&odd=" || $model?config?odd else ()
return
<ol class="headings breadcrumb">
<li><a href="{$parent-id}">{nav:get-document-title($model?config, $model('data')/ancestor-or-self::tei:TEI)}</a></li>
{
for $parentDiv in $model?data/ancestor-or-self::tei:div[tei:head]
let $id := util:node-id(
if ($model?config?view = "page") then $parentDiv/preceding::tei:pb[1] else $parentDiv
)
return
<li>
<a href="{$parent-id}?root={$id}{$current-view}{$current-odd}">{$parentDiv/tei:head/string()}</a>
</li>
}
</ol>
};
declare
%templates:wrap
function pages:navigation-title($node as node(), $model as map(*)) {
...
...
@@ -554,7 +528,7 @@ declare function pages:parse-params($node as node(), $model as map(*)) {
let $found := [
request:get-parameter($paramName, $default),
$model($paramName),
session:get-attribute(
"apps.simple
." || $paramName)
session:get-attribute(
$config:session-prefix || "
." || $paramName)
]
return
array:fold-right($found, (), function($in, $value) {
...
...
modules/lib/regenerate.xql
View file @
c2b2f2e6
...
...
@@ -4,6 +4,7 @@ import module namespace config="http://www.tei-c.org/tei-simple/config" at "../c
import module namespace pmu="http://www.tei-c.org/tei-simple/xquery/util";
import module namespace odd="http://www.tei-c.org/tei-simple/odd2odd";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "util.xql";
declare namespace expath="http://expath.org/ns/pkg";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
...
...
@@ -47,7 +48,13 @@ let $odd :=
xmldb:get-child-resources($config:odd-root)[ends-with(., ".odd")]
let $result :=
for $source in $odd
for $module in ("web", "print", "latex", "epub")
let $odd := doc($config:odd-root || "/" || $source)
let $pi := tpu:parse-pi($odd, ())
for $module in
if ($pi?output) then
tokenize($pi?output)
else
("web", "print", "latex", "epub")
return
try {
for $file in pmu:process-odd(
...
...
modules/lib/search.xql
View file @
c2b2f2e6
...
...
@@ -23,14 +23,11 @@ xquery version "3.1";
module namespace search="http://www.tei-c.org/tei-simple/search";
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace templates="http://exist-db.org/xquery/templates";
import module namespace templates="http://exist-db.org/xquery/templates";
import module namespace query="http://www.tei-c.org/tei-simple/query" at "../query.xql";
import module namespace kwic="http://exist-db.org/xquery/kwic" at "resource:org/exist/xquery/lib/kwic.xql";
import module namespace pages="http://www.tei-c.org/tei-simple/pages" at "pages.xql";
import module namespace tpu="http://www.tei-c.org/tei-publisher/util" at "util.xql";
import module namespace nav="http://www.tei-c.org/tei-simple/navigation" at "../navigation.xql";
import module namespace browse="http://www.tei-c.org/tei-simple/templates" at "browse.xql";
import module namespace config="http://www.tei-c.org/tei-simple/config" at "../config.xqm";
(:~
...
...
@@ -54,10 +51,10 @@ function search:query($node as node()*, $model as map(*), $query as xs:string?,
if (empty($query))
then
map {
"hits" : session:get-attribute(
"apps.simple
"),
"hitCount" : session:get-attribute(
"apps.simple
.hitCount"),
"query" : session:get-attribute(
"apps.simple
.query"),
"docs" : session:get-attribute(
"apps.simple
.docs")
"hits" : session:get-attribute(
$config:session-prefix || ".hits
"),
"hitCount" : session:get-attribute(
$config:session-prefix || "
.hitCount"),
"query" : session:get-attribute(
$config:session-prefix || "
.query"),
"docs" : session:get-attribute(
$config:session-prefix || "
.docs")
}
else
(:Otherwise, perform the query.:)
...
...
@@ -72,11 +69,11 @@ function search:query($node as node()*, $model as map(*), $query as xs:string?,
let $hits := if ($hitCount > 1000) then subsequence($hitsAll, 1, 1000) else $hitsAll
(:Store the result in the session.:)
let $store := (
session:set-attribute(
"apps.simple
", $hitsAll),
session:set-attribute(
"apps.simple
.hitCount", $hitCount),
session:set-attribute(
"apps.simple
.query", $query),
session:set-attribute(
"apps.simple
.field", $field),
session:set-attribute(
"apps.simple
.docs", $doc)
session:set-attribute(
$config:session-prefix || ".hits
", $hitsAll),
session:set-attribute(
$config:session-prefix || "
.hitCount", $hitCount),
session:set-attribute(
$config:session-prefix || "
.query", $query),
session:set-attribute(
$config:session-prefix || "
.field", $field),
session:set-attribute(
$config:session-prefix || "
.docs", $doc)
)
return
(: The hits are not returned directly, but processed by the nested templates :)
...
...
modules/lib/upload.xql
View file @
c2b2f2e6
xquery version "3.1";
import module namespace config="http://www.tei-c.org/tei-simple/config" at "../config.xqm";
import module namespace docx="http://existsolutions.com/teipublisher/docx";
import module namespace docx2tei="http://www.tei-c.org/pm/models/docx/tei/module"
at "../../transform/docx-tei-module.xql";
declare namespace json="http://www.json.org";
...
...
@@ -10,7 +14,14 @@ declare function local:upload($root, $paths, $payloads) {
for-each-pair($paths, $payloads, function($path, $data) {
try {
let $path :=
if (ends-with($path, ".odd")) then
if (ends-with($path, ".docx")) then
let $mediaPath := $config:data-root || "/" || $root || "/" || xmldb:encode($path) || ".media"
let $stored := xmldb:store($config:data-root || "/" || $root, xmldb:encode($path), $data)
let $tei :=
docx:process($stored, $config:data-root, docx2tei:transform#2, $mediaPath)
return
xmldb:store($config:data-root || "/" || $root, xmldb:encode($path) || ".xml", $tei)
else if (ends-with($path, ".odd")) then
xmldb:store($config:odd-root, xmldb:encode($path), $data)
else
xmldb:store($config:data-root || "/" || $root, xmldb:encode($path), $data)
...
...
modules/navigation-dbk.xql
View file @
c2b2f2e6
...
...
@@ -23,6 +23,11 @@ declare namespace dbk="http://docbook.org/ns/docbook";
import module namespace config="http://www.tei-c.org/tei-simple/config" at "config.xqm";
declare function nav:get-root($root as xs:string?, $options as map(*)?) {
$config:data-root !
collection(. || "/" || $root)//dbk:section[ft:query(., "file:*", $options)]/ancestor::dbk:article
};
declare function nav:get-header($config as map(*), $node as element()) {
$node/dbk:info
};
...
...
@@ -53,6 +58,14 @@ declare function nav:get-metadata($config as map(*), $root as element(), $field
()
};
declare function nav:sort($sortBy as xs:string, $items as element()*) {
switch ($sortBy)
case "date" return
sort($items, (), ft:field(?, "date", "xs:date"))
default return
sort($items, (), ft:field(?, $sortBy))
};
declare function nav:get-first-page-start($config as map(*), $data as element()) {
()
};
...
...
modules/navigation-tei.xql
View file @
c2b2f2e6
...
...
@@ -24,6 +24,14 @@ declare namespace vg="http://www.vangoghletters.org/ns/";
import module namespace config="http://www.tei-c.org/tei-simple/config" at "config.xqm";
declare
function nav:get-root($root as xs:string?, $options as map(*)?) {
$config:data-default ! (
for $doc in collection(. || "/" || $root)//tei:body[ft:query(., "file:*", $options)]
return
$doc/ancestor::tei:TEI
)
};
declare function nav:get-header($config as map(*), $node as element()) {
$node/tei:teiHeader
...
...
@@ -79,6 +87,15 @@ declare function nav:get-metadata($config as map(*), $root as element(), $field
()
};
declare function nav:sort($sortBy as xs:string, $items as element()*) {
switch ($sortBy)
case "date" return
sort($items, (), ft:field(?, "date", "xs:date"))
default return
sort($items, (), ft:field(?, $sortBy))
};
declare function nav:get-first-page-start($config as map(*), $data as element()) {
let $pb := ($data//tei:pb)[1]
return
...
...
modules/navigation.xql
View file @
c2b2f2e6
...
...
@@ -42,6 +42,10 @@ declare %private function nav:dispatch($config as map(*), $function as xs:string
()
};
declare function nav:get-root($root as xs:string?, $options as map(*)?) {
tei-nav:get-root($root, $options)
};
declare function nav:get-header($config as map(*), $node as element()) {
nav:dispatch($config, "get-header", [$config, $node])
};
...
...
@@ -78,6 +82,13 @@ declare function nav:get-first-page-start($config as map(*), $data as node()) {
nav:dispatch($config, "get-first-page-start", [$config, $data])
};
declare function nav:sort($sortBy as xs:string, $items as element()*) {
if (empty($items)) then
()
else
nav:dispatch(map { "type": nav:document-type(head($items)) }, "sort", [$sortBy, $items])
};
declare function nav:get-content($config as map(*), $div as element()) {
nav:dispatch($config, "get-content", [$config, $div])
};
...
...
modules/tei-query.xql
View file @
c2b2f2e6
...
...
@@ -45,10 +45,8 @@ declare function teis:query-default($fields as xs:string+, $query as xs:string,
if ($target-texts) then
for $text in $target-texts
return
$config:data-root ! doc(. || "/" || $text)//tei:div[ft:query(., $query, teis:options())] |
$config:data-root ! doc(. || "/" || $text)//tei:body[ft:query(., $query, teis:options())]
else
collection($config:data-root)//tei:div[ft:query(., $query, teis:options())] |
collection($config:data-root)//tei:body[ft:query(., $query, teis:options())]
else ()
};
...
...
@@ -93,11 +91,16 @@ declare function teis:autocomplete($doc as xs:string?, $fields as xs:string+, $q
function($key, $count) {
$key
}, 30)
default
return
case "title"
return
collection($config:data-root)/ft:index-keys-for-field("title", $q,
function($key, $count) {
$key
}, 30)
default return
collection($config:data-root)/util:index-keys-by-qname(xs:QName("tei:body"), $q,
function($key, $count) {
$key
}, 30, "lucene-index")
};
...
...
@@ -129,8 +132,8 @@ declare function teis:get-breadcrumbs($config as map(*), $hit as element(), $par
: on it.
:)
declare function teis:expand($data as element()) {
let $query := session:get-attribute(
"apps.simple
.query")
let $field := session:get-attribute(
"apps.simple
.field")
let $query := session:get-attribute(
$config:session-prefix || "
.query")
let $field := session:get-attribute(
$config:session-prefix || "
.field")
let $div :=
if ($data instance of element(tei:pb)) then
let $nextPage := $data/following::tei:pb[1]
...
...
search.html
View file @
c2b2f2e6
...
...
@@ -247,10 +247,6 @@
<
paper
-
card
>
<
div
class
=
"
card-content
"
>
<
pb
-
search
id
=
"
search-form
"
place
-
holder
=
"
i18n(search-query-attr)
"
data
-
template
=
"
pages:parse-params
"
value
=
"
${query}
"
submit
-
on
-
load
=
"
submit-on-load
"
subscribe
=
"
search
"
>
<
div
class
=
"
targets
"
>
<
paper
-
checkbox
name
=
"
tei-target
"
value
=
"
tei-text
"
>
Search
sections
<
/paper-checkbox
>
<
paper
-
checkbox
name
=
"
tei-target
"
value
=
"
tei-head
"
>
Search
headings
<
/paper-checkbox
>
<
/div
>
<
pb
-
custom
-
form
id
=
"
facets
"
url
=
"
modules/facets.xql
"
subscribe
=
"
results
"
event
=
"
pb-results-received
"
emit
=
"
search
"
/>
<
/pb-search
>
<
/div
>
...
...