DETROIT, Maine — The two-week search for a little white dog that ran away as she and her owner were arriving at a grooming appointment in Detroit ended on a happy note Friday, when she approached railroad workers who had heard she was missing.

The rail employees contacted Pittsfield police, who picked up Bonnie, a 9-year-old West Highland white terrier. The workers delivered Bonnie to where her two-week trek began, according to Beverly Buker, whose 90-year-old mother, Pearl Jones, owns Bonnie.

Despite being tired and in badly need of a bath and haircut, Bonnie otherwise was none the worse for wear. She even gained almost two pounds during her two weeks on the lam, Buker said. She said Westies are bred to hunt and that Bonnie likely ate mice and other small critters to survive.

More than 50 ticks were removed from Bonnie and many more washed down the drain, but the pooch has been vaccinated for Lyme disease.

“It’s a miracle because we didn’t think we’d ever get her back. I’ll tell you, people went above and beyond to help. Even people we didn’t know,” Buker said.

Jones lived in St. Albans until recently moving to an assisted living facility in Portland, Buker said. She was elated to learn Bonnie was back.

Bonnie had been missing since May 11, when she last was seen running into a 500-acre bog in the woods near Dog’s Paradise, a pet grooming business operated by Melissa and Ed Buzzell on River Road in Detroit.

Buker, the Buzzells and family and friends worried Bonnie was either injured, stuck or otherwise unable to make it out of the woods on her own and so the search began.

For up to a week after Bonnie ran away, searchers believed Bonnie was still in the woods because they could hear her barks from off in the distance. Efforts to retrieve her were hindered, in part, by the boggy terrain and large wild animals.

At that point, family and friends of Bonnie’s owner contacted Down East Emergency Medicine Institute, an Orono-based volunteer search and rescue group.

DEEMI lent its drone, which is equipped with high-resolution and infrared imaging technology, and the drone’s pilot, member Vinal Applebee to the effort, as well as a similarly equipped fixed wing aircraft that flew over the area while en route to another mission.

Richard Bowie, DEEMI’s operations director, said the missing dog case provided training opportunities for its volunteer members.

The drone had been used in several missing person cases in the region, but until the search for Bonnie had not been used in an animal rescue.

DEEMI, however, had to suspend its efforts after three days, after the dog’s barks could no longer be heard and were unable to find any trace of her.

Buker said she and others believe that Bonnie made her way out of the bog to a cleared utility line easement that in turn led to railroad tracks off Route 100 near Pittsfield.

She said Bonnie was spotted getting into the garbage at a residence along Route 100 but that she was gone by the time she and others arrived about 15 minutes later and by then, the rain had washed away the pooch’s footprints.

Buker estimated that Bonnie traveled four to five miles during her trek.