searchEntitiesByText(): use array_filter()

Changing an array inside its foreach() is asking for trouble.