eXist-db Lucene / KWIC output - linking to URL for document that produced a $hit
In eXist-DB 4.4 I have managed to deploy a simple Lucern query with KWIC output as a table.
I have a collection of tei:xml
documents which looks like this sample:
<TEI xml:id="MS609-0001.xml">
<text xml:id="MS609-0001">
[...]
<seg type="dep_event" subtype="event" xml:id="MS609-0001-1">
<pb n="1r"/>
<lb break="n" n="1"/>
<date type="deposition_date" when="1245-05-27" cert="high">Anno
Domini M° CC° XL° quinto VI Kalendas Iunii.</date>
<persName nymRef="#Arnald_Garnier_MSP-AU" role="dep">Arnaldus Garnerii</persName>
testis iuratus dixit quod vidit in
<placeName type="event_loc" nymRef="#home_of_Cap-de-Porc">domo
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" role="own">Petri de Sancto Andrea</persName>
</placeName>
<lb break="y" n="2"/>
<persName nymRef="#Bernard_Cap-de-Porc_MSP-AU" role="her">B<supplied reason="expname">ernardum</supplied> de Sancto Andrea</persName>,
fratrem dicti Petri, et socium eius, hereticos. Et vidit ibi cum eis dictum
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">P<supplied reason="expname">etrum</supplied> de Sancto Andrea</persName> et
<persName nymRef="#Susanna_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">uxor dicti<lb break="y" n="3"/>Petri</persName>. Et
<persName nymRef="#Arnald_Garnier_MSP-AU" ana="#pAdo" role="par"/>ipse
testis adoravit ibi dictos hereticos, sed non vidit alios adorare. Et
<date type="event_date" when="1239">sunt VI anni vel circa</date>.
<seg type="inq_int" subtype="specific_question">Et quando ipse testis exivit<lb break="y" n="4"/>domum invenit
<persName nymRef="#Guilhem_de_Rosengue_MSP-AU" key="inqint" ana="#pIntra" role="ref">Willelmus de Rozergue</persName> intrantem ad dictos hereticos.</seg>
</seg>
<seg>
[...]
</seg>
[...]
<text>
<TEI>
With this function calling KWIC:
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace kwic="http://exist-db.org/xquery/kwic";
let $query :=
<query>
<wildcard>heret*</wildcard>
</query>
for $hit in collection('/db/apps/deheresi/data/')//tei:seg[ft:query(.,$query)]
order by ft:score($hit) descending
return
kwic:summarize($hit, <config width="80" table="yes" />)
I get for example these results as a table:
<tr>
<td class="previous">...ernardum de Sancto Andrea,
fratrem dicti Petri, et socium eius, </td>
<td class="hi">hereticos</td>
<td class="following">. Et vidit ibi cum eis dictum
Petrum de Sancto Andrea et
...</td>
</tr>
<tr>
<td class="previous">...r dicti Petri. Et ipse
testis adoravit ibi dictos </td>
<td class="hi">hereticos</td>
<td class="following">, sed non vidit alios adorare. Et
sunt VI anni vel circa...</td>
</tr>
What I'd like to do is wrap the text in <td class="hi"/>
in a url that points to the source document viewable on the site. The site logic is quite 'clean', such that the first entry's <td class="hi">
would look like this:
<td class="hi"><a href="http://localhost:8081/exist/apps/deheresi/doc/MS609-0001">hereticos</a></td>
Where the url is a concat of
http://localhost:8081/exist/apps/deheresi/doc/
and the value of the respective result's ancestor node
tei:text/@xml:id
(which will always be an ancestor node of whatever tei:seg
content is returned in the query).
I note there is a @link
attribute available on the <config>
parameter in kwic:summarize()
, but I don't know how to dynamically get the source document nodes from the returned result in order to fill that in.
Many thanks in advance.
xquery exist-db tei
add a comment |
In eXist-DB 4.4 I have managed to deploy a simple Lucern query with KWIC output as a table.
I have a collection of tei:xml
documents which looks like this sample:
<TEI xml:id="MS609-0001.xml">
<text xml:id="MS609-0001">
[...]
<seg type="dep_event" subtype="event" xml:id="MS609-0001-1">
<pb n="1r"/>
<lb break="n" n="1"/>
<date type="deposition_date" when="1245-05-27" cert="high">Anno
Domini M° CC° XL° quinto VI Kalendas Iunii.</date>
<persName nymRef="#Arnald_Garnier_MSP-AU" role="dep">Arnaldus Garnerii</persName>
testis iuratus dixit quod vidit in
<placeName type="event_loc" nymRef="#home_of_Cap-de-Porc">domo
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" role="own">Petri de Sancto Andrea</persName>
</placeName>
<lb break="y" n="2"/>
<persName nymRef="#Bernard_Cap-de-Porc_MSP-AU" role="her">B<supplied reason="expname">ernardum</supplied> de Sancto Andrea</persName>,
fratrem dicti Petri, et socium eius, hereticos. Et vidit ibi cum eis dictum
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">P<supplied reason="expname">etrum</supplied> de Sancto Andrea</persName> et
<persName nymRef="#Susanna_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">uxor dicti<lb break="y" n="3"/>Petri</persName>. Et
<persName nymRef="#Arnald_Garnier_MSP-AU" ana="#pAdo" role="par"/>ipse
testis adoravit ibi dictos hereticos, sed non vidit alios adorare. Et
<date type="event_date" when="1239">sunt VI anni vel circa</date>.
<seg type="inq_int" subtype="specific_question">Et quando ipse testis exivit<lb break="y" n="4"/>domum invenit
<persName nymRef="#Guilhem_de_Rosengue_MSP-AU" key="inqint" ana="#pIntra" role="ref">Willelmus de Rozergue</persName> intrantem ad dictos hereticos.</seg>
</seg>
<seg>
[...]
</seg>
[...]
<text>
<TEI>
With this function calling KWIC:
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace kwic="http://exist-db.org/xquery/kwic";
let $query :=
<query>
<wildcard>heret*</wildcard>
</query>
for $hit in collection('/db/apps/deheresi/data/')//tei:seg[ft:query(.,$query)]
order by ft:score($hit) descending
return
kwic:summarize($hit, <config width="80" table="yes" />)
I get for example these results as a table:
<tr>
<td class="previous">...ernardum de Sancto Andrea,
fratrem dicti Petri, et socium eius, </td>
<td class="hi">hereticos</td>
<td class="following">. Et vidit ibi cum eis dictum
Petrum de Sancto Andrea et
...</td>
</tr>
<tr>
<td class="previous">...r dicti Petri. Et ipse
testis adoravit ibi dictos </td>
<td class="hi">hereticos</td>
<td class="following">, sed non vidit alios adorare. Et
sunt VI anni vel circa...</td>
</tr>
What I'd like to do is wrap the text in <td class="hi"/>
in a url that points to the source document viewable on the site. The site logic is quite 'clean', such that the first entry's <td class="hi">
would look like this:
<td class="hi"><a href="http://localhost:8081/exist/apps/deheresi/doc/MS609-0001">hereticos</a></td>
Where the url is a concat of
http://localhost:8081/exist/apps/deheresi/doc/
and the value of the respective result's ancestor node
tei:text/@xml:id
(which will always be an ancestor node of whatever tei:seg
content is returned in the query).
I note there is a @link
attribute available on the <config>
parameter in kwic:summarize()
, but I don't know how to dynamically get the source document nodes from the returned result in order to fill that in.
Many thanks in advance.
xquery exist-db tei
add a comment |
In eXist-DB 4.4 I have managed to deploy a simple Lucern query with KWIC output as a table.
I have a collection of tei:xml
documents which looks like this sample:
<TEI xml:id="MS609-0001.xml">
<text xml:id="MS609-0001">
[...]
<seg type="dep_event" subtype="event" xml:id="MS609-0001-1">
<pb n="1r"/>
<lb break="n" n="1"/>
<date type="deposition_date" when="1245-05-27" cert="high">Anno
Domini M° CC° XL° quinto VI Kalendas Iunii.</date>
<persName nymRef="#Arnald_Garnier_MSP-AU" role="dep">Arnaldus Garnerii</persName>
testis iuratus dixit quod vidit in
<placeName type="event_loc" nymRef="#home_of_Cap-de-Porc">domo
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" role="own">Petri de Sancto Andrea</persName>
</placeName>
<lb break="y" n="2"/>
<persName nymRef="#Bernard_Cap-de-Porc_MSP-AU" role="her">B<supplied reason="expname">ernardum</supplied> de Sancto Andrea</persName>,
fratrem dicti Petri, et socium eius, hereticos. Et vidit ibi cum eis dictum
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">P<supplied reason="expname">etrum</supplied> de Sancto Andrea</persName> et
<persName nymRef="#Susanna_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">uxor dicti<lb break="y" n="3"/>Petri</persName>. Et
<persName nymRef="#Arnald_Garnier_MSP-AU" ana="#pAdo" role="par"/>ipse
testis adoravit ibi dictos hereticos, sed non vidit alios adorare. Et
<date type="event_date" when="1239">sunt VI anni vel circa</date>.
<seg type="inq_int" subtype="specific_question">Et quando ipse testis exivit<lb break="y" n="4"/>domum invenit
<persName nymRef="#Guilhem_de_Rosengue_MSP-AU" key="inqint" ana="#pIntra" role="ref">Willelmus de Rozergue</persName> intrantem ad dictos hereticos.</seg>
</seg>
<seg>
[...]
</seg>
[...]
<text>
<TEI>
With this function calling KWIC:
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace kwic="http://exist-db.org/xquery/kwic";
let $query :=
<query>
<wildcard>heret*</wildcard>
</query>
for $hit in collection('/db/apps/deheresi/data/')//tei:seg[ft:query(.,$query)]
order by ft:score($hit) descending
return
kwic:summarize($hit, <config width="80" table="yes" />)
I get for example these results as a table:
<tr>
<td class="previous">...ernardum de Sancto Andrea,
fratrem dicti Petri, et socium eius, </td>
<td class="hi">hereticos</td>
<td class="following">. Et vidit ibi cum eis dictum
Petrum de Sancto Andrea et
...</td>
</tr>
<tr>
<td class="previous">...r dicti Petri. Et ipse
testis adoravit ibi dictos </td>
<td class="hi">hereticos</td>
<td class="following">, sed non vidit alios adorare. Et
sunt VI anni vel circa...</td>
</tr>
What I'd like to do is wrap the text in <td class="hi"/>
in a url that points to the source document viewable on the site. The site logic is quite 'clean', such that the first entry's <td class="hi">
would look like this:
<td class="hi"><a href="http://localhost:8081/exist/apps/deheresi/doc/MS609-0001">hereticos</a></td>
Where the url is a concat of
http://localhost:8081/exist/apps/deheresi/doc/
and the value of the respective result's ancestor node
tei:text/@xml:id
(which will always be an ancestor node of whatever tei:seg
content is returned in the query).
I note there is a @link
attribute available on the <config>
parameter in kwic:summarize()
, but I don't know how to dynamically get the source document nodes from the returned result in order to fill that in.
Many thanks in advance.
xquery exist-db tei
In eXist-DB 4.4 I have managed to deploy a simple Lucern query with KWIC output as a table.
I have a collection of tei:xml
documents which looks like this sample:
<TEI xml:id="MS609-0001.xml">
<text xml:id="MS609-0001">
[...]
<seg type="dep_event" subtype="event" xml:id="MS609-0001-1">
<pb n="1r"/>
<lb break="n" n="1"/>
<date type="deposition_date" when="1245-05-27" cert="high">Anno
Domini M° CC° XL° quinto VI Kalendas Iunii.</date>
<persName nymRef="#Arnald_Garnier_MSP-AU" role="dep">Arnaldus Garnerii</persName>
testis iuratus dixit quod vidit in
<placeName type="event_loc" nymRef="#home_of_Cap-de-Porc">domo
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" role="own">Petri de Sancto Andrea</persName>
</placeName>
<lb break="y" n="2"/>
<persName nymRef="#Bernard_Cap-de-Porc_MSP-AU" role="her">B<supplied reason="expname">ernardum</supplied> de Sancto Andrea</persName>,
fratrem dicti Petri, et socium eius, hereticos. Et vidit ibi cum eis dictum
<persName nymRef="#Peire_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">P<supplied reason="expname">etrum</supplied> de Sancto Andrea</persName> et
<persName nymRef="#Susanna_Cap-de-Porc_MSP-AU" ana="#uAdo" role="par">uxor dicti<lb break="y" n="3"/>Petri</persName>. Et
<persName nymRef="#Arnald_Garnier_MSP-AU" ana="#pAdo" role="par"/>ipse
testis adoravit ibi dictos hereticos, sed non vidit alios adorare. Et
<date type="event_date" when="1239">sunt VI anni vel circa</date>.
<seg type="inq_int" subtype="specific_question">Et quando ipse testis exivit<lb break="y" n="4"/>domum invenit
<persName nymRef="#Guilhem_de_Rosengue_MSP-AU" key="inqint" ana="#pIntra" role="ref">Willelmus de Rozergue</persName> intrantem ad dictos hereticos.</seg>
</seg>
<seg>
[...]
</seg>
[...]
<text>
<TEI>
With this function calling KWIC:
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace kwic="http://exist-db.org/xquery/kwic";
let $query :=
<query>
<wildcard>heret*</wildcard>
</query>
for $hit in collection('/db/apps/deheresi/data/')//tei:seg[ft:query(.,$query)]
order by ft:score($hit) descending
return
kwic:summarize($hit, <config width="80" table="yes" />)
I get for example these results as a table:
<tr>
<td class="previous">...ernardum de Sancto Andrea,
fratrem dicti Petri, et socium eius, </td>
<td class="hi">hereticos</td>
<td class="following">. Et vidit ibi cum eis dictum
Petrum de Sancto Andrea et
...</td>
</tr>
<tr>
<td class="previous">...r dicti Petri. Et ipse
testis adoravit ibi dictos </td>
<td class="hi">hereticos</td>
<td class="following">, sed non vidit alios adorare. Et
sunt VI anni vel circa...</td>
</tr>
What I'd like to do is wrap the text in <td class="hi"/>
in a url that points to the source document viewable on the site. The site logic is quite 'clean', such that the first entry's <td class="hi">
would look like this:
<td class="hi"><a href="http://localhost:8081/exist/apps/deheresi/doc/MS609-0001">hereticos</a></td>
Where the url is a concat of
http://localhost:8081/exist/apps/deheresi/doc/
and the value of the respective result's ancestor node
tei:text/@xml:id
(which will always be an ancestor node of whatever tei:seg
content is returned in the query).
I note there is a @link
attribute available on the <config>
parameter in kwic:summarize()
, but I don't know how to dynamically get the source document nodes from the returned result in order to fill that in.
Many thanks in advance.
xquery exist-db tei
xquery exist-db tei
edited Nov 14 '18 at 14:04
jbrehr
asked Nov 14 '18 at 13:46
jbrehrjbrehr
134212
134212
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It turns out that the node $hit
allows access to the rest of the source document (or a copy of it in memory). Thus, I was able to build a URL as string using $hit/ancestor
let $doclink := concat("http://localhost:8081/exist/apps/deheresi/doc/", $hit/ancestor::tei:text/data(@xml:id))
Then fed that string into the function parameter @link
:
kwic:summarize($hit, <config width="80" table="yes" link="{$doclink}"/>)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301714%2fexist-db-lucene-kwic-output-linking-to-url-for-document-that-produced-a-hit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It turns out that the node $hit
allows access to the rest of the source document (or a copy of it in memory). Thus, I was able to build a URL as string using $hit/ancestor
let $doclink := concat("http://localhost:8081/exist/apps/deheresi/doc/", $hit/ancestor::tei:text/data(@xml:id))
Then fed that string into the function parameter @link
:
kwic:summarize($hit, <config width="80" table="yes" link="{$doclink}"/>)
add a comment |
It turns out that the node $hit
allows access to the rest of the source document (or a copy of it in memory). Thus, I was able to build a URL as string using $hit/ancestor
let $doclink := concat("http://localhost:8081/exist/apps/deheresi/doc/", $hit/ancestor::tei:text/data(@xml:id))
Then fed that string into the function parameter @link
:
kwic:summarize($hit, <config width="80" table="yes" link="{$doclink}"/>)
add a comment |
It turns out that the node $hit
allows access to the rest of the source document (or a copy of it in memory). Thus, I was able to build a URL as string using $hit/ancestor
let $doclink := concat("http://localhost:8081/exist/apps/deheresi/doc/", $hit/ancestor::tei:text/data(@xml:id))
Then fed that string into the function parameter @link
:
kwic:summarize($hit, <config width="80" table="yes" link="{$doclink}"/>)
It turns out that the node $hit
allows access to the rest of the source document (or a copy of it in memory). Thus, I was able to build a URL as string using $hit/ancestor
let $doclink := concat("http://localhost:8081/exist/apps/deheresi/doc/", $hit/ancestor::tei:text/data(@xml:id))
Then fed that string into the function parameter @link
:
kwic:summarize($hit, <config width="80" table="yes" link="{$doclink}"/>)
answered Nov 14 '18 at 21:31
jbrehrjbrehr
134212
134212
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53301714%2fexist-db-lucene-kwic-output-linking-to-url-for-document-that-produced-a-hit%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown