Custom order of values

Exist there any way to define a custom order for a value in a query? I try to create a index for my study notes with the following query and template.

templates.studyIndex = template.new([==[
${(string.match(note_type, 'semester_overview') and '*') or ((string.match(note_type, 'module_overview') and '  *') or '    *')} [[${name}]]
]==])
${template.each(query[[from index.tag "study" order by semester desc, module desc, note_type desc]], templates.studyIndex)}

My problem is that my note_types are not in an alphabetic order. I have semester_overvew, module_overview, lecture_notes and project_notes and need to get that orderd in this order to get my index work. At the moment project_notes are over the module_overview. Is there a way to reach this?

If you need to custom sorting, what you can do is use Lua’s table.sort: Lua 5.4 Reference Manual

${table.sort(query[[from index.tag "study"]], function(a, b)
  -- your custom sort logic here
  return a - b
end)}
1 Like