Query Help: lines tagged with a specific value

I would like to create a query that scans all of my pages list any lines (not pages) with a specific tag value, for instance 'shopping'...

possible?

Is this what you want?

${query [[
  from p = index.paragraphs()
  where p.itags and table.includes(p.itags, "shopping")
  select { Page = "[[" .. p.page .. "]]", Line = p.text }
]]}


test #shopping

Thanks - yes. Will this also pick up any tagged tasks?

No, but you can do the following

${combineTables(query [[
  from p = index.paragraphs()
  where p.itags and table.includes(p.itags, "shopping")
  select { Page = "[[" .. p.page .. "]]", Line = p.text }
]],
query [[
  from p = index.tasks()
  where p.itags and table.includes(p.itags, "shopping")
  select { Page = "[[" .. p.page .. "]]", Line = p.text }
]])
}

This requires the following space-lua

function combineTables(table1, table2)
  local result = table1
  for _, v in ipairs(table2) do
    table.insert(result,v)
  end
  return result
end

You can put space-lua for combineTables anywhere in your space. I recommend putting it somewhere like "Library/Custom/CombineTables" and tagging it with #meta. Remember to run a system reload in command-palette after adding the space-lua.

Perfect! Thanks so much.

@zef Hi. Just wondering if there is a reason not to do combineTables with tables or if it should be included in Std-library? Something like table.union? Or is there a way to do this with what is there today in Std-library?

I think there's no off-the-shelf API to do this now, no. I try to stick to the Lua standard API as much as possible and not add too much, although adding table.union, even as a non-standard API would be useful...