You were right, I did some more testing and it's actually the accessing the name of each container (folder) that's taking up time. Currently I'm doing it as
set noteRefs to a reference to every note in default account
set containers to container of noteRefs
(inside the loop:) name of item i of containers
So to make it fast I probably need to deal with references of the containers instead of the containers themselves, but I'm not sure how the syntax for that looks. For me the whole thing runs in less than 0.1 seconds without containers, and 2 seconds with them.
Good point, I forgot about that. I henceforth ban unusual characters in note titles! I didn't know about JXA though, I'll look into it.
Glad you like it. I poked around and couldn't easily find the note text in the SQL database. It might be easier to get with the AppleScript methods, but it wasn't immediately working for me, probably because they're stored in HTML and we want them as a string. I will try to look into it further. I'm happy to include searching the body too as an option, but I made it search titles only for now because I like the more specific search scope.