Hi,
Is there a way to retrieve the parent/ancestor nodes of the full-text search results of a basex database ?
For instance, consider I have a document named 'feed1', 'feed2', 'feed3' in my database.
A sample document ('feed1') looks as follows: <feed> <id>1</id> <updated>2011-02-07T07:10:49.588Z</updated> <title>feed1</title> <entry> <id>59</id> <title>Feed1 Root Package</title> <updated>2011-02-07T07:11:01.324Z</updated> </entry> </feed>
The following xquery: for $doc_name in db:list() return (ft:extract(doc($doc_name)/feed/entry/*[text() contains text 'Root Package']))
outputs the following result as expected : <title>Feed1 <mark>Root</mark> <mark>Package</mark></title>
But, is there a way to retrieve the parent and ancestor nodes of the resulting <title> node, meaning is there a way I can output the 'id' of the entry and 'id' of the feed as well. The desired output could be:
[<title>Feed1 <mark>Root</mark> <mark>Package</mark></title>, <id>59</id>, <id>1</id>].
Thanks, Sony
Hi Sony,
thanks for your concise example. The usual way to do this is to split the process of retrieving the relevant entries and to create the requested result. Your query could be rewritten as follows:
for $doc_name in db:list() for $node in doc($doc_name)/feed/entry/*[text() contains text 'Root Package'] return ( ft:extract($node[text() contains text 'Root Package']), $node/../id, $node/ancestor::feed/id )
The full text expression is now specified twice – which is not critical in terms of performance, but surely not the most elegant way to write queries. This is all due to some internal peculiarities of the XQuery Full Text specs.
Hope this solves your issue, Christian
___________________________
On Mon, Feb 7, 2011 at 7:34 PM, Sony Vijay vsony7@vt.edu wrote:
Hi, Is there a way to retrieve the parent/ancestor nodes of the full-text search results of a basex database ? For instance, consider I have a document named 'feed1', 'feed2', 'feed3' in my database. A sample document ('feed1') looks as follows:
<feed> <id>1</id> <updated>2011-02-07T07:10:49.588Z</updated> <title>feed1</title> <entry> <id>59</id> <title>Feed1 Root Package</title> <updated>2011-02-07T07:11:01.324Z</updated> </entry> </feed> The following xquery: for $doc_name in db:list() return (ft:extract(doc($doc_name)/feed/entry/*[text() contains text 'Root Package'])) outputs the following result as expected : <title>Feed1 <mark>Root</mark> <mark>Package</mark></title> But, is there a way to retrieve the parent and ancestor nodes of the resulting <title> node, meaning is there a way I can output the 'id' of the entry and 'id' of the feed as well. The desired output could be: [<title>Feed1 <mark>Root</mark> <mark>Package</mark></title>, <id>59</id>, <id>1</id>]. Thanks, Sony
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
basex-talk@mailman.uni-konstanz.de