Allow selective deep search for references.

This patch allows client traversals to call the set_deep_search(bool) method to
indicate whether references in child loops are to be extracted as well.