Hi,
I’m a Silverbullet beginner with no lua experience, trying to create an lua script that will give me a list of the most common tags, but I can’t get the sort function to work.
The function I wrote so far is below (I haven’t done the formatting of the output yet). However, the sort function does not seem to change the order at all and it doesn’t seem to give an error either.
function countTags()
-- Count tags
local pageTags = {}
for tag in query[[from index.tag 'tag']] do
if not pageTags[tag.name] then
pageTags[tag.name] = 1
else
pageTags[tag.name] = pageTags[tag.name] + 1
end
end
table.sort(pageTags, function(a, b) return a.value < b.value end)
return pageTags
This doesn’t sort the table at all.
I’ve tried to sort only the values in the table, which kind of works, but it sorts them as strings (so 11 comes before 2)
local v = {}
for tag, count in pairs(pageTags) do
table.insert(v, count)
end
table.sort(v)
return v
Appreciate if you can give me some pointers on how I can get my table sorted numerically.
Tnx,
Mike