From f83dab3e6f69d1aff1198b35463d54ab57c94dbd Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Wed, 6 Nov 2024 16:53:09 +0100 Subject: [PATCH 1/8] first shot at fixing #156 --- add/data/xql/search.xql | 14 ++++++++------ add/data/xqm/edition.xqm | 8 ++++++++ app/controller/window/search/SearchWindow.js | 3 ++- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/add/data/xql/search.xql b/add/data/xql/search.xql index 54ec0bb8b..a4f9c45f8 100644 --- a/add/data/xql/search.xql +++ b/add/data/xql/search.xql @@ -8,6 +8,7 @@ xquery version "3.1"; import module namespace kwic = "http://exist-db.org/xquery/kwic"; import module namespace transform="http://exist-db.org/xquery/transform"; +import module namespace edition = "http://www.edirom.de/xquery/edition" at "../xqm/edition.xqm"; import module namespace eutil = "http://www.edirom.de/xquery/util" at "../xqm/util.xqm"; (: NAMESPACE DECLARATIONS ================================================== :) @@ -25,6 +26,7 @@ declare option output:media-type "text/html"; (: VARIABLE DECLARATIONS =================================================== :) declare variable $lang := request:get-parameter('lang', ''); +declare variable $edition := request:get-parameter('uri', ''); (: FUNCTION DECLARATIONS =================================================== :) @@ -75,12 +77,12 @@ let $return := let $search := if (string-length($term) gt 0) then ( - collection('/db')//tei:text[ft:query(., $term)]/ancestor::tei:TEI - | collection('/db')//tei:title[ft:query(., $term)]/ancestor::tei:TEI - | collection('/db')//mei:mei[ft:query(., $term)] - | collection('/db')//mei:title[ft:query(., $term)]/ancestor::mei:mei - | collection('/db')//mei:annot[ft:query(., $term)][@type eq 'editorialComment'] - | collection('/db')//mei:annot[contains(@xml:id, $term)] + edition:collection($edition)//tei:text[ft:query(., $term)]/ancestor::tei:TEI + | edition:collection($edition)//tei:title[ft:query(., $term)]/ancestor::tei:TEI + | edition:collection($edition)//mei:mei[ft:query(., $term)] + | edition:collection($edition)//mei:title[ft:query(., $term)]/ancestor::mei:mei + | edition:collection($edition)//mei:annot[ft:query(., $term)][@type eq 'editorialComment'] + | edition:collection($edition)//mei:annot[contains(@xml:id, $term)] ) else () diff --git a/add/data/xqm/edition.xqm b/add/data/xqm/edition.xqm index d47d1d235..5c5f684dd 100644 --- a/add/data/xqm/edition.xqm +++ b/add/data/xqm/edition.xqm @@ -13,11 +13,13 @@ module namespace edition = "http://www.edirom.de/xquery/edition"; (: IMPORTS ================================================================= :) import module namespace functx="http://www.functx.com"; +import module namespace eutil = "http://www.edirom.de/xquery/util" at "util.xqm"; (: NAMESPACE DECLARATIONS ================================================== :) declare namespace edirom = "http://www.edirom.de/ns/1.3"; declare namespace xlink = "http://www.w3.org/1999/xlink"; +declare namespace util = "http://exist-db.org/xquery/util"; (: VARIABLE DECLARATIONS =================================================== :) @@ -188,3 +190,9 @@ declare function edition:getFrontendUri($editionUri as xs:string, $contextPath a return string-join(($contextPath, $editionContext), '/') }; + +declare function edition:collection($edition as xs:string?) as document-node()* { + if($edition) + then collection(eutil:getPreference('edition_path', $edition)) + else util:log('warn', 'No edition provided') +}; diff --git a/app/controller/window/search/SearchWindow.js b/app/controller/window/search/SearchWindow.js index 8430b601d..4fa95dfef 100644 --- a/app/controller/window/search/SearchWindow.js +++ b/app/controller/window/search/SearchWindow.js @@ -68,7 +68,8 @@ Ext.define('EdiromOnline.controller.window.search.SearchWindow', { 'GET', { term: term, - lang: getPreference('application_language') + lang: getPreference('application_language'), + uri: view.uri }, Ext.bind(function(response){ me.win.setResult(response.responseText); From 82f413f473ad55bb1af10ec7116516878dbb59f9 Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Wed, 6 Nov 2024 19:44:43 +0100 Subject: [PATCH 2/8] that's actually not needed The `edition` parameter is automatically added by `window.doAJAXRequest` --- app/controller/window/search/SearchWindow.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controller/window/search/SearchWindow.js b/app/controller/window/search/SearchWindow.js index 4fa95dfef..8430b601d 100644 --- a/app/controller/window/search/SearchWindow.js +++ b/app/controller/window/search/SearchWindow.js @@ -68,8 +68,7 @@ Ext.define('EdiromOnline.controller.window.search.SearchWindow', { 'GET', { term: term, - lang: getPreference('application_language'), - uri: view.uri + lang: getPreference('application_language') }, Ext.bind(function(response){ me.win.setResult(response.responseText); From 3e40ec7b637263d8379b43678e66837dcd19c959 Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Thu, 7 Nov 2024 12:18:16 +0100 Subject: [PATCH 3/8] move variables to query body and fix parameter name from `uri` to `edition` --- add/data/xql/search.xql | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/add/data/xql/search.xql b/add/data/xql/search.xql index a4f9c45f8..683cf6e29 100644 --- a/add/data/xql/search.xql +++ b/add/data/xql/search.xql @@ -23,11 +23,6 @@ declare namespace tei = "http://www.tei-c.org/ns/1.0"; declare option output:method "xhtml"; declare option output:media-type "text/html"; -(: VARIABLE DECLARATIONS =================================================== :) - -declare variable $lang := request:get-parameter('lang', ''); -declare variable $edition := request:get-parameter('uri', ''); - (: FUNCTION DECLARATIONS =================================================== :) declare function local:filter($node as node(), $mode as xs:string) as xs:string? { @@ -50,6 +45,8 @@ declare function local:getPath($node as node()) as xs:string { (: QUERY BODY ============================================================== :) +let $lang := request:get-parameter('lang', '') +let $edition := request:get-parameter('edition', '') let $term := request:get-parameter('term', '') let $trans := From e6cdc9f752f90e197faf6f5ec29822936873e0ee Mon Sep 17 00:00:00 2001 From: Hizkiel Date: Thu, 7 Nov 2024 14:59:38 +0100 Subject: [PATCH 4/8] fix function for displaying kwic results --- add/data/xql/search.xql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/add/data/xql/search.xql b/add/data/xql/search.xql index 683cf6e29..3fc15411f 100644 --- a/add/data/xql/search.xql +++ b/add/data/xql/search.xql @@ -82,7 +82,6 @@ let $return := | edition:collection($edition)//mei:annot[contains(@xml:id, $term)] ) else () - return ( if (count($search) gt 0) then ( @@ -159,13 +158,14 @@ let $return := else ('') }">{ - kwic:get-summary($match, ($match/exist:match)[1], , - util:function(xs:QName("local:filter"), 2)) + local:filter#2 + ) } , if ($hitCount gt 3) then From d83133d11f71f3269d1ca60a5879686249f8c90d Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Fri, 8 Nov 2024 15:05:10 +0100 Subject: [PATCH 5/8] improve inline function documentation --- add/data/xqm/edition.xqm | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/add/data/xqm/edition.xqm b/add/data/xqm/edition.xqm index 5c5f684dd..e1253b9b7 100644 --- a/add/data/xqm/edition.xqm +++ b/add/data/xqm/edition.xqm @@ -176,12 +176,11 @@ declare function edition:getName($uri as xs:string) as xs:string { (:~ : Returns the frontend URI of the edition, e.g. if the edirom:edition file : submitted via $editionUri is xmldb:exist///db/apps/editionFolder/edition.xml - : and the $contextPath is /exist the string returned woud be /exist/apps/editionFolder + : and the $contextPath is /exist the string returned would be /exist/apps/editionFolder : - : @param $editionUri The xmldb-collection-path of the edition - : @param $contextPath the request:get-context-path() of the frontend - : - : @return xs:string + : @param $editionUri The URI of the Edition's document to process + : @param $contextPath The request:get-context-path() of the frontend + : @return The frontend URI of the edition :) declare function edition:getFrontendUri($editionUri as xs:string, $contextPath as xs:string) as xs:string { @@ -191,8 +190,17 @@ declare function edition:getFrontendUri($editionUri as xs:string, $contextPath a string-join(($contextPath, $editionContext), '/') }; -declare function edition:collection($edition as xs:string?) as document-node()* { - if($edition) - then collection(eutil:getPreference('edition_path', $edition)) +(:~ + : Returns the documents contained in the collection specified by the + : `edition_path` parameter in the edition's preference file. + : If `$editionUri` is the empty sequence or no information is found + : for `edition_path`, the empty sequence is returned. + : + : @param $edition The URI of the Edition's document to process + : @return The document nodes contained in or under the given collection + :) +declare function edition:collection($editionUri as xs:string?) as document-node()* { + if($editionUri and eutil:getPreference('edition_path', $editionUri)) + then collection(eutil:getPreference('edition_path', $editionUri)) else util:log('warn', 'No edition provided') }; From 8307eb4ae8450a55a652274d5b76dcc23b5911a5 Mon Sep 17 00:00:00 2001 From: Peter Stadler Date: Fri, 8 Nov 2024 15:23:14 +0100 Subject: [PATCH 6/8] fix callback function --- add/data/xql/search.xql | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/add/data/xql/search.xql b/add/data/xql/search.xql index 3fc15411f..1633c0e99 100644 --- a/add/data/xql/search.xql +++ b/add/data/xql/search.xql @@ -25,11 +25,16 @@ declare option output:media-type "text/html"; (: FUNCTION DECLARATIONS =================================================== :) -declare function local:filter($node as node(), $mode as xs:string) as xs:string? { +(:~ + : Callback function for `kwic:get-summary` + : Contrary to the documentation at https://exist-db.org/exist/apps/doc/kwic (1Q18) + : this function has to return a node(), see https://github.com/eXist-db/exist/issues/4239 + :) +declare function local:filter($node as node(), $mode as xs:string) as node()? { if ($mode eq 'before') then - concat($node, ' ') + text { concat($node, ' ') } else - concat(' ', $node) + text { concat(' ', $node) } }; declare function local:getPath($node as node()) as xs:string { @@ -158,7 +163,7 @@ let $return := else ('') }">{ - kwic:get-summary(kwic:expand($match), ($match/exist:match)[1],