Inist-CNRS/node-sphinxapi

SetGeoAnchor does not work.

Closed this issue · 5 comments

I use this code below:

client.SetGeoAnchor('dep_latitude', 'dep_longitude', 0.21, 0.2);

then sphinxd reports:
query error: index rt: unknown latitude attribute ''

rt index informations:
mysql> desc rt;

+---------------------+-----------+
| Field               | Type      |
+---------------------+-----------+
| id                  | integer   |
| nickname            | field     |
| sponsor             | field     |
| departure           | field     |
| destination         | field     |
| remark              | field     |
| dep_geohash         | field     |
| dest_geohash        | field     |
| event_mode          | uint      |
| sponsor_code        | uint      |
| event_sub_type_code | uint      |
| car_type            | uint      |
| gender              | uint      |
| source              | uint      |
| dep_longitude       | float     |
| dep_latitude        | float     |
| dest_longitude      | float     |
| dest_latitude       | float     |
| start_time          | timestamp |
| update_time         | timestamp |
+---------------------+-----------+
20 rows in set (0.31 sec)

I use SphinxSE:

select * from sphinx where query = 'select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23);'

it works well.

SphinxSE result:

mysql> select * from sphinx where query = 'select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23);';
+-----+--------+---------------------------------------------------------------------------------+----------+
| id  | weight | query                                                                           | distance |
+-----+--------+---------------------------------------------------------------------------------+----------+
| 468 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9398689 |
| 477 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9398696 |
| 478 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9398696 |
| 480 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9399440 |
| 490 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9388416 |
| 496 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9388416 |
| 524 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9399180 |
| 596 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9361148 |
| 621 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9389579 |
| 624 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9401976 |
| 649 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9385772 |
| 664 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9398688 |
| 674 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9392441 |
| 677 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9393216 |
| 678 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9393216 |
| 686 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  8047119 |
| 781 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9388171 |
| 789 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9393443 |
| 796 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9398717 |
| 812 |      1 | select=@geodist as distance;geoanchor=dep_latitude, dep_longitude, 0.65, 0.23); |  9398709 |
+-----+--------+---------------------------------------------------------------------------------+----------+
20 rows in set (0.01 sec)
touv commented

Is there the same problem with another client API (python, php) ?
I reviewed the source code and I haven't seen anything strange. As you can see below, the code looks same at the official client.

https://code.google.com/p/sphinxsearch/source/browse/trunk/api/sphinxapi.py#635

https://github.com/touv/node-sphinxapi/blob/master/lib/sphinxapi.js#L576

I'll try later.

Is there a fix for this?

Fixed it by changing lines 578 & 579 of sphinxapi.js to:
req.push(pack('>L', [len(self._anchor.attrlat)]) + self._anchor.attrlat)
req.push(pack('>L', [len(self._anchor.attrlong)]) + self._anchor.attrlong)