nesting queries
Monday, 12 March 2012 · 3 messages · last reply 15 Mar 2012
CM
Cerstin Mahlow12 Mar 2012 16:30 #
Hi,
I would like to have a nested xquery, but I am not sure if this is possible at all:
When a user searches the corpus, he can save the hits he likes most. The result for the query is a form with checkboxes. The node IDs together with the query and a time stamp are saved in a second collection. This collections looks like this:
<collection>
<entry time="2012-03-04T17:24:53">
<node>1434455</node>
<query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query>
<person>xyz</person>
<phraseme>Ad0024</phraseme>
<selected>yes</selected>
</entry>
<entry time="2012-03-04T17:24:53">
<node>1475764</node>
<query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query>
<person>abc</person>
<phraseme>Ad0024</phraseme>
<selected>no</selected>
</entry>
</collection>When the user searches again with a different query, he will see the results as for the first search and is able to save only those that are not in the hit-collection. This is controlled by this part in the "return" part of the xquery in my perl client:
{
if (not (db:open("collect")//node[text() = \$node and ../phraseme[text() = "$phraseme"] and ../selected[text() = "yes"]]))
then <input type="checkbox" name="NODE" value="{\node}"/>
else "X"
}Already saved hits get an "X" and new hits get the checkbox.
For documentation, I would like to collect all queries a node could be found with. Thus, instead of printing "X", I would like to add an additional query-element to the entry-element, i.e., something like
insert node <query>$query</query> after /collection/entry/node[text() = "\$node" and ../phraseme[text() = "$phraseme" and ../selected[text() = "yes"]]]
to get:
<collection>
<entry time="2012-03-04T17:24:53">
<node>1434455</node>
<query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query>
<query>[text() contains text ('Daumen' ftand 'Auge') using stemming using language "de" distance at most 10 words ordered]</query>
<query>[text() contains text ('Daumen' ftand 'Auge') distance at most 10 words ordered]</query>
<person>xyz</person>
<phraseme>Ad0024</phraseme>
<selected>yes</selected>
</entry>
<entry time="2012-03-04T17:24:53">
<node>1475764</node>
<query>[text() contains text ('Daumen' ftand 'Auge' ftand 'halten') using stemming using language "de" distance at most 10 words ordered]</query>
<person>abc</person>
<phraseme>Ad0024</phraseme>
<selected>no</selected>
</entry>
</collection>However, I am not sure if it is possible at all to mix displaying (in the "then" part) and updating (in the "else" part) -- although I would like to update a different collection than I am searching. If it is possible, I guess I have to include the name of the collection for insertion by using db:open? Is it necessary to specify the exact place for insertion (as in my example) as this should be already determined by the condition?
Best regards
Cerstin
--
Dr. phil. Cerstin Mahlow
Universität Basel
Deutsches Seminar
Nadelberg 4
4051 Basel
Schweiz
Tel: +41 61 267 07 65
Fax: +41 61 267 34 40
Mail: cerstin.mahlow at unibas.ch
Web: http://www.oldphras.net
LK
Lukas Kircher14 Mar 2012 13:42 #
Hi Cerstin,
However, I am not sure if it is possible at all to mix displaying
(in the "then" part) and updating (in the "else" part)
True - that's actually a limitation of the update specification, wich forbids
mixing updating and non-updating expressions. You can find some information on it in our documentation [1] and in the actual XQuery specification [2]. As a consequence you have to insert the new query element during a consecutive query.
Quoted text · Cerstin Mahlow · 2 lines
If it is possible, I guess I have to include the name of the collection for > insertion
by using db:open? Is it necessary to specify the exact place for insertion
Quoted text · Cerstin Mahlow · 1 line
> (as in
my example) as this should be already determined by the condition?
Quoted text · Cerstin Mahlow · 1 line
>
Declaring a variable via the Let expression would help to specify the exact location only once ... but of course as you have to insert the node during a second query it's not helping here.
Sorry that I can't provide you with a better solution ... feel free to ask for more.
Best regards,
Lukas
[1] http://docs.basex.org/wiki/Update#Returning_Results
[2] http://www.w3.org/TR/xquery-update-10/#id-conditional-expr
CM
Cerstin Mahlow15 Mar 2012 17:29 #
Hi Lukas,
Zitat von Lukas Kircher <lukaskircher1 at googlemail.com>:
Quoted text · Lukas Kircher · 11 lines
>> However, I am not sure if it is possible at all to mix displaying >> >> (in the "then" part) and updating (in the "else" part) >> > > True - that's actually a limitation of the update specification, wich > forbids > mixing updating and non-updating expressions. You can find some information > on it in our documentation [1] and in the actual XQuery specification [2]. > As a consequence you have to insert the new query element during a > consecutive query.
OK, thanks for clarification.
Cerstin
--
Dr. phil. Cerstin Mahlow
Universität Basel
Deutsches Seminar
Nadelberg 4
4051 Basel
Schweiz
Tel: +41 61 267 07 65
Fax: +41 61 267 34 40
Mail: cerstin.mahlow at unibas.ch
Web: http://www.oldphras.net
---------------------------------------------------------------- This message was sent using IMP, the Internet Messaging Program.
Written for BaseX 7.1. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery