Hi, Apologies if this is a very simple question and/or not in the right place. I’m loving playing with the v2 SB and I’m already making a lot of progress but I’m stuck with something.
I have a query where I can pull all the pages tagged with ‘japan’ and ‘phrases’ and display them as a nice table. (1) below.
I have a query where I can pull all the pages tagged with ‘japan’ and ‘phrases’ and make the names clickable links. (2) below.
But I can’t figure out how to write a query where I can have a nice table AND make the names clickable links and I’m looking for a bit of help. I reckon I’m 90% there (probably) but can’t make the last 10%.
Thanks,
Nick.
(1)
${query[[
from p = index.tag "japan" and index.tag "phrases"
order by p.name
select {
Name = p.name,
Description = p.description
}
]]}
(2)
${template.each(query[[
from p = index.tag "japan" and index.tag "phrases"
order by p.name
select {
Name = p.name,
Description = p.description
}
]], template.new[==[
[[${Name}]] ${Description}
]==])}
however, on second thought: What do you want to achieve with this “and” and the second index.tag?
Trying this on my side that just delivers values from the second one…
Aha! You’re a genius. That did it perfectly! Super job.
OK so the ‘and’ and the second index.tag… I’m going to Japan in Oct and so I have a series of notes. Some about ‘phrases’ and some about ‘accommodation’ and some about ‘travel’ - so I want to have 3 separate tables, each about ‘japan’ but obviously also about ‘phrases’, ‘accommodation’, or ‘travel’ in turn. The second and seems to get me that - or at least it does right now.
Hmmm. You’re correct. It seems to just care about the second tag. So how do I do a proper search for BOTH tags (or any arbitrary number of tags)?
In fact, I already had a similar requirement. But I could not figure out a proper way to put something “dynamic” within the queryphrase.
However, I have a workaround for you. Not very elegant or performant, but should solve the problem:
Just run the query multiple times and add all results to a table, like so:
```space-lua
function MyMultiQuery (taglist)
local result = {}
for i, myTag in ipairs(taglist) do
for _,v in ipairs( query[[ from index.tag "page" where table.includes(tags, myTag ) ]] ) do
table.insert(result, v)
end
end
return result
end
```
The expression will look like ${SpecialTestQuery( {"japan", "phrases"} )} for example. However, you could generate the List of tags to search via script, too.