Search query optimization

I am working on a web application that uses Lucene.net (version 2.0.0.4) to search a store. Although my web app user can search for stores in the US that are within 50 miles of the location. I am using a 3rd party API to find all cities in a radius. For a city, Edison, NJ is said to give me about 450 cities within a 40 mile radius (API returns a .Net hash table containing 450 cities). While iterating over this hash table, I am using the BooleanQuery / Query classes to create a lucene query.

In this case, I find it takes a long time to create, execute and return search results through lucene. Is there a way that I can optimize this code?

Thank!

0


source to share


3 answers


When plotting your zip code, match cities with latitude and longitude coordinates. In the web app, when you do a radius search, hover over the map for the city you want to find in coordinates and query for the range (you will need to convert the distance to what units your coordinates are in).



It's imperfect in that you will be looking for a square instead of a circle, but you can write code to filter results outside the original radius if you need to be precise.

+1


source


I think the key to this performance is to think about how you store your data and some kind of metadata around it.

What I mean?

You have a list of cities that have a store in NJ, for example, and filter out cities that come back from your third party api based on your main list. You may find that you only have 5 matches out of 450 returned. Likewise, I would not combine 450 queries in one query - try it and decompose them into smaller sums.



Also, if you can create state-based indexes, you may find that a smaller index - especially for NJ - can process your query more efficiently than fetching specific state data in a larger index.

Hope this helps, Kiran

0


source


KenE's answer is good and you should google "lucene spatial search" for more information on this approach.

There you can go the other way, assuming that the radius is always 40 miles: just change the process.

Enter the field below the title nearyby_city

. For each store in your zip code, add a list of cities that are within its 40-mile radius. Now when you're looking for a store near Edison, NJ, just add a term to your query nearby_city:"Edison, NJ"

. Now only shops 40 miles from this city will match your request.

0


source







All Articles