Retrieving the parent nodes of full-text search results

Monday, 7 February 2011 · 2 messages
CG
Christian Grünin reply to Sony Vijay, 7 Feb 2011, 21:037 Feb 2011 20:21 #
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
Quoted text · Sony Vijay · 40 lines
On Mon, Feb 7, 2011 at 7:34 PM, Sony Vijay <vsony7 at 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 at mailman.uni-konstanz.de > https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk > >
SV
Sony Vijay7 Feb 2011 21:03 #
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

⚡Generated with XQuery