Including the "doc" information in the RETURN clause

Wednesday, 2 February 2011 · 5 messages · last reply 3 Feb 2011
DL
David leigh2 Feb 2011 22:47 #
I may be doing this completely wrong to begin with, so try not to be too shocked at my examples! ;c) My BaseX database consists of songs. They were loaded from individual XML files that are stored in a directory structure. I'm searching for songs that contain given lyrics. So far so good. I'm NOT returning XML format data, but tabular data. I'm using the "return" clause with the concat() function of XQuery to formulate each results row. For instance "song title", "author", "lyrics", etc. One row per song that is found from my search. What I'd like to be able to do is to have that results row also contain the information in the "doc" node so that in addition to selected contents of the XML file, the results row would also contain the file name and the relative directory path (which I see are in the "doc" node when I use the BaseX GUI). Here's a real-life example of a query that works well for me to return rows of elements found WITHIN the XML file:
for $song in collection("OpenSongSearch")

where $song/song/lyrics[ . contains text  "baloche"] or $song/song/title[ .
contains text  "baloche"]  or $song/song/author[ . contains text  "baloche"]
order by $song/song/title
return
concat($song/song/title,string('|'),$song/song/author,string('|'),replace(re
place($song/song/lyrics,'\n','^line^'),'\[\w+\]',''),string('
'))
The program that invokes the BaseX call parses these results to put into a listbox in a dialog. The only thing that I knew to try to add the "doc" node was:
return concat($song/doc,string('|'),
$song/song/title,string('|'),$song/song/author,string('|'),replace(replace($
song/song/lyrics,'\n','^line^'),'\[\w+\]',''),string('
'))
This did not give me an error but simply added the additional vertical bar at the beginning and no "doc" node info. I know this is more of a XQuery question than a BaseX question per se, but any hints for novice would be greatly appreciated. Thanks!
 <mailto:david at leighweb.com> DavidEmailSig
DL
David leigh2 Feb 2011 23:25 #
Ok, I got it figured out from this page: http://docs.basex.org/wiki/Database_%26_Collection. So, in my return concat, I need to use the "base-uri" of $song to get the actual file path. So, my query will look something like:
for $song in collection("OpenSongSearch")

where $song/song/lyrics[ . contains text  "baloche"] or $song/song/title[ .
contains text  "baloche"]  or $song/song/author[ . contains text  "baloche"]
order by $song/song/title
return concat(base-uri($song),string('|'),
$song/song/title,string('|'),$song/song/author,string('|'),replace(replace($
song/song/lyrics,'\n','^line^'),'\[\w+\]',''),string('&#10;'))
Yep, that works! Sorry to bug you all with a question that's documented! Are there other options than base-uri? For instance, base-uri has the file name. Is there a function like that with just the path but not the file name? If not, I can certainly work with base-uri. (I couldn't find any, but thought I'd ask) Thanks!
CG
Christian Grün3 Feb 2011 12:52 #
Hi David,
Quoted text · David leigh · 4 lines
> Are there other options than base-uri? For instance, base-uri has the file > name. Is there a function like that with just the path but not the file > name? If not, I can certainly work with base-uri. (I couldn’t find any, > but thought I’d ask)
base-uri() and document-uri() will always return the full path. You might want to check out the BaseX specific function db:info(), which gives you general database information, including the original collection path (but this is probably not what you are looking for): http://docs.basex.org/wiki/Database_Functions#db:info Christian
Quoted text · David leigh · 35 lines
> Ok, I got it figured out from this page: > http://docs.basex.org/wiki/Database_%26_Collection. So, in my return concat, > I need to use the “base-uri” of $song to get the actual file path. So, my > query will look something like: > > for $song in collection("OpenSongSearch") > > where $song/song/lyrics[ . contains text "baloche"] or $song/song/title[ . > contains text "baloche"] or $song/song/author[ . contains text "baloche"] > > order by $song/song/title > return concat(base-uri($song),string('|'), > $song/song/title,string('|'),$song/song/author,string('|'),replace(replace($song/song/lyrics,'\n','^line^'),'\[\w+\]',''),string('&#10;')) > > > > Yep, that works! Sorry to bug you all with a question that’s documented! > > > Thanks! > > > > > > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
DL
David leigh3 Feb 2011 13:19 #
I use the "info db" already to get the number of documents and the root path of the collection is something my calling program already has. So it's really what's in base-uri that interests me. So document-uri is identical to base-uri? Thanks!
Quoted text · Christian Grün · 59 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: Thursday, February 03, 2011 12:53 PM To: david at leighweb.com Cc: basex-talk at mailman.uni-konstanz.de Subject: Re: [basex-talk] Including the "doc" information in the RETURN clause Hi David, > Are there other options than base-uri? For instance, base-uri has the file > name. Is there a function like that with just the path but not the file > name? If not, I can certainly work with base-uri. (I couldnt find any, > but thought Id ask) base-uri() and document-uri() will always return the full path. You might want to check out the BaseX specific function db:info(), which gives you general database information, including the original collection path (but this is probably not what you are looking for): http://docs.basex.org/wiki/Database_Functions#db:info Christian > Ok, I got it figured out from this page: > http://docs.basex.org/wiki/Database_%26_Collection. So, in my return concat, > I need to use the base-uri of $song to get the actual file path. So, my > query will look something like: > > for $song in collection("OpenSongSearch") > > where $song/song/lyrics[ . contains text "baloche"] or $song/song/title[ . > contains text "baloche"] or $song/song/author[ . contains text "baloche"] > > order by $song/song/title > return concat(base-uri($song),string('|'), > $song/song/title,string('|'),$song/song/author,string('|'),replace(replace($ song/song/lyrics,'\n','^line^'),'\[\w+\]',''),string('&#10;')) > > > > Yep, that works! Sorry to bug you all with a question thats documented! > > > Thanks! > > > > > > > > > > _______________________________________________ > BaseX-Talk mailing list > BaseX-Talk at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
CG
Christian Grün3 Feb 2011 13:51 #
Quoted text · David leigh · 2 lines
> So document-uri is identical to base-uri? > Thanks!
It's very similar. The most notable difference is that base-uri() kann also be applied to non-document nodes. Hope this helps, Christian

⚡Generated with XQuery