public async Task<List<SpotSearchResult>> GetSpotsByName(string name) { var client = new IndexQueryClient(connection); var results = await client.SearchAsync("spot", new SearchQuery(name) //.OrderBy("posttext") .SearchField("name").Top(500)); if (!results.IsSuccess) throw new Exception( String.Format("Query failed, resaon: {0}", results.StatusCode.ToString()) ); List<SpotSearchResult> spotresult = new List<SpotSearchResult>(); foreach (SearchQueryRecord record in results.Body.Records) { SpotSearchResult result = new SpotSearchResult(); result.Uid = record.Properties["id"].ToString(); result.Name = record.Properties["name"].ToString(); result.Description = record.Properties["description"].ToString(); if (record.Properties["location"] != null) { dynamic test = JsonConvert.DeserializeObject(record.Properties["location"].ToString()); result.Location = new Location(); result.Location.Latitude = Convert.ToDouble(test.coordinates.Last.ToString()); result.Location.Longitude = Convert.ToDouble(test.coordinates.First.ToString()); spotresult.Add(result); } } return spotresult; }
public async Task<List<SpotSearchResult>> GetSpotsNearby(double longitude, double latitude) { var client = new IndexQueryClient(connection); var results = await client.SearchAsync("spot", new SearchQuery() //.OrderBy("posttext") .SearchField("name") //geo.distance(location, geography'POINT(<long> <lat>)' .Filter(String.Format("geo.distance(location, geography'POINT({0} {1})') le 50", longitude.ToString(CultureInfo.InvariantCulture.NumberFormat), latitude.ToString(CultureInfo.InvariantCulture.NumberFormat) )) ); if (!results.IsSuccess) throw new Exception( String.Format("Query failed, resaon: {0}", results.StatusCode.ToString()) ); List<SpotSearchResult> spotresult = new List<SpotSearchResult>(); foreach (SearchQueryRecord record in results.Body.Records) { SpotSearchResult result = new SpotSearchResult(); result.Uid = record.Properties["id"].ToString(); result.Name = record.Properties["name"].ToString(); result.Description = record.Properties["description"].ToString(); dynamic test = JsonConvert.DeserializeObject(record.Properties["location"].ToString()); result.Location.Latitude = Convert.ToDouble(test.coordinates.Last.ToString(), CultureInfo.InvariantCulture.NumberFormat); result.Location.Longitude = Convert.ToDouble(test.coordinates.First.ToString(), CultureInfo.InvariantCulture.NumberFormat); spotresult.Add(result); } return spotresult; }