0

I am using Yii2-sphinx extension and everything working fine. Now I am doing distance search using sphinx so i want to set latitude and longitude for a given postcode. How can I set those two filters for my index?

As sphinx has an option to set geofilters but in yii2-sphinx, I am not able to do this.

halfer
  • 19,824
  • 17
  • 99
  • 186
Awais Mustafa
  • 151
  • 2
  • 9

1 Answers1

0

See, http://sphinxsearch.com/blog/2013/07/02/geo-distances-with-sphinx/

Want a query somewhat like

SELECT *, GEODIST(0.659298124, -2.136602399, latitude, longitude) as distance 
  FROM geodemo WHERE distance < 10000 ORDER BY distance ASC LIMIT 0,100;

So would need to use GEODIST function in ->select() and the filter in ->andWhere()

May want to change the order too.

barryhunter
  • 20,886
  • 3
  • 30
  • 43
  • Yes i am using almost same but not able to change these values 0.659298124, -2.136602399. These two values will be dynamic as values will be changed according to the given postcode. I am using join query and the query is written in sphinx.conf file as join is not supported in sphinx query builder. – Awais Mustafa Dec 21 '16 at 14:23
  • Well they are just the lat/long expressed in radians, will need to look it up from the API. You need the lat/long attributes in radians in the sphinx index too. It can't go in teh sql_query, asi its dynamic. The location is dependn't on the specific query, can be hardcoded in the index. – barryhunter Dec 21 '16 at 17:36
  • can you please help me in building such query? – Awais Mustafa Dec 23 '16 at 06:48