import math
USER_LON = 19USER_LAT = 47
def CreateTouple(t): lon = float(t[1].split(',')[0]) lat = float(t[1].split(',')[1]) docid = t[0] return (docid, lon, lat)
'''1. Perform the redisearch query2. Remove the first results which is the number of results3. Put the docid and the location inside a touple4. Create a touple of (docid, lon, lat)5. Create a touple of (distance, docid)6. Sorting by distance7. Run the exection'''GB().\map(lambda x: execute('FT.SEARCH', 'idx', '@test:[19,47,100,km]')).\map(lambda x: x[1:]).\flatmap(lambda x: [(x[i - 1], x[i][1]) for i in range(len(x)) if i % 2 == 1]).\map(CreateTouple).\map(lambda x: (math.sqrt((x[1] - USER_LON)**2 + (x[2] - USER_LAT)**2), x[0])).\sort().\run('idx:idx')
127.0.0.1:6379> FT.CREATE idx SCHEMA test GEOOK127.0.0.1:6379> FT.ADD idx doc1 1.0 FIELDS test "19.05,47.497"OK127.0.0.1:6379> FT.ADD idx doc2 1.0 FIELDS test "19.06,47.498"OK127.0.0.1:6379> FT.ADD idx doc3 1.0 FIELDS test "19.07,47.499"OK127.0.0.1:6379> FT.ADD idx doc4 1.0 FIELDS test "19.02,47.492"OK
python gears.py ClientExample.py [["(0.4924063362711708, 'doc4')", "(0.4995087586819674, 'doc1')", "(0.5016014354046422, 'doc2')", "(0.5038858997828798, 'doc3')"], []]
GEORADIUS vendor-geo -111 33 50 km WITHDIST
FT.SEARCH vendors "@geolocation:[-111.9729275 33.4322451 50 km] WITHDIST" SORTBY distance ASC LIMIT 0 5
--
You received this message because you are subscribed to the Google Groups "RediSearch Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redisearch+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/redisearch/8ba299de-c204-41eb-b666-e0740b5996e7%40googlegroups.com.
127.0.0.1:6379> FT.CREATE idx SCHEMA geo GEO lon NUMERIC NOINDEX lat NUMERIC NOINDEXOK127.0.0.1:6379> FT.ADD idx doc1 1.0 FIELDS geo "19.05,47.497" lon 19.05 lat 47.497OK127.0.0.1:6379> FT.ADD idx doc2 1.0 FIELDS geo "19.06,47.498" lon 19.06 lat 47.498OK127.0.0.1:6379> FT.ADD idx doc3 1.0 FIELDS geo "19.07,47.499" lon 19.07 lat 47.499OK127.0.0.1:6379> FT.ADD idx doc4 1.0 FIELDS geo "19.02,47.492" lon 19.02 lat 47.492OK
127.0.0.1:6379> FT.AGGREGATE idx @geo:[19,47,100,km] LOAD 2 @lon @lat APPLY "sqrt((@lon - 19)^2 + (@lat - 47)^2)" as dist sortby 1 @dist1) (integer) 42) 1) lon 2) "19.02" 3) lat 4) "47.492" 5) dist 6) "0.492406336271"3) 1) lon 2) "19.05" 3) lat 4) "47.497" 5) dist 6) "0.499508758682"4) 1) lon 2) "19.06" 3) lat 4) "47.498" 5) dist 6) "0.501601435405"5) 1) lon 2) "19.07" 3) lat 4) "47.499" 5) dist 6) "0.503885899783"
To unsubscribe from this group and stop receiving emails from it, send an email to redisearch+unsubscribe@googlegroups.com.