Complex Smart Search Filters

Sam Power asked on June 2, 2015 09:40

I have implemented smart search on my website. I have done so by building a few custom search indexes. I have a number of filters which are basic dropdowns which compare against a field I have provided in the index. This works well.

Each result has a specific location, I have saved into the record the latitude and longitude for the record. What I would like is to have the user enter a location (I would then pull the latitude longitude for this location). A custom filter would then order the search results based on distance from the entered location.

It seems that the provided smart search filter web part can only do basic string comparisons. I need it to be able to provide it with my own compare function to determine the order results should be displayed.

Hopefully I have explained myself well enough here. Any strategies for implementing something like this?

Thanks, Sam

Correct Answer

Brenden Kehren answered on June 8, 2015 13:44

Documentation on creating Custom Filters.

You could also check out this web part on the Marketplace and see if it works for you.

0 votesVote for this answer Unmark Correct answer

Recent Answers

Brenden Kehren answered on June 2, 2015 13:40

I've done this in a few instances and you'd have to build a custom search index OR create your own web part and/or filter to get this to work as you'd expect for the locations. With either solution, you need to get the lat and long of the place they are searching for, then get a list of locations close to that. This can be run this against a geolocation database or a zip code table that has lat long and city/state info in it. Then you need to order the results by distance, then display them.

If you're using SQL 2008 or newer, you can use the GEOGRAPHY spacial data type to get distance. You'd use it like so (of course your lat and long values would be input parameters:

SELECT *, GEOGRAPHY::Point(Latitude, Longitude, 4326).STDistance('POINT(44.9778 93.2650)')/1609.344 AS ProxDistance
FROM YourTable
ORDER BY ProxDistance ASC
0 votesVote for this answer Mark as a Correct answer

Sam Power answered on June 3, 2015 02:20 (last edited on June 3, 2015 02:21)

Nice answer, but I was more looking for guidance on the specifics of implementing the filter as opposed to strategies for calculating distance. Is there a web part I can just add which allows me to enter custom code for determining relevance? Or a filter web part that allows me to run something like the SQL query you just provided?

0 votesVote for this answer Mark as a Correct answer

Sam Power answered on June 9, 2015 03:46

Thank you Brenden. Very helpful as always.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.