Once upon an algorithm, a widower in San Francisco who was an expert in online consumer behavior took to the internet to find the one.

“I was still hurting,” said Bill Tancer, whose wife of 17 years had succumbed to complications of breast cancer in July 2014. “But I felt it was time to put myself out there and start dating again.”

Mr. Tancer did exactly that in January 2015, when he created a dating profile and sent it to eHarmony. He fully expected to receive numerous matches, wishing to find among them a woman who could potentially become, as he put it, “my one and only.”

But Mr. Tancer, then 48, received a reply that seemed to come not from an algorithm in a search engine, but from a genie in a bottle. He was granted exactly what he had wished for: one match, and one match only, an improbable result that brought to his screen the profile of Erika Holiday, a 38-year-old forensic psychologist and adjunct professor of psychology at the University of Southern California, some 300 miles away.