store results of a query in a new database

Thursday, 14 March 2013 · 8 messages · last reply 21 Mar 2013
CM
Cerstin Elisabeth Mahlow14 Mar 2013 19:11 #
Hi, I would like to store the results of an xquery extracting some nodes from an existing database into a new database. So I have the DB 'collect' open and then do:
db:create('annotate-abcdef')
and then
for $i at $p in //entry[phraseme[text() = "abcdef"] and selected[text() = "yes"]]
    let $query := $i/query
    let $nodeid := $i/node
    let $node := db:open-id('TG-DTA-GerManC-stemming-ws', $nodeid)
    let $nodename := name($node)
    let $nodecontent := string($node)
    return insert node <div>{$nodeid} {$query} {element {$nodename} {$nodecontent}}
</div> as last into db:open('annotate-abcdef')
However, the error message is [XUDY0027] Insert target must not be empty. How would I add a root element to the new DB, as I don't wan't to link it to an existing document? All nodes added to the DB are only results from queries over an existing DB. All I can see from the Wiki is using a document as initial data for the DB. How do I set UPDINDEX ON for the new DB? I will later update the information added in the first place by other queries. To be able to use ft:mark, I would have to optimize the DB with db:optimize() after having added nodes, is this correct? Thanks in advance and best regards Cerstin
-- Dr. phil. Cerstin Mahlow Universität Basel Departement Sprach- und Literaturwissenschaften Fachbereich Deutsche Sprach- und Literaturwissenschaft 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
CM
Cerstin Elisabeth Mahlow18 Mar 2013 11:14 #
Hi ,
Quoted text · Cerstin Elisabeth Mahlow · 2 lines
Am 14.03.2013 um 19:11 schrieb Cerstin Elisabeth Mahlow <cerstin.mahlow at unibas.ch>: > How would I add a root element to the new DB, as I don't wan't to link it to an existing document? All nodes added to the DB are only results from queries over an existing DB. All I can see from the Wiki is using a document as initial data for the DB.
I now use a rather odd workaround:
db:create('annotate', <root/>, '/dev/null/')
I think it should be possible to create a DB with a root element only, not requiring a document. As I want to use fulltext queries for this DB later, I created the fulltext index after inserting all nodes. It seems that one has to run OPTIMIZE first and only afterwards can create the fulltext index with CREATE INDEX. Is this correct? Or is it possible to create all indexes with one command? When I update this DB later by letting users interact, do I have to run OPTIMIZE after every update to be able to use ft:mark for the following user interactions? Thanks in advance Cerstin
-- Dr. phil. Cerstin Mahlow Universität Basel Departement Sprach- und Literaturwissenschaften Fachbereich Deutsche Sprach- und Literaturwissenschaft 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
CG
Christian Grünin reply to Cerstin Elisabeth Mahlow, 14 Mar 2013, 19:1118 Mar 2013 15:54 #
Hi Cerstin,
Quoted text · Cerstin Elisabeth Mahlow · 2 lines
> So I have the DB 'collect' open and then do: > db:create('annotate-abcdef')
as you guessed, you’ll have to specify a document path, in which you can then add new nodes. Every XML document has a root node, and vice versa, so it’s conceptually not possible to only create a root node without a document. Please note, however, that your second argument is simply the name and path of your document, and does not read any input.
Quoted text · Cerstin Elisabeth Mahlow · 1 line
> How do I set UPDINDEX ON for the new DB?
The following lines should do what you need:
  declare option db:ftindex "on";
  declare option db:updindex "on";
  db:create('annotate', <root/>, 'root.xml')
If you activate the FTINDEX option before creating a database, the OPTIMIZE call will always create/update your full-text index.
Quoted text · Cerstin Elisabeth Mahlow · 1 line
> To be able to use ft:mark, I would have to optimize the DB with db:optimize() after having added nodes, is this correct?
ft:mark() also works without full-text index, but the index solution is usually faster. Christian
CM
Cerstin Elisabeth Mahlow18 Mar 2013 16:30 #
Hi Christian, Am 18.03.2013 um 15:54 schrieb Christian Grün <christian.gruen at gmail.com> :
Quoted text · Christian Grün · 9 lines
>> So I have the DB 'collect' open and then do: >> db:create('annotate-abcdef') > > as you guessed, you’ll have to specify a document path, in which you > can then add new nodes. Every XML document has a root node, and vice > versa, so it’s conceptually not possible to only create a root node > without a document. Please note, however, that your second argument is > simply the name and path of your document, and does not read any > input.
Ah, so I would better use
db:create('annotate-$name', <root/>, 'annotate-$name.xml')
Somehow it is not clear from the Wiki, I thought I had to use an existing document with some data in it. So this document does not have to exist before?
Quoted text · Christian Grün · 10 lines
>> How do I set UPDINDEX ON for the new DB? > > The following lines should do what you need: > > declare option db:ftindex "on"; > declare option db:updindex "on"; > db:create('annotate', <root/>, 'root.xml') > > If you activate the FTINDEX option before creating a database, the > OPTIMIZE call will always create/update your full-text index.
Ah, I will try this.
Quoted text · Christian Grün · 4 lines
>> To be able to use ft:mark, I would have to optimize the DB with db:optimize() after having added nodes, is this correct? > > ft:mark() also works without full-text index, but the index solution > is usually faster.
OK, since some of the DBs will have more than 400 entries, it is save to always optimize the index after updating. Thanks and best regards Cerstin
-- Dr. phil. Cerstin Mahlow Universität Basel Departement Sprach- und Literaturwissenschaften Fachbereich Deutsche Sprach- und Literaturwissenschaft 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
CG
Christian Grün18 Mar 2013 23:42 #
Quoted text · Cerstin Elisabeth Mahlow · 1 line
> Somehow it is not clear from the Wiki, I thought I had to use an existing document with some data in it. So this document does not have to exist before?
Good to know. Edits in our Wiki are always welcome! ;) Thanks, Christian
CM
Cerstin Elisabeth Mahlow18 Mar 2013 23:47 #
Am 18.03.2013 um 23:42 schrieb Christian Grün <christian.gruen at gmail.com> :
Quoted text · Christian Grün · 3 lines
>> Somehow it is not clear from the Wiki, I thought I had to use an existing document with some data in it. So this document does not have to exist before? > > Good to know. Edits in our Wiki are always welcome! ;)
And my assumption isn't true: The document has to exist, I cannot specify a non-existing document, i.e., a document I maybe would like to produce later as an export of the DB. What I don't understand: Why do I have to specify a document when the content is not used? All I need is a fresh DB which I fill with "data" that maybe later will form a document. So I stick with the /dev/null solution. It looks odd, but it works :) Best regards Cerstin
-- Dr. phil. Cerstin Mahlow Universität Basel Departement Sprach- und Literaturwissenschaften Fachbereich Deutsche Sprach- und Literaturwissenschaft 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
CG
Christian Grün18 Mar 2013 23:53 #
Quoted text · Cerstin Elisabeth Mahlow · 1 line
> And my assumption isn't true: The document has to exist, I cannot specify a non-existing document, i.e., a document I maybe would like to produce later as an export of the DB.
This sounds surprising to me, as I don’t get any errors when running e.g. the following command.. basex "db:create('db', <root/>, 'doesnotexist.xml')" How does your command call look like? Christian
CM
Cerstin Elisabeth Mahlow21 Mar 2013 16:59 #
Hi Christian,
Quoted text · Christian Grün · 9 lines
Am 18.03.2013 um 23:53 schrieb Christian Grün <christian.gruen at gmail.com>: >> And my assumption isn't true: The document has to exist, I cannot specify a non-existing document, i.e., a document I maybe would like to produce later as an export of the DB. > > This sounds surprising to me, as I don’t get any errors when running > e.g. the following command.. > > basex "db:create('db', <root/>, 'doesnotexist.xml')" > > How does your command call look like?
It's in the cgi and it looks like this:
$session->execute("xquery declare option db:ftindex 'on'; declare option db:updindex 'on'; db:create('annotate-$phraseme', <root/>, 'annotate-$phraseme.xml')");

$phraseme holds the ID to be used.
But it's funny, it works today without error, but it didn't work two days ago. And I did not install any updates. So it fixed itself, thanks! Cerstin
-- Dr. phil. Cerstin Mahlow Universität Basel Departement Sprach- und Literaturwissenschaften Fachbereich Deutsche Sprach- und Literaturwissenschaft 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

⚡Generated with XQuery