Fix a bug in duplicate detection
This is caused by AppEngine's inability to sort a query when the
inequality or IN operator is used. See also [0].
[0] http://code.google.com/p/googleappengine/issues/detail?id=1100
Patch by: Sverre Rabbelier and Lennard de Rijk