Spatial search with sort by distance and paging orders entities incorrectly and repeats them

Description

Spatial search with sort by distance and paging orders entities incorrectly and repeats them.

Same problem using SpatialMode.RANGE and GRID.

Example output from unit test (page size = 5):

index / distance / entity id:
0 1,854654 46
1 2,476669 11
2 3,628696 14
3 3,986162 1
4 9,840840 48 wrong order

5 6,909802 44
6 8,288416 13
7 8,673849 9
8 8,891801 6
9 9,840840 48 was at index 4, wrong order

10 13,790553 17
11 14,801496 5
12 14,959930 2
13 15,407163 21
14 16,545712 10

15 14,801496 5 was at index 11
16 14,959930 2 was at index 12
17 15,407163 21 was at index 13
18 16,545712 10 was at index 14
19 16,622222 18

20 14,972440 39
21 15,407163 21 was at index 13
22 16,028147 31
23 16,545712 10 was at index 14
24 16,622222 18 was at index 19

25 16,622222 18 was at index 19
26 16,652192 20
27 17,444358 33
28 18,885611 7
29 19,359880 35

30 16,652192 20 was at index 26
31 17,444358 33 was at index 27
32 18,885611 7 was at index 28
33 19,359880 35 was at index 29
34 19,391599 26

35 19,559055 22
36 19,968307 45

Environment

Java 7u11 x64
HibernateSearch 4.2
PostgreSQL 9.1 / H2

Status

Assignee

Nicolas Helleringer

Reporter

Piotr B.

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Fix versions

Affects versions

4.2.0.Final

Priority

Major