0

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

Karthik
  • 1,091
  • 1
  • 13
  • 36
  • "After indexing lat and lang like this .. " you set UnIndexed values. I'm not sure. but from my experience if you want to search for data you should to index it. – tasmaniski Nov 16 '11 at 20:32

2 Answers2

1

It is not possible to query unindexed data. Unindexed data are only stored.

If you want to search(query) the lat and long you should set it as indexed data.

See list of Zend_Search_Lucene_Field Types

Also at this link you have simple tutorial for Zend_Search_Lucene

tasmaniski
  • 4,767
  • 3
  • 33
  • 65
  • Thanks.. But is it possible for me to do the above distance formula after indexing the lat and long? – Karthik Nov 17 '11 at 09:28
  • 1
    I'm not sure I understand where is the problem . In any case, When you get result(lat and long) from search, you can use distance formula for calculating, it is standard PHP Math functions http://php.net/manual/en/ref.math.php . As for php, you can use distance formula wherever you want ... – tasmaniski Nov 18 '11 at 08:58
0

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/

Camilla
  • 489
  • 5
  • 14