phpzend-frameworkzend-lucene

Conditions in Zend Lucene


We have a location based service in our company. The content can be searched through mobiles precisely for the user's location. This search consist of distance search using the following formula

((ACOS(SIN($lat * PI() / 180) * SIN(lat * PI() / 180) + COS($lat * PI() / 180) * COS(lat * PI() / 180) * COS(($lon – lon) * PI() / 180)) * 180 / PI()) * 60 * 1.1515)

and also some text search on title, category, description.

With millions of records in our database we could not optimise this to be as fast as we want to. We then decided to give the Zend Lucene search a shot. After indexing lat and lang like this,

$doc->addField(Zend_Search_Lucene_Field::UnIndexed('lat', '-0.502123');
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('lng', '1.502123');
$doc->addField(Zend_Search_Lucene_Field::Text('title', 'This is a title');
$doc->addField(Zend_Search_Lucene_Field::Text('desc', 'this is a description');

how can I query the distance formula on an UnIndexed Lucene_Field of lat and lng? Is it possible? or is there any work around?

Thank you, Karthik


Solution

  • I had this same problem but the other answer didn't help me. So I've found this great tutorial. I Hope it helps others like me. http://develop.nydi.ch/2010/10/lucene-spatial-example/