Beispiel #1
0
        /// <summary>
        /// geo_type_col是GeoPoint类型,查询表中geo_type_col这一列的值在左上角为"10,0", 右下角为"0,10"的矩形范围内的数据
        /// </summary>
        /// <param name="client"></param>
        public static void GeoBoundingBoxQuery(OTSClient client)
        {
            Console.WriteLine("\n Start GeoBoundingBox query...");

            SearchQuery         searchQuery         = new SearchQuery();
            GeoBoundingBoxQuery geoBoundingBoxQuery = new GeoBoundingBoxQuery(); // 设置查询类型为GeoBoundingBoxQuery

            geoBoundingBoxQuery.FieldName   = Geo_type_col;                      // 设置比较哪个字段的值
            geoBoundingBoxQuery.TopLeft     = "10,0";                            // 设置矩形左上角
            geoBoundingBoxQuery.BottomRight = "0,10";                            // 设置矩形右下角
            searchQuery.Query = geoBoundingBoxQuery;

            SearchRequest searchRequest = new SearchRequest(TableName, IndexName, searchQuery);

            var columnsToGet = new ColumnsToGet();

            columnsToGet.Columns = new List <string> {
                Geo_type_col
            };                                                         //设置返回Col_GeoPoint这一列
            searchRequest.ColumnsToGet = columnsToGet;

            SearchResponse response = client.Search(searchRequest);

            Console.WriteLine(response.TotalCount);
            foreach (var row in response.Rows)
            {
                PrintRow(row);
            }
        }
Beispiel #2
0
 public static GeoBoundingBoxQuery BuildGeoBoundingBoxQuery(Aliyun.TableStore.DataModel.Search.Query.GeoBoundingBoxQuery query)
 {
     GeoBoundingBoxQuery.Builder builder = GeoBoundingBoxQuery.CreateBuilder();
     builder.SetFieldName(query.FieldName);
     builder.SetTopLeft(query.TopLeft);
     builder.SetBottomRight(query.BottomRight);
     return(builder.Build());
 }
Beispiel #3
0
        public void Export_Omits_Field_If_Not_Provided()
        {
            var query = new GeoBoundingBoxQuery()
                        .TopLeft(1, 2)
                        .BottomRight(3, 4);

            var expected = JsonConvert.SerializeObject(new
            {
                top_left     = new[] { 1.0, 2.0 },
                bottom_right = new[] { 3.0, 4.0 }
            }, Formatting.None);

            Assert.Equal(expected, query.Export().ToString(Formatting.None));
        }
Beispiel #4
0
        public void Export_ReturnsValidJson()
        {
            var query = new GeoBoundingBoxQuery()
                        .TopLeft(1, 2)
                        .BottomRight(3, 4)
                        .Field("bar");

            var expected = JsonConvert.SerializeObject(new
            {
                top_left     = new[] { 1.0, 2.0 },
                bottom_right = new[] { 3.0, 4.0 },
                field        = "bar"
            }, Formatting.None);

            Assert.Equal(expected, query.Export().ToString(Formatting.None));
        }
Beispiel #5
0
        public override void Visit(TermRangeNode node, IQueryVisitorContext context)
        {
            if (!(context is IElasticQueryVisitorContext elasticContext) || !elasticContext.IsGeoPropertyType(node.Field))
            {
                return;
            }

            var box = new BoundingBox {
                TopLeft = node.Min, BottomRight = node.Max
            };
            var query = new GeoBoundingBoxQuery {
                BoundingBox = box, Field = node.Field
            };

            node.SetQuery(query);
        }
        public IActionResult Box([FromBody] BoxSearch box)
        {
            var query = new GeoBoundingBoxQuery();

            query.TopLeft(box.LongitudeTopLeft, box.LatitudeTopLeft);
            query.BottomRight(box.LongitudeBottomRight, box.LatitudeBottomRight);
            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);
            // end::Box[]

            // tag::BoxResults[]
            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));
        }