Hi,
I have a problem with slow queries. I'm not sure if it is due to the construction of the query or if there is something else going on.
I'm querying two databases: "collect" which is opened at the beginning and contains several thousands entries like these two:
<entry time="2012-05-22T11:27:09"> <node>40177618</node> <query>[text() contains text ('den' ftand 'Hals' ftand 'brachen') distance at most 10 words]</query> <person>britta</person> <phraseme>Ad0194</phraseme> <selected>yes</selected> </entry> <entry time="2012-05-22T11:27:09"> <node>40672561</node> <query>[text() contains text ('den' ftand 'Hals' ftand 'brachen') distance at most 10 words]</query> <person>britta</person> <phraseme>Ad0194</phraseme> <selected>no</selected> </entry>
The node-ids refer to a second database: "TG-DTA-GerManC-stemming-ws". The queries contain the xquery the node was found with.
For a particular phraseme, I display the original node using ft:mark to highlight the query terms. Additionally, I display some of the metadata for this node. The user will be able to "delete" some of the entries -- i.e., setting the value of "selected" from "yes" to "no". Therefore I render everything as a form element with a checkbox. The query is this one:
for $i at $p in //entry[phraseme[text() = "Ad0194"] and selected[text() = "yes"]] let $query := $i/query let $node := $i/node let $prefix := fn:in-scope-prefixes($i) let $title := db:open-id('TG-DTA-GerManC-stemming-ws', $node) /ancestor::*:TEI[1]//*:fileDesc[1]//*:titleStmt[1]//*:title[1] let $author := db:open-id('TG-DTA-GerManC-stemming-ws', $node) /ancestor::*:TEI[1]//*:sourceDesc[1]//*:bibl[1]//*:author[1] let $note := db:open-id('TG-DTA-GerManC-stemming-ws', $node) /ancestor::*:TEI[1]//*:notesStmt//*:note let $expr := concat("ft:mark(db:open-id('TG-DTA-GerManC-stemming-ws', ", $node, ") ", $query, ")") let $time := data($i/@time) return <div> <hit count="{ $p}"> <p> <input type="checkbox" name="NODE" value="{$node}"/> <b class="hitno">{$p} ({ if($prefix = "dta") then "DTA" else "TG"})</b>Knoten: {$i/node} </p> {xquery:eval($expr)} </hit> <bib> <p class="bibl"> <b>{$time}</b><br/> <b>Bibliographie</b> { data($author)}: { data($title)} <br/> <b>Anmerkung</b>: { data ($note) }<br/> <b>Korpus</b>: { if($prefix = "dta") then "Deutsches Textarchiv" else "TextGrid Digitale Bibliothek"} </p> </bib> <p></p> </div>
However, for this particular phraseme ("Ad0194"), there will be 676 hits to be displayed (out of around 1000 stored) which takes around 15 seconds in the GUI. In the actual web application, the full site is shown after more than 20 seconds (there is some HTML to be displayed and another short xquery for displaying distinct queries for all entries in question), which is too slow, I think.
Is there anything I can do to speed up the query? Can I somehow rewrite it to make execution faster? I think opening the second DB four times costs a lot of time. Both DBs have an optimized index already.
Thanks in advance
Cerstin