Ejemplo n.º 1
0
        public ValidatedAddress ValidateAddress(GeoQuery query)
        {
            var request = new GeocodeRequest
            {
                BingMapsKey = Startup.BingKey,
                Query       = query.ToString()
            };

            var result = request.Execute().Result;

            if (result.ResourceSets.Length > 0)
            {
                var location = (Location)result.ResourceSets[0].Resources[0];
                if (location.Address.Locality.IsNullOrWhiteSpace() || location.Address.AddressLine.IsNullOrWhiteSpace())
                {
                    return(new ValidatedAddress {
                        ConfidenceLevel = ConfidenceLevel.None
                    });
                }
                else
                {
                    return(_mapper.Map <ValidatedAddress>(location));
                }
            }

            return(new ValidatedAddress {
                ConfidenceLevel = ConfidenceLevel.None
            });
        }
Ejemplo n.º 2
0
        public async Task <List <DomainId> > SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope,
                                                         CancellationToken ct = default)
        {
            Guard.NotNull(app, nameof(app));
            Guard.NotNull(query, nameof(query));

            var result = new List <(DomainId Id, double Score)>();

            await SearchAsync(result, "*", BuildGeoQuery(query, scope), query.Take, 1, ct);

            return(result.OrderByDescending(x => x.Score).Select(x => x.Id).Distinct().ToList());
        }
        protected async Task SearchGeo(List <DomainId>?expected, string field, double latitude, double longitude, SearchScope target = SearchScope.All)
        {
            var query = new GeoQuery(schemaId.Id, field, latitude, longitude, 1000, 1000);

            var result = await Sut.TextIndex.SearchAsync(app, query, target);

            if (expected != null)
            {
                result.Should().BeEquivalentTo(expected.ToHashSet());
            }
            else
            {
                result.Should().BeEmpty();
            }
        }
Ejemplo n.º 4
0
        public async Task <List <DomainId>?> SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope)
        {
            var byGeo =
                await GetCollection(scope).Find(
                    Filter.And(
                        Filter.Eq(x => x.AppId, app.Id),
                        Filter.Eq(x => x.SchemaId, query.SchemaId),
                        Filter_ByScope(scope),
                        Filter.GeoWithinCenterSphere(x => x.GeoObject, query.Longitude, query.Latitude, query.Radius / 6378100)))
                .Limit(Limit).Only(x => x.ContentId)
                .ToListAsync();

            var field = Field.Of <MongoTextIndexEntity>(x => nameof(x.ContentId));

            return(byGeo.Select(x => DomainId.Create(x[field].AsString)).Distinct().ToList());
        }
Ejemplo n.º 5
0
        public ISearchClient <T> WithinRadiusOf(string propertyName, GeoLocation geoLocation, double km)
        {
            var tType    = typeof(T);
            var property = tType.GetProperty(propertyName);

            if (property.PropertyType != typeof(GeoLocation))
            {
                throw new SyntaxErrorException("The property selected as WithinRadiusOf property is not of the type GeoLocation");
            }
            GeoQuery = new GeoQuery {
                Distance     = km,
                Latitude     = geoLocation.Latitude,
                Longitude    = geoLocation.Longitude,
                PropertyName = propertyName
            };

            return(this);
        }
Ejemplo n.º 6
0
        public virtual async Task <List <DomainId>?> SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope,
                                                                 CancellationToken ct = default)
        {
            Guard.NotNull(app, nameof(app));
            Guard.NotNull(query, nameof(query));

            var findFilter =
                Filter.And(
                    Filter.Eq(x => x.AppId, app.Id),
                    Filter.Eq(x => x.SchemaId, query.SchemaId),
                    Filter_ByScope(scope),
                    Filter.GeoWithinCenterSphere(x => x.GeoObject, query.Longitude, query.Latitude, query.Radius / 6378100));

            var byGeo =
                await GetCollection(scope).Find(findFilter).Limit(query.Take).Project <MongoTextResult>(searchGeoProjection)
                .ToListAsync(ct);

            return(byGeo.Select(x => x.ContentId).ToList());
        }
Ejemplo n.º 7
0
        public override async ValueTask <FilterNode <ClrValue>?> Visit(CompareFilter <ClrValue> nodeIn, Args args)
        {
            if (nodeIn.Value.Value is FilterSphere sphere)
            {
                var field = string.Join(".", nodeIn.Path.Skip(1));

                var searchQuery = new GeoQuery(args.Schema.Id, field, sphere.Latitude, sphere.Longitude, sphere.Radius, 1000);
                var searchScope = args.Context.Scope();

                var ids = await args.TextIndex.SearchAsync(args.Context.App, searchQuery, searchScope);

                if (ids == null || ids.Count == 0)
                {
                    return(ClrFilter.Eq("id", "__notfound__"));
                }

                return(ClrFilter.In("id", ids.Select(x => x.ToString()).ToList()));
            }

            return(nodeIn);
        }
Ejemplo n.º 8
0
 public Task <List <DomainId>?> SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope)
 {
     return(Task.FromResult <List <DomainId>?>(null));
 }
Ejemplo n.º 9
0
        public async Task <List <DomainId> > SearchAsync(IAppEntity app, GeoQuery query, SearchScope scope,
                                                         CancellationToken ct = default)
        {
            Guard.NotNull(app);
            Guard.NotNull(query);

            var serveField = GetServeField(scope);

            var elasticQuery = new
            {
                query = new
                {
                    @bool = new
                    {
                        filter = new object[]
                        {
                            new
                            {
                                term = new Dictionary <string, object>
                                {
                                    ["schemaId.keyword"] = query.SchemaId.ToString()
                                }
                            },
                            new
                            {
                                term = new Dictionary <string, string>
                                {
                                    ["geoField.keyword"] = query.Field
                                }
                            },
                            new
                            {
                                term = new Dictionary <string, string>
                                {
                                    [serveField] = "true"
                                }
                            },
                            new
                            {
                                geo_distance = new
                                {
                                    geoObject = new
                                    {
                                        lat = query.Latitude,
                                        lon = query.Longitude
                                    },
                                    distance = $"{query.Radius}m"
                                }
                            }
                        },
                    }
                },
                _source = new[]
                {
                    "contentId"
                },
                size = query.Take
            };

            return(await SearchAsync(elasticQuery, ct));
        }
    void OnGUI()
    {
        if (Time.time % 2 < 1)
        {
            success = callBack.getResult();
        }
        // For Setting Up ResponseBox.
        GUI.TextArea(new Rect(10, 5, 1000, 175), success);

        //===================================**************=========================================
        if (GUI.Button(new Rect(50, 200, 200, 30), "Insert JsonDoc"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.InsertJSONDocument(cons.dbName, collectionName, cons.json, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(260, 200, 200, 30), "Find AllDocuments"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.FindAllDocuments(cons.dbName, collectionName, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(470, 200, 200, 30), "Find AllCollections"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.FindAllCollections(cons.dbName, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(680, 200, 200, 30), "Find DocumentById"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.FindDocumentById(cons.dbName, collectionName, cons.docId, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(890, 200, 200, 30), "Find DocumentByKeyValue"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.FindDocumentByKeyValue(cons.dbName, collectionName, cons.key, cons.val, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(50, 250, 200, 30), "UpdateDocumentByKeyValue"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.UpdateDocumentByKeyValue(cons.dbName, collectionName, cons.key, cons.val, cons.newJson, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(260, 250, 200, 30), "UpdateDocumentById"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.UpdateDocumentByDocId(cons.dbName, collectionName, cons.docId, cons.newJson, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(470, 250, 200, 30), "Delete DocumentById"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.DeleteDocumentById(cons.dbName, collectionName, cons.docId, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(680, 250, 200, 30), "Delete DocumentsByKeyValue"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.DeleteDocumentsByKeyValue(cons.dbName, collectionName, cons.key, cons.val, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(890, 250, 200, 30), "DeleteAllDocuments"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.DeleteAllDocuments(cons.dbName, collectionName, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(260, 300, 200, 30), "FindAllDocumentsCount"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.FindAllDocumentsCount(cons.dbName, collectionName, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(470, 300, 200, 30), "FindAllDocumentsByPaging"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.FindAllDocuments(cons.dbName, collectionName, max, offSet, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(680, 300, 200, 30), "InsertJsonWithGeoTag"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            GeoTag gp = new GeoTag();
            gp.SetLat(-73.99171);
            gp.SetLng(40.738868);
            storageService.SetGeoTag(gp);
            storageService.InsertJSONDocument(cons.dbName, collectionName, cons.json, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(890, 300, 200, 30), "FindDocumentsByLocation"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.

            GeoTag gp = new GeoTag();
            gp.SetLat(-73.99171);
            gp.SetLng(40.738868);

            GeoQuery query = QueryBuilder.BuildGeoQuery(gp, GeoOperator.NEAR, 100);
            storageService.FindDocumentsByLocation(cons.dbName, collectionName, query, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(50, 350, 200, 30), "FindAllDocumentsSelectKeys"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.

            HashSet <string> selectKeys = new HashSet <string> ();
            selectKeys.Add("Name");
            storageService.SetSelectKeys(selectKeys);
            storageService.FindAllDocuments(cons.dbName, collectionName, callBack);
        }

        //===================================**************=========================================
        if (GUI.Button(new Rect(260, 350, 200, 30), "FindDocumentsByQuery"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            Query q1 = QueryBuilder.Build("AppName", "de", Operator.LIKE);
            Query q2 = QueryBuilder.Build("AppId", "123hg4bdb", Operator.LIKE);
            Query q3 = QueryBuilder.CompoundOperator(q1, Operator.OR, q2);
            storageService.FindDocumentsByQuery(cons.dbName, collectionName, q3, callBack);
        }
        //===================================**************=========================================
        if (GUI.Button(new Rect(470, 350, 200, 30), "SaveOrUpdateDocument"))
        {
            storageService = sp.BuildStorageService();                                      // Initializing Storage Service.
            storageService.SaveOrUpdateDocumentByKeyValue(cons.dbName, collectionName, cons.key, cons.val, cons.newJson, callBack);
        }
    }
Ejemplo n.º 11
0
 /// <summary>
 /// Performs a location query and returns the result.
 /// </summary>
 /// <param name="query">The location query.</param>
 /// <returns>The query result.</returns>
 /// <remarks>
 /// The format of the query result is designed to be compatible with the <see cref="GeoQueryResults" />
 /// class defined within the <b>LillTek.GeoTracker</b> assembly.  See this class for more details.
 /// </remarks>
 public byte[] Query(GeoQuery query)
 {
     return(null);
 }