Quick Q: search methods in anki pylib

Apologies if this is the wrong place for this but hoping someone could point me in the right direction as I’ve absolutely hit a wall with a sortof niche use case. I had a few python scripts for 2.0 that leaned heavily on being able to find cards with effectively the same sort of query string you’d use in the gui browser ie:

col.findNotes("note:Note Name")

Attempting to update these, I’ve gotten things set up via installing anki with pip but even after reading the source I cannot figure out how searching works now, it is somewhat over my head. Possibly these methods now expect a SearchNode object or certain arguments?

Or is the problem more that I’m not escaping spaces in some way? I’ve tried:

col.find_notes("note:Note Name")

returns empty list

col.find_notes("StringWithNoSpaces")

returns some cids but doesn’t match the old field:searchstring functionality. Any easy way to go here? Many thanks for any help.

The search API changed quite a bit internally but find_notes should work as expected with a string argument.

If your note type name has spaces in it, you should enclose it in double quotes (e.g. note:"My Note Type" Name)

Note that searching in a field (field:something) requires an exact match, unlike the simple something search, and the two methods differ in important ways. See the relevant manual section
Anki Manual and the notes above that section.

1 Like

Thanks, with your advice it now works similar to how it used to, using:

col.find_notes('note:"Note Name"')

Could have sworn I’d tried that but must have been tripped up by the string within a string. Thanks again for your help.