Optimizing search query

lucene

I'm working on a web application which uses Lucene.net(version 2.0.0.4) for store search.
Though my web application user can search for stores in the US which are located within 50 miles from a given location.
I'm using a third party API to find all the cities within a radius.For a city say Edison,NJ, it gives me around 450 cities within 40 miles(API returns a .Net hashtable containing 450 cities).
By iterating over this hashtable, am using BooleanQuery/Query classes to build lucene query.

In this scenario,i find that it is taking a lot of time to build,execute and return the search results through lucene.
Is there any way I can optimize this code??

Thanks!

Best Answer

When you are building your index, map the cities to latitude and longitude coordinates. In the web app when you are doing a radius search, map the city searched to coordinates and do a range query (you'll need to convert the distance to whatver units your coordinates are in).

This is imperfect in that you will be searching a square instead of a circle, but you could write some code to filter results outside the original radius if you need to be precise.

Related Topic