Optimized query for importing content based on metadata

Friday, 19 October 2018 · 3 messages · last reply 22 Oct 2018
JD
Jason Davis19 Oct 2018 23:01 #
Hi, I’ve cobbled together a query that I want to use to import xml from the filesystem into the database based on specific metadata requirements:
let $xmlroot := "/Users/jason.davis/Sandbox/dita-docs/content/"
   for $file in file:list($xmlroot, true())
   where matches($file, 'xml') or matches($file, 'ditamap')
   let $doc := file:resolve-path($file, $xmlroot)
   return if (doc($doc)//brand[contains(.,'xyz')])
   then db:add("d4st^dita-docs^meta-test",  $doc)
   else ()
It works, so I’m pleased! I’m just wondering if there is a more efficient way to achieve what I want to do. I know that using a specific XPath in the doc function is one thing I can do better. Any suggestions are appreciated! Thanks, Jason
CG
Christian Grün19 Oct 2018 23:26 #
Hi Jason, My version would have looked pretty similar:
  let $xmlroot := '/Users/jason.davis/Sandbox/dita-docs/content/'
  for $path in file:list($xmlroot, true())
  where matches($path, '\.(xml|ditamap)$')
  let $doc := doc($xmlroot || $path)
  where $doc//brand[contains(., 'xyz')]
  return db:add('d4st^dita-docs^meta-test', $doc, $path)
If you have already openen the document, you can directly pass it on to db:add. Cheers, Christian
Quoted text · Jason Davis · 19 lines
On Fri, Oct 19, 2018 at 11:01 PM Jason Davis <jason.davis at hortonworks.com> wrote: > > Hi, > > I’ve cobbled together a query that I want to use to import xml from the filesystem into the database based on specific metadata requirements: > > let $xmlroot := "/Users/jason.davis/Sandbox/dita-docs/content/" > for $file in file:list($xmlroot, true()) > where matches($file, 'xml') or matches($file, 'ditamap') > let $doc := file:resolve-path($file, $xmlroot) > return if (doc($doc)//brand[contains(.,'xyz')]) > then db:add("d4st^dita-docs^meta-test", $doc) > else () > > It works, so I’m pleased! I’m just wondering if there is a more efficient way to achieve what I want to do. I know that using a specific XPath in the doc function is one thing I can do better. Any suggestions are appreciated! > > Thanks, > Jason
JD
Jason Davis22 Oct 2018 16:53 #
Thanks Christian! I appreciate the touch-up and the insight. Jason
Quoted text · Christian Grün · 1 line
On 10/19/18, 2:26 PM, "Christian Grün" <christian.gruen at gmail.com> wrote:
Hi Jason, My version would have looked pretty similar:
      let $xmlroot := '/Users/jason.davis/Sandbox/dita-docs/content/'
      for $path in file:list($xmlroot, true())
      where matches($path, '\.(xml|ditamap)$')
      let $doc := doc($xmlroot || $path)
      where $doc//brand[contains(., 'xyz')]
      return db:add('d4st^dita-docs^meta-test', $doc, $path)
If you have already openen the document, you can directly pass it on to db:add. Cheers, Christian On Fri, Oct 19, 2018 at 11:01 PM Jason Davis
Quoted text · Christian Grün · 18 lines
<jason.davis at hortonworks.com> wrote: > > Hi, > > I’ve cobbled together a query that I want to use to import xml from the filesystem into the database based on specific metadata requirements: > > let $xmlroot := "/Users/jason.davis/Sandbox/dita-docs/content/" > for $file in file:list($xmlroot, true()) > where matches($file, 'xml') or matches($file, 'ditamap') > let $doc := file:resolve-path($file, $xmlroot) > return if (doc($doc)//brand[contains(.,'xyz')]) > then db:add("d4st^dita-docs^meta-test", $doc) > else () > > It works, so I’m pleased! I’m just wondering if there is a more efficient way to achieve what I want to do. I know that using a specific XPath in the doc function is one thing I can do better. Any suggestions are appreciated! > > Thanks, > Jason

⚡Generated with XQuery