public async Task <IEnumerable <GetUpcomingEventsQueryResult> > GetUpcomingEvents(GetUpcomingEventsQuery getUpcomingEventsQuery) { var geoDistanceQuery = new GeoDistanceQuery(); geoDistanceQuery.Field("location"); geoDistanceQuery.Latitude(getUpcomingEventsQuery.Latitude); geoDistanceQuery.Longitude(getUpcomingEventsQuery.Longitude); geoDistanceQuery.Distance($"{getUpcomingEventsQuery.Radius}km"); var statusMatchQuery = new MatchQuery(EventStatuses.ACTIVE); statusMatchQuery.Field("status"); var conjunctionQuery = new ConjunctionQuery(geoDistanceQuery, statusMatchQuery); if (!string.IsNullOrEmpty(getUpcomingEventsQuery.Keywords)) { var subjectMatchQuery = new MatchQuery(getUpcomingEventsQuery.Keywords).Fuzziness(1); conjunctionQuery.And(subjectMatchQuery); } var searchParams = new SearchParams() .Fields("*") .Limit(10) .Timeout(TimeSpan.FromMilliseconds(10000)); var searchQuery = new SearchQuery { Query = conjunctionQuery, Index = "idx_geo_events", SearchParams = searchParams }; var queryResult = await _eventsBucket.QueryAsync(searchQuery); var result = new List <GetUpcomingEventsQueryResult>(); foreach (var hit in queryResult.Hits) { result.Add(new GetUpcomingEventsQueryResult { EventId = Guid.Parse(hit.Id), Subject = hit.Fields["subject"], UrlKey = hit.Fields["urlKey"], Description = hit.Fields["description"], Date = DateTimeOffset.Parse(hit.Fields["date"].ToString()) }); } return(result); }
public IActionResult Point([FromBody] PointSearch point) { var query = new GeoDistanceQuery(); query.Latitude(point.Latitude); query.Longitude(point.Longitude); query.Distance(point.DistanceWithUnits); var searchParams = new SearchParams() // .Fields("geo", "name") // omitting because of bug NCBC-1651 .Limit(10) .Timeout(TimeSpan.FromMilliseconds(10000)); var searchQuery = new SearchQuery { Query = query, Index = "mygeoindex", SearchParams = searchParams }; var results = _bucket.Query(searchQuery); var list = new List <GeoSearchResult>(); foreach (var hit in results.Hits) { // *** this part shouldn't be necessary // the geo and name should come with the search results // but there's an SDK bug NCBC-1651 var doc = _bucket.Get <dynamic>(hit.Id).Value; // **************** list.Add(new GeoSearchResult { Latitude = doc.geo.lat, Longitude = doc.geo.lon, InfoWindow = new InfoWindow { Content = doc.name + "<br />" + doc.city + ", " + doc.state + " " + doc.country } }); } return(Ok(list)); }
public async Task <IActionResult> GetUpcomingEvents([FromQuery] GetUpcomingEventsRequest request) { var query = new GeoDistanceQuery(); query.Field("location"); query.Latitude(request.Latitude); query.Longitude(request.Longitude); query.Distance($"{request.Radius}km"); var searchParams = new SearchParams() .Fields("*") .Limit(10) .Timeout(TimeSpan.FromMilliseconds(10000)); var searchQuery = new SearchQuery { Query = query, Index = "eventsgeoindex", SearchParams = searchParams }; var searchQueryResults = await _bucket.QueryAsync(searchQuery); var result = new List <GetUpcomingEventsResponse>(); foreach (var hit in searchQueryResults.Hits) { result.Add(new GetUpcomingEventsResponse { Subject = hit.Fields["subject"], Address = hit.Fields["address"], Date = hit.Fields["date"] }); } return(Ok(result)); }