Querying a subset
Hello, I'm using Java org.xmldb.api package for accessing the Basex server (xmldb:basex://...) After getting the resultSet I need to make further queries about the requested subset (for reporting, etc.) I have seen that getId() cannot be used since the Resource will be anonymous if it is obtained as the result of a query. Source: http://xmldb-org.sourceforge.net/xapi/api/index.html
The queries are not fixed and are based on end user selection. I couldn't find a way to have a direct access/reference to a document. In my case the ID is simply the filename, but it doesn't seem to be so efficient. I wonder if creating a temporal collection for the subset would be faster than making query/queries similar to the following example in which there are only two ids, but I can have thousands of them:
let $ids := ('360836','300139')
for $x in collection("collection_name")
let $filename := substring-after(base-uri($x),'/')
let $id := substring-before($filename,'.')
where $id = $ids
return ...And: XQuery has no formal notion of files inside a database/collection http://stackoverflow.com/questions/3363442/refer-to-a-specific-document-in-a-basex-db-using-xquery
With kind regards, Menashè
Quoted text · Menashè Eliezer · 28 lines
On 04/30/2015 02:49 PM, Menashè Eliezer wrote: > Hello, > I'm using Java org.xmldb.api package for accessing the Basex server > (xmldb:basex://...) > After getting the resultSet I need to make further queries about the > requested subset (for reporting, etc.) > I have seen that getId() cannot be used since the Resource will be > anonymous if it is obtained as the result of a query. > Source: http://xmldb-org.sourceforge.net/xapi/api/index.html > > The queries are not fixed and are based on end user selection. > I couldn't find a way to have a direct access/reference to a document. > In my case the ID is simply the filename, but it doesn't seem to be so > efficient. > I wonder if creating a temporal collection for the subset would be > faster than making query/queries similar to the following example in > which there are only two ids, but I can have thousands of them: > > let $ids := ('360836','300139') > for $x in collection("collection_name") > let $filename := substring-after(base-uri($x),'/') > let $id := substring-before($filename,'.') > where $id = $ids > return ... > > -- > With kind regards, > Menashè
Hi Menashé,
If you want to directly address XML nodes of a BaseX database, you can use the db:node-pre/db:open-pre or db:node-id/db:open-id functions. Please have a look at the Wiki for more information [1].
Hope this helps, Christian
[1] http://docs.basex.org/wiki/Database_Module#Read_Operations
Quoted text · Menashè Eliezer · 28 lines
On Thu, Apr 30, 2015 at 2:49 PM, Menashè Eliezer <meliezer at ogs.trieste.it> wrote: > Hello, > I'm using Java org.xmldb.api package for accessing the Basex server > (xmldb:basex://...) > After getting the resultSet I need to make further queries about the > requested subset (for reporting, etc.) > I have seen that getId() cannot be used since the Resource will be anonymous > if it is obtained as the result of a query. > Source: http://xmldb-org.sourceforge.net/xapi/api/index.html > > The queries are not fixed and are based on end user selection. > I couldn't find a way to have a direct access/reference to a document. In my > case the ID is simply the filename, but it doesn't seem to be so efficient. > I wonder if creating a temporal collection for the subset would be faster > than making query/queries similar to the following example in which there > are only two ids, but I can have thousands of them: > > let $ids := ('360836','300139') > for $x in collection("collection_name") > let $filename := substring-after(base-uri($x),'/') > let $id := substring-before($filename,'.') > where $id = $ids > return ... > > -- > With kind regards, > Menashè
Hi Christian,
Thank you for this valuable reply! The following query is really fast. Should I use it also for thousands of possible values instead of creating a temporal collection of the subset?
let $ids := (161,891)
for $x in collection("collection_name")
where db:node-id($x)=$ids
return ...With kind regards, Menashè
Quoted text · Christian Grün · 42 lines
On 04/30/2015 04:55 PM, Christian Grün wrote: > Hi Menashé, > > If you want to directly address XML nodes of a BaseX database, you can > use the db:node-pre/db:open-pre or db:node-id/db:open-id functions. > Please have a look at the Wiki for more information [1]. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Database_Module#Read_Operations > > > > On Thu, Apr 30, 2015 at 2:49 PM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: >> Hello, >> I'm using Java org.xmldb.api package for accessing the Basex server >> (xmldb:basex://...) >> After getting the resultSet I need to make further queries about the >> requested subset (for reporting, etc.) >> I have seen that getId() cannot be used since the Resource will be anonymous >> if it is obtained as the result of a query. >> Source: http://xmldb-org.sourceforge.net/xapi/api/index.html >> >> The queries are not fixed and are based on end user selection. >> I couldn't find a way to have a direct access/reference to a document. In my >> case the ID is simply the filename, but it doesn't seem to be so efficient. >> I wonder if creating a temporal collection for the subset would be faster >> than making query/queries similar to the following example in which there >> are only two ids, but I can have thousands of them: >> >> let $ids := ('360836','300139') >> for $x in collection("collection_name") >> let $filename := substring-after(base-uri($x),'/') >> let $id := substring-before($filename,'.') >> where $id = $ids >> return ... >> >> -- >> With kind regards, >> Menashè
Hi Menashè,
Quoted text · Menashè Eliezer · 1 line
> The following query is really fast.
This should even be faster:
let $ids := (161,891)
for $id in $ids
return db:open-id("collection_name", $id)Quoted text · Menashè Eliezer · 2 lines
> Should I use it also for thousands of > possible values instead of creating a temporal collection of the subset?
If the id approach does what you need, there is probably no need for an additional collection. If you update your data, you may need to use the UPDINDEX flag before creating the database; otherwise, id lookups will be pretty slow.
Best, Christian
Quoted text · Menashè Eliezer · 55 lines
> > let $ids := (161,891) > for $x in collection("collection_name") > where db:node-id($x)=$ids > return ... > > With kind regards, > Menashè > > On 04/30/2015 04:55 PM, Christian Grün wrote: > > Hi Menashé, > > If you want to directly address XML nodes of a BaseX database, you can > use the db:node-pre/db:open-pre or db:node-id/db:open-id functions. > Please have a look at the Wiki for more information [1]. > > Hope this helps, > Christian > > [1] http://docs.basex.org/wiki/Database_Module#Read_Operations > > > > On Thu, Apr 30, 2015 at 2:49 PM, Menashè Eliezer > <meliezer at ogs.trieste.it> wrote: > > Hello, > I'm using Java org.xmldb.api package for accessing the Basex server > (xmldb:basex://...) > After getting the resultSet I need to make further queries about the > requested subset (for reporting, etc.) > I have seen that getId() cannot be used since the Resource will be anonymous > if it is obtained as the result of a query. > Source: http://xmldb-org.sourceforge.net/xapi/api/index.html > > The queries are not fixed and are based on end user selection. > I couldn't find a way to have a direct access/reference to a document. In my > case the ID is simply the filename, but it doesn't seem to be so efficient. > I wonder if creating a temporal collection for the subset would be faster > than making query/queries similar to the following example in which there > are only two ids, but I can have thousands of them: > > let $ids := ('360836','300139') > for $x in collection("collection_name") > let $filename := substring-after(base-uri($x),'/') > let $id := substring-before($filename,'.') > where $id = $ids > return ... > > -- > With kind regards, > Menashè > >
Hi Christian,
Thank you for your valuable help!
With kind regards, Menashè
Quoted text · Christian Grün · 75 lines
On 04/30/2015 06:50 PM, Christian Grün wrote: > Hi Menashè, > >> The following query is really fast. > This should even be faster: > > let $ids := (161,891) > for $id in $ids > return db:open-id("collection_name", $id) > >> Should I use it also for thousands of >> possible values instead of creating a temporal collection of the subset? > If the id approach does what you need, there is probably no need for > an additional collection. If you update your data, you may need to use > the UPDINDEX flag before creating the database; otherwise, id lookups > will be pretty slow. > > Best, > Christian > > >> let $ids := (161,891) >> for $x in collection("collection_name") >> where db:node-id($x)=$ids >> return ... >> >> With kind regards, >> Menashè >> >> On 04/30/2015 04:55 PM, Christian Grün wrote: >> >> Hi Menashé, >> >> If you want to directly address XML nodes of a BaseX database, you can >> use the db:node-pre/db:open-pre or db:node-id/db:open-id functions. >> Please have a look at the Wiki for more information [1]. >> >> Hope this helps, >> Christian >> >> [1] http://docs.basex.org/wiki/Database_Module#Read_Operations >> >> >> >> On Thu, Apr 30, 2015 at 2:49 PM, Menashè Eliezer >> <meliezer at ogs.trieste.it> wrote: >> >> Hello, >> I'm using Java org.xmldb.api package for accessing the Basex server >> (xmldb:basex://...) >> After getting the resultSet I need to make further queries about the >> requested subset (for reporting, etc.) >> I have seen that getId() cannot be used since the Resource will be anonymous >> if it is obtained as the result of a query. >> Source: http://xmldb-org.sourceforge.net/xapi/api/index.html >> >> The queries are not fixed and are based on end user selection. >> I couldn't find a way to have a direct access/reference to a document. In my >> case the ID is simply the filename, but it doesn't seem to be so efficient. >> I wonder if creating a temporal collection for the subset would be faster >> than making query/queries similar to the following example in which there >> are only two ids, but I can have thousands of them: >> >> let $ids := ('360836','300139') >> for $x in collection("collection_name") >> let $filename := substring-after(base-uri($x),'/') >> let $id := substring-before($filename,'.') >> where $id = $ids >> return ... >> >> -- >> With kind regards, >> Menashè >> >>
Written for BaseX 8.1. BaseX may have changed since: please check the current documentation.