Fix for has_child can cause an infinite loop (100% CPU) when used in bool query.

Closes #3955