How do I execute SearchQuery using JXA?

If suppose I want to use JXA search my entire database for all records containing the phrase “John Doe” or all records containing “Doe, John” in the Name.

I can certainly set up a loop to iterate through the entire database but I suspect that will not take advantage of DT3’s indexes and thus will be slow.

In the scripting dictionary I see that SearchQuery is a property of a window, not a method. So I am not sure how that would work within a script when I do not want it to open up a window.

Can someone give me the basic outline how to set up via JXA a script which can accept an arbitrary search query in the same format as I would do any query in the regular DT3 UI?

See search command.

OK that works- thank you