Hi Godmar I would think of two level query in style
for $doc in collection() where (there is at least one match) return (**now second for found item return particular finding**)
Another trick would be using group by
for $finding in **find all the findings using your matching criteria** let $doc := **¨find document name of the finding** group by $doc return <doc-group> (for $f in $finding return <finding>{$f}</finding>) </doc-group>
I second approach I am not sure about efficiency at finding parent document, give it a try and see. Note: do not be surprised by a strange reuse of $finding: inside of return of group by it contains all the elements belonging to one group. See http://docs.basex.org/wiki/XQuery_3.0
With best regards
Jan
2011/4/22 Godmar Back godmar@gmail.com
Jan,
we know how to iterate over the results of a query.
The problem is identifying the boundaries in the results.
In Sony's example, the results will be of the structure (A, B, C, D1, D2, D3, D4 ....., A*, B*, C*, D*1, D*2, D*3, ....)
We don't know how many 'D' there will be before the next A. '.next()' on a query returns a String, making it impossible to distinguish Dn from A*. Plus, it's not clear how to write this query.
But it seems that identifying nodes whose descendants match a fulltext pattern, along with all text extracts, ought to be a common task that should be written in a single query, rather than two.
- Godmar
On Fri, Apr 22, 2011 at 1:41 AM, Jan Vlčinský (CAD) jan.vlcinsky@cad-programs.com wrote:
Hi Sony I think, your need can be easily fulfilled. For example I use following XQuery as sort of "dir" command. for $doc in collection() return base-uri($doc) Just do your task the same way, add your where condition and modify the return statement and you are done. And if you use some API to get the results, there are options to get back particular parts of the response part by part, see http://docs.basex.org/wiki/Language_Bindings and refer to examples 3
and
4:
QueryExample shows you how to evaluate queries in an iterative manner. QueryBindExample shows you how to bind a variable to your query and evaluates the query in an iterative manner.
Good luck Jan 2011/4/22 Sony Vijay sony.vibh@gmail.com
Hi, Is there a way to return variable-length results using xquery ? Consider the following xml file (document name: doc1)
<feed> <title>feed1</title> <entry> <id>1</id> <title>entry 1 title match</title> <content>entry 1 content match </content> </entry> <entry> <id>2</id> <title>entry 2 title match</title> <content>entry 2 content match </content> <author> <name>entry 2 author match </name> </author> </entry> </feed> Consider that there are multiple xml files in my database. I am trying
to
run an xquery which would perform a search across all the xml files in
the
database which contain entires with the matching key. Then for each
matching
document, return all the entry nodes with at least one match, followed
by a
list of nodes with the match. Say the match key word is: "match", the desired result is the following:
document name (doc1), id (1), [title (entry 1 title match), content
(entry
1 content match)], document name(doc1), id (2), [title (entry 2 title match), content (entry 2 content match), author: name (entry 2 author match)]
Please note that the first entry(id=1) contains two matching nodes
whereas
the second entry(id=2) contains 3 matching nodes. Returning a variable length result as shown above would help me identify the next matching document name and entry id. Currently, I perform this action by splitting the task into 2 sub-tasks:
Return the document name and entry id with at least one match using one xquery Return the list of matching child nodes for each of the above entries using a second xquery
Is there a better way to do this? Thanks, Sony
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk
-- Ing. Jan Vlčinský CAD programy Slunečnicová 338/3, 734 01 Karviná Ráj, Czech Republic tel: +420-597 602 024; mob: +420-608 979 040 skype: janvlcinsky; GoogleTalk: jan.vlcinsky@gmail.com http://cz.linkedin.com/in/vlcinsky
BaseX-Talk mailing list BaseX-Talk@mailman.uni-konstanz.de https://mailman.uni-konstanz.de/mailman/listinfo/basex-talk