views:

490

answers:

3

I am currently looking into using Lucene.NET for powering the search functionality on a web application I am working on. However, the search functionality I am implementing not only needs to do full text searches, but also needs to rank the results by proximity to a specified address.

Can Lucene.NET handle this requirement? Or do I have need to implement some way of grouping hits into different locations (e.g. less than 5 miles, less than 10 miles, etc) first, then use Lucene.NET to rank the items within those groups? Or is there a completely different way that I am overlooking?

A: 

What you are looking for is called spatial search. I'm not sure if there are extensions to Lucene.Net to do this but you could take a look at NHibernate Spatial. Other than that, these queries are often done within the database. At least PostGreSQL, MySQL and SQL Server 2008 have spatial query capabilities.

mmiika
A: 

After some additional research, I think I may have found my answer. I will use Lucene.NET to filter the search results down by other factors, then use the geocoded information from Google or Yahoo to sort the results by distance.

Kevin Pang
+2  A: 

You can implement a custom scorer to rank the results in order of distance, but you must filter the results before to be efficient. You can make use of the bounding boxes method, filtering the results in a square of 20 milles around your address, and after that apply the ranking.

If I don't remember bad, In the lucene in action book there is an example of a distance relevance algorithm. It's for java lucene, but the api is the same and you can translate easily to c# or vb.net

Jokin