Accessing and using paths in database

Friday, 4 November 2016 · 2 messages · last reply 8 Nov 2016
BD
Bridger Dyson-Smith4 Nov 2016 18:37 #

Hi all,

I've been looking through the documentation but not seeing (probably overlooking!) something on accessing paths in a database.

If I create a db from the following directory structure:

top-level/ dir-a/ sub-1/ file.xml sub-2/ file.xml dir-b/ sub-1/ file.xml sub-2/ file.xml dir-c/ ...etc... ...etc...

is there a way to selectively process based on the path top-level/dir-a? I've been attempting some things along the following:

for $doc in fn:collection('test-db')
return switch(db:path($doc))
                case fn:matches(.,'dir-a') return <something/>
                detault case <something-else/>

but db:path returns a sequence. I've also tried something similar with $paths in db:open('test-db', $paths) but have had some difficulties with that as well.

I've noticed a section on the Document Index [1], but I'm not sure how to access it.

Honestly, I'm not sure if that's even the best approach to handling the vague idea I have bouncing around in my head. From a "large" database with many paths, I'd like to be able to selectively apply certain queries to some and other queries to the remainder.

I hope that makes some sense. Thank you in advance for any pointers. Best, Bridger

[1] http://docs.basex.org/wiki/Indexes#Document_Index

CG
Christian Grün8 Nov 2016 08:26 #

Hi Bridger,

Sorry for letting you wait.

Quoted text · Bridger Dyson-Smith · 1 line
> is there a way to selectively process based on the path `top-level/dir-a`?

This should work (as long as you have a static path pattern):

  db:open('test-db', 'top-level/dir-a')
  collection('test-db/top-level/dir-a')
Quoted text · Bridger Dyson-Smith · 6 lines
> for $doc in fn:collection('test-db') > return switch(db:path($doc)) > case fn:matches(.,'dir-a') return <something/> > detault case <something-else/> > > but db:path returns a sequence.

Are you sure? This would be a bug then (the function is expected to always return a single string). Do you have a little example?

Cheers, Christian


⚡Generated with XQuery