Smaer search filter with radius & given lat long

Mustafa Muhammad Noman asked on July 22, 2017 19:43

hi I have a page type which has lat long location info. I want to add a filter in the smart search which can let user to select the radius & search from his current location. how can I do this ?

currently I have a SQL query which work well but how can I calculate that distance in smart search result / filter,?

Recent Answers


Brenden Kehren answered on July 23, 2017 15:16

I would look in the Marketplace for something like this first.

https://devnet.kentico.com/marketplace/web-parts/basic-repeater-with-distance-calculation

0 votesVote for this answer Mark as a Correct answer

Mustafa Muhammad Noman answered on July 23, 2017 16:34

hi Brenden,

thank you for the reply. so your suggesting to use simple repeater instead of smart search ?

actually I know I can do this, even I have the query to do this with repeater but I want to use it in the smart search feature. let me give you a detail on my requirement,

in my advanced search page I have few smart search filter with smart search dialog & smart search result, all of them work well

now I want to add a another dropdown list which let user to select the radius (1 mil, 10 mil etc)

so when search it will search from user current location with the radius.

is that possible to add a custom smart search filter which add some query in the main query which calculate the distance & find listing based on selected radius. My query as following

Declare @latitude decimal(11,6)
Declare @longitude decimal(11,6)
declare @radius int
declare @radiusDataCount int
declare @requestedDataCount int
declare @pageType varchar(100)

set @latitude=51.509865;
set @longitude= -0.118092;
set @radius=15;
set @requestedDataCount = 15;
set @pageType = 'Dev.CompanyDetail'

DECLARE @source geography = 'POINT(-0.118092 51.509865)' 



SELECT TOP (@requestedDataCount) Name, [CompanyLatitude],[CompanyLongitude], 
GEOGRAPHY::Point([CompanyLatitude], [CompanyLongitude], 4326).STDistance(@source)/1609.344 AS DistanceMile
FROM Dev_CompanyDetail
INNER JOIN [View_CMS_Tree_Joined] AS T ON CompanyID= T.DocumentForeignKeyValue 
WHERE [CompanyLatitude] IS NOT NULL
AND (T.DocumentNamePath NOT LIKE '%/Unapproved listing/%' 
         AND T.ClassName = @pageType
)

ORDER BY DistanceMile ASC
0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on July 23, 2017 22:21

Hi Mustafa,

If filtering locations that are in a square area instead of a radius area is precise enough, you could do this with Lucene ranger filter syntax. So, if each document in the SmartSearch index has a latitude and longitude field, and if you can calculate the upper bound and lower bound of both the latitude and longitude to define a square area, you could define a filter expression like this:

+latitude:[(double)lat1 TO (double)lat2] +longitude:[(double)long1TO (double)lon2]

If you need a more sophisticated solution, it would probably require finding a way to integrate Lucene contrib libraries as described here: https://www.leapinggorilla.com/Blog/Read/1005/spatial-search-in-lucenenet

I'd try to avoid that, because for consumer purposes a square area is probably as useful as a perfect radius. And, if you don't have to worry about huge amounts of data, I'd consider the repeater that Brenden referenced.

Mike

0 votesVote for this answer Mark as a Correct answer

Mustafa Muhammad Noman answered on July 24, 2017 14:59

hi Mike,

thank you for the reply. I will try that

0 votesVote for this answer Mark as a Correct answer

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