Improving search speed #54
-
Hi, I am an amateur Python coder so apologies in advance if I missed something obvious. I am trying to create a python function where with a given keywords string, it returns the list of matching Apple notes. Here's the code:
Now this function works perfectly as intended, but it's just quite slow. On my latest Mac mini it takes 5 second to find that one note matching the two words out of some 100 notes which is barely massive. Is there any way I could speed this up? The target note always live in a folder called "Work" but there does not seem to be a way for me to look only in this folder. Look forward to any suggestion and thanks for this impressive piece of work! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Actually don't worry it turns out that I was an idiot:
I am happy to just call it [0] as there is usually one and only result. |
Beta Was this translation helpful? Give feedback.
macnotesapp relies on the AppleScript interface to interact with Notes and this is very slow (and in some cases buggy which macnotesapp jhas to work around). Your code requires searching through every single note which means that each note has to be retrieved via the very slow AppleScript interface. As you noted in the second post, the solution is to use
noteslist()
which does the search in Notes before returning the AppleScript objects. This for example, returns the IDs of all notes whose text (body or name) matches "keyword"). This is much faster though it's still not as fast as I'd like. TheNotesList
properties return a list of all matching notes.