Inside updateSearchResult I stuff the techs into a temporary table before iterating over them, sort them according to the same effort function used to select next tech, and then iterate over that sorted table:
<...>
-- NOTICE: localised name matching does not work at present, pending unlikely changes to Factorio API
techs = {}
for name, tech in pairs(player.force.technologies) do
table.insert(techs, {name, tech})
end
sortTechsByEffort(techs, config)
for _, namedTech in pairs(techs) do
<...>
function sortTechsByEffort(techs, config)
local compare = function(a, b)
print(a)
return calcEffort(a[2], config) < calcEffort(b[2], config)
end
table.sort(techs, compare)
return
end
There are probably more idiomatic ways to do this, but it didn't require me to replicate the internal game sorting logic.